Image noise: Difference between revisions
Content added Content deleted
(added ocaml) |
|||
Line 242: | Line 242: | ||
With this revision, on my laptop, I typically get in the range of 58..59 FPS, with a cpu load of about 3% (so I am probably limited by v-sync, and if I tuned my opengl drivers I perhaps could get significantly faster fps?). |
With this revision, on my laptop, I typically get in the range of 58..59 FPS, with a cpu load of about 3% (so I am probably limited by v-sync, and if I tuned my opengl drivers I perhaps could get significantly faster fps?). |
||
=={{header|OCaml}}== |
|||
with the ocaml-sdl bindings |
|||
<lang ocaml>let frames = |
|||
{ contents = 0 } |
|||
let t_acc = |
|||
{ contents = 0 } |
|||
let last_t = |
|||
{ contents = Sdltimer.get_ticks () } |
|||
let print_fps () = |
|||
let t = Sdltimer.get_ticks () in |
|||
let dt = t - !last_t in |
|||
t_acc := !t_acc + dt; |
|||
if !t_acc > 1000 then begin |
|||
let el_time = !t_acc / 1000 in |
|||
Printf.printf |
|||
"- fps: %g\n%!" |
|||
(float !frames /. float el_time); |
|||
t_acc := 0; |
|||
frames := 0; |
|||
end; |
|||
last_t := t |
|||
let blit_noise surf = |
|||
let ba = Sdlvideo.pixel_data_8 surf in |
|||
let dim = Bigarray.Array1.dim ba in |
|||
let rec aux () = |
|||
for i = 0 to pred dim do |
|||
ba.{i} <- if Random.bool () then max_int else 0 |
|||
done; |
|||
Sdlvideo.flip surf; |
|||
incr frames; |
|||
print_fps (); |
|||
aux () |
|||
in |
|||
aux () |
|||
let blit_noise surf = |
|||
try blit_noise surf |
|||
with _ -> Sdl.quit () |
|||
let () = |
|||
Sdl.init [`VIDEO; `TIMER]; |
|||
Random.self_init(); |
|||
let surf = |
|||
Sdlvideo.set_video_mode |
|||
~w:640 ~h:480 ~bpp:8 |
|||
[(*`HWSURFACE;*) `DOUBLEBUF] |
|||
in |
|||
Sys.catch_break true; |
|||
blit_noise surf</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |