Coder Social home page Coder Social logo

ocamlsdl2's Introduction

OCaml and SDL 2.0

OCaml and SDL

Introduction

OCamlSDL2 is an OCaml interface to the SDL2 library.

If you are searching for OCaml bindings for SDL 1.2 then you should go there instead: ocamlsdl.sf.net

Versions

This version of the bindings is known to work with SDL 2.0.9 or 2.0.10 and OCaml 4.07.1 until 4.13.1

Compile and Install

Read the file "INSTALL.txt" for instructions about how to compile and install.

Opam

You can install ocamlsdl2 with opam.

If you installed SDL2 version 2.0.9 or later you can install the last version:

$ opam install ocamlsdl2

But if you still use an older version of SDL2 like for example SDL2 version 2.0.6 then you should install a previous version of the bindings:

$ opam install ocamlsdl2.0.02

To know which version of the SDL2 is on your system, you can use the command:

$ sdl2-config --version

To install the source directory (tarball release or git clone):

$ opam install .

API Documentation

The API documentation can be browsed online:

https://fccm.github.io/OCamlSDL2/

Accompanying libraries

There are also bindings for the accompanying libraries:
(unlike the main ocamlsdl2 these are not tested on Windows yet)

Dune

If you use Dune to build your project, you can use this instruction to your dune file:

  (libraries sdl2)

License

This software is provided "AS-IS", without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely.

ocamlsdl2's People

Contributors

codename68 avatar csoren avatar fccm avatar gadmm avatar piotrm0 avatar scvalex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ocamlsdl2's Issues

Support for sdlttf

Hi,

it would be nice if support for sdlttf could be added. More precisely, we would need Sdlttf.init, Sdlttf.open_font and Sdlttf.render_utf8_shaded.

Thanks!

error: use of undeclared identifier 'SDL_DISPLAYEVENT'

Every time I try to install OCamlSDL2, the output is:

[ERROR] The compilation of ocamlsdl2 failed at "/home/cacilhas/.opam/opam-init/hooks/sandbox.sh build make -C src opt".

#=== ERROR while compiling ocamlsdl2.0.04 =====================================#
# context     2.0.8 | linux/x86_64 | ocaml-base-compiler.4.11.1 | https://opam.ocaml.org#d9cdb856
# path        ~/.opam/4.11.1/.opam-switch/build/ocamlsdl2.0.04
# command     ~/.opam/opam-init/hooks/sandbox.sh build make -C src opt
# exit-code   2
# env-file    ~/.opam/log/ocamlsdl2-15511-ad8886.env
# output-file ~/.opam/log/ocamlsdl2-15511-ad8886.out
### output ###
# sdlevent_stub.c:145:13: warning: enumeration values 'SDL_SCANCODE_AUDIOREWIND' and 'SDL_SCANCODE_AUDIOFASTFORWARD' not handled in switch [-Wswitch]
# [...]
#             ^
# sdlevent_stub.c:513:10: error: use of undeclared identifier 'SDL_DISPLAYEVENT'
#     case SDL_DISPLAYEVENT:               return Val_SDL_DISPLAYEVENT;
#          ^
# sdlevent_stub.c:520:10: error: use of undeclared identifier 'SDL_SENSORUPDATE'
#     case SDL_SENSORUPDATE:               return Val_SDL_SENSORUPDATE;
#          ^
# 1 warning and 2 errors generated.
# Makefile:193: recipe for target 'sdlevent_stub.o' failed
# make: *** [sdlevent_stub.o] Error 2
# make: Leaving directory '/home/cacilhas/.opam/4.11.1/.opam-switch/build/ocamlsdl2.0.04/src'

ocamlsdl2-15511-ad8886.out.gz

Win10+Msys2 - flexlink: unknown option '-Wall'.

Hi - I'm new to ocaml - I've been using f#, but want to use a native solution.

So, I'm using ocaml version 4.04.0, because that is what comes with MSys2. I've gotten your bindings to compile, but when I try the examples folder, I get this error:

