|
List Info
Thread: "ocaml_beginners"::[] Programs that use libocaml-sdl ?
|
|
| "ocaml_beginners"::[] Programs
that use libocaml-sdl ? |
  France |
2007-04-09 15:31:13 |
|
Hi !
Please do you know a source example that depends on libsdl-ocaml-dev ?
( My debian tells me nothing about a package that uses libsdl-ocaml. )
But maybe the whole thing is simply just to learn the use of SDL...
Fabrice
----------------
fun OCaml -> fun
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[]
Programs that use libocaml-sdl ? |
  United States |
2007-04-09 16:07:33 |
|
On Mon, 9 Apr 2007, Fabrice Marchant wrote:
> Hi !
>
> Please do you know a source example that depends on libsdl-ocaml-dev ?
> ( My debian tells me nothing about a package that uses libsdl-ocaml. )
> But maybe the whole thing is simply just to learn the use of SDL...
You should be able to figure things out from the
ocamldoc-generated documentation:
http://ocamlsdl.sourceforge.net/doc/html/index.html
It doesn't say much, but there is not much to say either.
A program should look more or less like that:
open Sdlevent
(* Enable some events *)
let init_events () =
Sdlevent.enable_events (make_mask
[KEYDOWN_EVENT;
MOUSEBUTTONDOWN_EVENT;
QUIT_EVENT;
USER_EVENT]);
Sdlevent.add [USER 0] (* I use this as an initialization signal *)
(* Test whether we should continue *)
let onkeydown x =
match x.keysym with
Sdlkey.KEY_ESCAPE
| Sdlkey.KEY_q -> false
| _ -> true
let onmousedown mev =
...
(* Process the pending events until there is no more event to process.
The return value indicate whether the loop should continue. *)
let rec process_events x =
match Sdlevent.poll () with
None -> do_something_here x; true
| Some QUIT -> false
| Some ev ->
if (match ev with
KEYDOWN kev -> onkeydown kev
| MOUSEBUTTONDOWN mev -> onmousedown mev
| USER 0 -> my_init_function x
| _ -> true)
then process_events stack schedule
else false
(* Call some library's loop *)
let _ =
init_events ();
Some_library.init ();
Some_library.loop ~draw:process_events 20
In my case, I was using OpenGL with some sound. The exact code for my loop
was the following:
let loop ~draw dt =
let schedule = Yz_schedule.create_schedule () in
try
while true do
GlClear.color (0., 0., 0.);
GlClear.clear [`color];
GlMat.mode `projection;
GlMat.load_identity ();
Yz_schedule.tick schedule;
let continue = draw schedule in
if continue then
(Gl.flush ();
Sdlgl.swap_buffers ();
Sdltimer.delay dt)
else raise Exit
done
with Exit ->
Sdlmixer.close_audio ();
Sdl.quit ()
where "draw" corresponds to the "process_events" function that is passed
to the "loop" function from the main module.
And I use a "schedule" object to define animations and all kinds of
planned events.
Martin
--
Martin Jambon
http://martin.jambon.free.fr
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[]
Programs that use libocaml-sdl ? |
  France |
2007-04-10 16:37:15 |
|
Thanks a lot Martin for the example !
> > But maybe the whole thing is simply just to learn the use of SDL...
the doc...
> It doesn't say much, but there is not much to say either.
I should have realized this was just an ocaml binding ! The first thing is maybe to learn SDL with the C examples. It will probably be about the same thing with OCaml.
However I continue to wonder if a true arcade game was built in OCaml. I looked at OCaml arcade game programs in SourceForge. Only these :
- "gamesys MLG115" that is interesting but slow and
- ArcadeMassConspiracy that seems up to now insufficient
I do not focus on any graphic library and maybe SDL isn't the best one.
I like KXL approach :
http://kxl.orz.hm/
because, looking at pure Xlib programming, there are a lot of heavy unesuful things.
Who cares about selecting displays or screens for a game ?
What mainly does KXL is restricting Xlib access to only things that are needed for games.
"grande" is a good 2D games based on KXL.
Maybe is it possible to make an OCaml binding for this C lib.
I would be interested to see a true OCaml arcade game.
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[]
Programs that use libocaml-sdl ? |
  United Kingdom |
2007-04-11 07:22:14 |
|
On Tue, Apr 10, 2007 at 11:37:15PM +0200, Fabrice Marchant wrote:
> However I continue to wonder if a true arcade game was built in
> OCaml. I looked at OCaml arcade game programs in SourceForge. Only
> these :
It should be possible to write an arcade game in OCaml. OCaml's
features / target developers are similar enough to C++, and nearly all
commercial games these days seem to be written in C++.
I had a go at a silly demo game, here:
http://merjis.com/developers/ocamlode
Don't expect very much, but it demonstrates some of the principles
involved, including:
* OpenGL for graphics.
* ODE for physics.
* SDL for I/O.
* All game structures are persistent (demonstrating that pure
functional programming is not in itself a bar to performance or
functionality).
* A "confined" garbage collector. I invoke the GC manually between
frames to ensure it doesn't kick in at an unexpected moment and cause
the gameplay to jump or hang.
[...]
> I do not focus on any graphic library and maybe SDL isn't the best one.
SDL is fine for writing games. In fact it was originally developed by
Loki software (a defunct gaming house) in order to port commercial
Windoze games over to Linux. The gaming company may not have
survived, but it wasn't because of any faults with their tech.
http://en.wikipedia.org/wiki/Simple_DirectMedia_Layer#History
Rich.
--
Richard Jones
Red Hat
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[]
Programs that use libocaml-sdl ? |
  France |
2007-04-14 15:03:19 |
|
Debo and Rich : I'm very sorry !
Wasn't there and when, at last, I try to look at these games - many thanks ! - on my Debian Etch...
impossible ! I'm incompetent, ashamed :
* Debo, I was unable to successfully build Spiff
Problems come at link time. The linker complains about this :
(The installed version of tcl/tk is 8.4 )
"ocamlopt -inline 20 -o spiff.opt -I +labltk -I +lablGL unix.cmxa labltk.cmxa
lablgl.cmxa togl.cmxa texhelp.o tex.cmx collision.cmx fixedobj.cmx
freeobj.cmx badguy.cmx spiff.cmx wall.cmx level.cmx mousehelp.o mouse.cmx
game.cmx ui.cmx main.cmx
Files /usr/lib/ocaml/3.09.2/lablGL/togl.cmxa
and /usr/lib/ocaml/3.09.2/labltk/labltk.cmxa
make inconsistent assumptions over interface Tk
make: *** [spiff.opt] Error 2
I discover this kind of "inconsistency error".
* Rich, I had problems with the demo game :
Began to install physics lib ode that lacks on my system : OK.
The ocamlode-0.5-r2 Make builds, after I launch manually "ocamlopt ode.ml" (otherwise I haven't ode.o)
However, when I launch the generated katamari.opt, a window swiftly opens and closes.
This returns to my xterm with a naughty :
freeglut ERROR: Function <glutWireSphere> called without first calling 'glutInit'.
Regards
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[]
Programs that use libocaml-sdl ? |
  United Kingdom |
2007-04-15 09:08:55 |
|
On Sat, Apr 14, 2007 at 10:03:19PM +0200, Fabrice Marchant wrote:
> * Rich, I had problems with the demo game :
> Began to install physics lib ode that lacks on my system : OK.
> The ocamlode-0.5-r2 Make builds, after I launch manually "ocamlopt ode.ml" (otherwise I haven't ode.o)
> However, when I launch the generated katamari.opt, a window swiftly opens and closes.
> This returns to my xterm with a naughty :
> freeglut ERROR: Function <glutWireSphere> called without first calling 'glutInit'.
I don't have a Debian machine with the required packages to hand to
test this, but it would appear to be a linking problem. glutInit IIRC
is called by linking in a separate lablgl.glut package (using
ocamlfind). As usual with experimental software of this type, when it
breaks you get to keep both parts ...
Rich.
--
Richard Jones
Red Hat
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[]
Programs that use libocaml-sdl ? |
  France |
2007-04-15 15:57:15 |
|
> I don't have a Debian machine with the required packages to hand to
> test this, but it would appear to be a linking problem. glutInit IIRC
> is called by linking in a separate lablgl.glut package (using
> ocamlfind). As usual with experimental software of this type, when it
> breaks you get to keep both parts ...
Will ask to Debian users how to properly build the two softs.
Best regards.
Fabrice
__._,_.___
.
__,_._,___
|
[1-7]
|
|