caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Peter Ronnquist <peter.ronnquist@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] f#/mono vs ocaml runtime system - open gl animation screen tearing.
Date: Sun, 1 May 2011 16:24:12 +0200	[thread overview]
Message-ID: <BANLkTin6GeYtWSz3M9CbezYs0gzd8kHG_A@mail.gmail.com> (raw)

While making the simple examples for SDL+opengl for the C language I
realized that even the C version showed "stuttering" but the fsharp
version is completely smooth and synced to the vblank.
Appearantly the fsharp version somehow manages to sync to the vblank
probably thanks to  the openTK api:

  do base.VSync <- VSyncMode.On

I had to configure the nvidia driver with
X Server XVideo Settings:
Video Texture Adaptor -> Sync to VBlank
Video Blitter Adaptor Settings -> Sync to VBlank

OpenGL Settings
Performance -> Sync to VBlank
                   -> Allow Flipping

then both the C sdl opengl version and ocaml sdl openg version worked smoothly.

So to sum it up, I had the wrong setting of the nvidia driver and was
fooled sinced the fsharp version still synced with the vblank.

I am posting the ocaml sdl openg test program here in case someone
would like to try it on debian 6 squeeze:

Sorry for the "false alarm", it was not ocamls fault,  and thank you
for the good advice.

(*

 Using opengl, sdl and revised syntax.

 Compile with:

 camlopt -pp camlp4r -I . -I +sdl -I +lablgl bigarray.cmxa sdl.cmxa
lablgl.cmxa unix.cmxa  str.cmxa simple2.ml -o simple2

*)

open Sdlevent;
open Sdlkey;
open Sdlgl;

(* Window size in pixels *)
value x_size_window = 512;
value y_size_window = 512;

(* Space coordinates *)
value upper_size = 1.5;
value lower_size = -1.5;
value left_size = -1.5;
value right_size = 1.5;

value init_gl width height = do {
  GlDraw.viewport ~x:0 ~y:0 ~w:width ~h:height;
  GlClear.color (0.0, 0.0, 0.0) ~alpha:0.0;
  GlClear.clear [`color; `depth];
  GlDraw.shade_model `smooth;
  GlMat.load_identity ();

  GlClear.color (0.1, 0.3, 0.1);
  GlDraw.shade_model `smooth;
};

value time =
  let start = Unix.gettimeofday () in fun () -> Unix.gettimeofday () -. start
;

value key_left_is_down = ref False;
value key_right_is_down = ref False;


(* Start of program *)
value () =

    do {

    Sdl.init [`VIDEO];
    at_exit Sdl.quit;


    set_attr [DOUBLEBUFFER True];
    ignore (Sdlvideo.set_video_mode x_size_window y_size_window
[`OPENGL ; `DOUBLEBUF ; `RESIZABLE ; `HWSURFACE]);
    init_gl x_size_window y_size_window;

    let render () =
      do {

    GlMat.mode `projection;
    GlMat.load_identity ();
    GluMat.ortho2d ~x:(-1.5, 1.5) ~y:(-1.5, 1.5);
    GlMat.mode `modelview;
    GlMat.load_identity ();
    GlClear.clear [ `color ; `depth];

    GlMat.translate ~x:(sin (time ()*.2.0) *. 1.) ~z:1. ();
    GlDraw.begins `quads;
      List.iter GlDraw.vertex2 [
        ( -0.2, -0.5);
	  (0.2, -0.5);
	    (0.2, 0.5);
	      (-0.2, 0.5)];

    GlDraw.ends ();
    Gl.flush ();
    Sdlgl.swap_buffers ();

    }
    in
      let quit_loop = ref False in
      while not quit_loop.val  do {
	(* Calculate elapsed time since last rendering *)
	  render ();
	

        match Sdlevent.poll () with
        [ Some( KEYDOWN {keysym = KEY_ESCAPE} ) -> do {
          print_endline "You pressed escape! The fun is over now.";
          quit_loop.val := True
        }
        | Some( KEYDOWN {keysym = KEY_LEFT} ) -> do {
          key_left_is_down.val := True;
        }
        | Some( KEYDOWN {keysym = KEY_RIGHT} ) -> do {
          key_right_is_down.val := True;
        }
        | Some( KEYUP {keysym = KEY_LEFT} ) -> do {
          key_left_is_down.val := False;
        }
        | Some( KEYUP {keysym = KEY_RIGHT} ) -> do {
          key_right_is_down.val := False;
        }
        | Some event -> do {
          print_endline (string_of_event event);
        }
        | None -> ()
        ]

      };

};

             reply	other threads:[~2011-05-01 14:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-01 14:24 Peter Ronnquist [this message]
     [not found] <fa.bAPY0rzAUUqrEHcCwn9toRc5oMo@ifi.uio.no>
2011-04-26 20:38 ` Ethan Burns
  -- strict thread matches above, loose matches on Subject: below --
2011-04-26 19:15 Peter Ronnquist
2011-04-26 19:30 ` Gabriel Scherer
2011-04-26 20:16   ` Peter Ronnquist
2011-04-26 19:39 ` Török Edwin
2011-04-26 20:37   ` Anthony Tavener
2011-04-27  6:51 ` rixed
2011-04-27 10:02 ` Jon Harrop
2011-04-27 21:08   ` Peter Ronnquist

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTin6GeYtWSz3M9CbezYs0gzd8kHG_A@mail.gmail.com \
    --to=peter.ronnquist@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).