make test
ocamlopt -g -I ../src sdl2.cmxa
ex_version.ml -o "ex_version.exe"
flexlink: unknown option '-Wall'.
FlexDLL version 0.34

error: use of undeclared identifier 'int32'

Hi,

When building on macOS sierra with clang-800.0.42.1 (g++/gcc that comes with the latest version of XCode), I get the following output:

ocamlc -g -ccopt "-static -I/usr/local/include/SDL2 -D_THREAD_SAFE -g -O " sdlsurface_stub.c
sdlsurface_stub.c:193:5: error: use of undeclared identifier 'int32'
    int32 *pixels = (int32 *) SDL_Surface_val(surface)->pixels;
    ^
sdlsurface_stub.c:193:12: error: use of undeclared identifier 'pixels'
    int32 *pixels = (int32 *) SDL_Surface_val(surface)->pixels;
           ^
sdlsurface_stub.c:193:29: error: expected expression
    int32 *pixels = (int32 *) SDL_Surface_val(surface)->pixels;
                            ^
sdlsurface_stub.c:193:22: error: use of undeclared identifier 'int32'
    int32 *pixels = (int32 *) SDL_Surface_val(surface)->pixels;
                     ^
sdlsurface_stub.c:196:28: error: use of undeclared identifier 'pixels'
    return caml_copy_int32(pixels[ofs]);
                           ^
5 errors generated.

This is probably related to the default standard used for C and could probably be fixed by setting something like --std=c89, I guess.

When changing int32 to int32_t, the build gets a bit further, but now errors out with:

make opt byte
ocamlmklib -o sdl2 -oc sdl2_stubs  sdlinit_stub.o  sdlquit_stub.o  sdlrect_stub.o  sdlblendMode_stub.o  sdlsurface_stub.o  sdlwindow_stub.o  sdlrender_stub.o  sdltexture_stub.o  sdlpixelFormat_stub.o  sdlpixel_stub.o  sdlevent_stub.o  sdlkeyboard_stub.o  sdlkeymod_stub.o  sdlmouse_stub.o  sdljoystick_stub.o  sdlclipboard_stub.o  sdltimer_stub.o  sdlgl_stub.o  sdlaudio_stub.o  sdlfilesystem_stub.o  sdlversion_stub.o  sdlcpuinfo_stub.o  sdlpower_stub.o  sdlrwops_stub.o  sdlerror_stub.o  sdl_platform_stub.o -L/usr/local/lib -lSDL2 -lm -liconv -lobjc
ocamlmklib -o sdl2 -oc sdl2_stubs  sdlinit.cmx  sdlquit.cmx  sdlrect.cmx  sdlblendMode.cmx  sdlsurface.cmx  sdlwindow.cmx  sdlrender.cmx  sdltexture.cmx  sdlpixelFormat.cmx  sdlpixel.cmx  sdlevent.cmx  sdlkeyboard.cmx  sdlkeycode.cmx  sdlscancode.cmx  sdlkeymod.cmx  sdlhat.cmx  sdlmouse.cmx  sdljoystick.cmx  sdlclipboard.cmx  sdltimer.cmx  sdlaudio.cmx  sdlfilesystem.cmx  sdlversion.cmx  sdlcpuinfo.cmx  sdlpower.cmx  sdlrwops.cmx  sdlerror.cmx  sdlgl.cmx  sdl.cmx -L/usr/local/lib -lSDL2 -lm -liconv -lobjc
File "_none_", line 1:
Error: sdlinit.cmx

This is with OCaml 4.03.0 and SDL 2.0.5.

Cheers!

Opam install and Dune: linking error

Hey I'm interested in using this library for a school project, and I'm having trouble compiling some basic code with dune.

I've installed the opam package using opam install ocamlsdl2

Here's my dune file
(executable (name test)(libraries sdl2))

When I'm running dune build, I'm getting
ocamlopt test.exe (exit 2) (cd _build/default && /usr/bin/ocamlopt.opt -w @[email protected]@30..39@[email protected]@[email protected] -strict-sequence -strict-formats -short-paths -keep-locs -g -o test.exe /home/wisesalmon/.opam/default/lib/sdl2/sdl2.cmxa -I /home/wisesalmon/.opam/default/lib/sdl2 .test.eobjs/native/dune__exe__Test.cmx) /usr/bin/ld: /home/wisesalmon/.opam/default/lib/sdl2/libsdl2_stubs.a(sdlinit_stub.o): in function caml_SDL_Init': /home/wisesalmon/.opam/default/.opam-switch/build/ocamlsdl2.0.03/src/sdlinit_stub.c:55: undefined reference to SDL_Init' /usr/bin/ld: /home/wisesalmon/.opam/default/lib/sdl2/libsdl2_stubs.a(sdlinit_stub.o): in function caml_SDL_InitSubSystem': /home/wisesalmon/.opam/default/.opam-switch/build/ocamlsdl2.0.03/src/sdlinit_stub.c:63: undefined reference to SDL_InitSubSystem'
...
collect2: error: ld returned 1 exit status
File "caml_startup", line 1: Error: Error during linking (exit code 1)
Any idea what the problem is?

Thanks

library name with dune

I tried to compile a small example using dune and weirdly, adding (libraries ocamlsdl2) to my stanza produces the error:

Error: Library "ocamlsdl2" not found.
Hint: try:
  dune external-lib-deps --missing a.exe

Eventhough it is installed, as shown from the command:

$ opam list | grep ocamlsdl
ocamlsdl                0.9.1       Interface between OCaml and SDL
ocamlsdl2               0.04        Interface to the SDL2 library

However, putting (libraries sdl2) in my dune file works fine. Is this a normal documented behaviour? Is this a bug of dune? Or a bug of OCamlSDL2?

Support OCaml 4.07.1

OCamlSDL2 no longer builds with the latest version of OCaml+SDL2.

I get the following error:

sdltimer_stub.c: In function ‘caml_SDL_GetTicks_d’:
/usr/lib/ocaml/caml/memory.h:335:12: error: ‘caml__frame’ undeclared (first use in this function); did you mean ‘caml_raise’?
     (void) caml__frame, \
            ^~~~~~~~~~~
/usr/lib/ocaml/caml/memory.h:416:3: note: in expansion of macro ‘CAMLxparam1’
   CAMLxparam1 (x)
   ^~~~~~~~~~~
sdltimer_stub.c:29:5: note: in expansion of macro ‘CAMLlocal1’
     CAMLlocal1(ret);
     ^~~~~~~~~~
/usr/lib/ocaml/caml/memory.h:335:12: note: each undeclared identifier is reported only once for each function it appears in
     (void) caml__frame, \
            ^~~~~~~~~~~
/usr/lib/ocaml/caml/memory.h:416:3: note: in expansion of macro ‘CAMLxparam1’
   CAMLxparam1 (x)
   ^~~~~~~~~~~
sdltimer_stub.c:29:5: note: in expansion of macro ‘CAMLlocal1’
     CAMLlocal1(ret);
     ^~~~~~~~~~

Mac support

Hey does this project support MacOS? ie

  • tested?
  • untested but might work?
  • won't work?
  • etc.

Thanks

Example using Cairo with SDL

I would like to draw shapes on a screen, but I also need to rotate them, scale them, etc. and it looks like SDL by itself
does not provide this functionality. I know Cairo which can do all of that but I need some toy example showing
how to mix cairo and SDL code together.

For reference, here is some example showing how to mix Cairo with the Graphics library:
https://github.com/Chris00/ocaml-cairo/blob/master/examples/graphics_demo.ml

Would be great to have something similar but for SDL!
That way, as advertised here: https://www.cairographics.org/SDL/ we can mix the best of both worlds (cairo for advanced drawing and SDL for cross-platform game platform).

Installation instructions and documentation

Hi,

OCamlSDL2 works great, thanks for creating it!

I'm using it here: https://github.com/xyproto/hello_sdl2/tree/master/ocaml

But I wonder - would it be possible to offer users simpler installation instructions for installing OCamlSDL2? There are quite a few commands that has to be executed, instead of the more common "configure && make && make install".

And, is there some sort of API documentation available?

The examples were of great help.

Thanks!

Best regards,
Alexander F Rødseth

Fatal error: cannot load shared library dllsdl2_stubs

Hi, I am on manjaro (arch linux base distro)
I tried to compile a game with ocamlc + ocamlfind and it works.
But when I run the executable I get the error :
Fatal error: cannot load shared library dllsdl2_stubs
Reason: /home/idimension/.opam/default/lib/stublibs/dllsdl2_stubs.so: undefined symbol: SDL_WriteBE32

SDL2 version : 2.26.5
OCaml version : 4.14.0

OCamlSDL2 fails to build and install (opam) on Windows, cygwin

Building on windows fails with "The system cannot find the path specified." (check the log.txt file. I translated the error message here in the issue as the original one in the logfile is in polish).

As the result, opam's CI system automatically prohibited this package from installing on win32:
opam install ocamlsdl2
results with
[ERROR] ocamlsdl2 unmet availability conditions, e.g. os != "win32"

Details:

  • ocamlc --version : 4.11.0
  • sdl2-config --version : 2.0.22
  • winver : Windows Server 1809
  • virtualization: vbox

This is the only spare virt machine on which I could test it on. I'd be glad if anyone would test this on other windows versions.

In manjaro (arch base linux distro) `sdl2-config --static-libs` returns empty so project cannot be built.

Using OCamlSDL2 in my manjaro linux box was failed with below message.

(cd _build/default && /usr/bin/ocamlopt.opt -w @[email protected]@30..39@[email protected]@[email protected] -strict-sequence -strict-formats -short-paths -keep-locs -g -o bin/main.exe /home/siabard/.opam/4.13.1/lib/sdl2/sdl2.cmxa -I /home/siabard/.opam/4.13.1/lib/sdl2 /home/siabard/.opam/4.13.1/lib/sdl2_img/sdl2_img.cmxa -I /home/siabard/.opam/4.13.1/lib/sdl2_img lib/sdl2_tutorial.cmxa bin/.main.eobjs/native/dune__exe__Main.cmx)
/usr/bin/ld: /home/siabard/.opam/4.13.1/lib/sdl2/libsdl2_stubs.a(sdljoystick_stub.o): undefined reference to symbol 'SDL_JoystickNumAxes'
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../lib/libSDL2.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking (exit code 1)

In my linux box's sdl2-config, --static-libs is commented.

#    --static-libs)
#    --libs|--static-libs)
#      echo -L/usr/lib -pthread -lSDL2  -lrt -lunwind-generic -lunwind -lglib-2.0 -lgobject-2.0 -lgio-2.0 -libus-1.0 -ldbus-1 -ldl -lm  -Wl,--no-undefined -pthread -lSDL2 
#      ;;

There are two ways tested and they all worked.

  1. Uncomment --static-libs in sdl2-config and install with opam install ocamlsdl2
  2. Get clone of source and modify Makefile as LIBS_ = $(shell sdl2-config --libs) and build it (opam install . in cloned source).

I don't know which way is better, but wish that this will help someone who has a same issue like me.

My /etc/lsb-release is

DISTRIB_ID=ManjaroLinux
DISTRIB_RELEASE=21.2.1
DISTRIB_CODENAME=Qonos
DISTRIB_DESCRIPTION="Manjaro Linux"

Thank you.

Building on osx

ocaml and sdl .h files are not found when doing "make dep", fixed by the diff below. Installs fine otherwise.

diff --git a/src/Makefile b/src/Makefile
index a86812a..952f272 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -17,8 +17,8 @@ OCAML := ocaml
OCAMLDOC := ocamldoc
OCAMLDEP := ocamldep
OCAMLFIND := ocamlfind
-CC_MM = gcc -MM
OCAMLDIR := $(shell $(OCAMLC) -where)
+CC_MM = gcc -MM -I $(OCAMLDIR) $(CFLAGS)
DIRSEP := $(shell $(OCAML) dir_sep.ml)
BINDINGS_DIR := sdl2
PREFIX :=

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.