create initial opengl renderer
This commit is contained in:
parent
0379c8c2e2
commit
8ce34a1a4b
|
@ -15,6 +15,4 @@ module Sdl = struct
|
||||||
let gl_set_swap_interval_exn i = gl_set_swap_interval i |> or_exn
|
let gl_set_swap_interval_exn i = gl_set_swap_interval i |> or_exn
|
||||||
end
|
end
|
||||||
|
|
||||||
module Gl = struct
|
include (val Ohlog.logs "Geom")
|
||||||
include Tgl4.Gl
|
|
||||||
end
|
|
||||||
|
|
46
src/main.ml
46
src/main.ml
|
@ -1,51 +1,51 @@
|
||||||
open! Import
|
open! Import
|
||||||
|
include (val Ohlog.sublogs logger "Main")
|
||||||
include (val Ohlog.logs "main")
|
|
||||||
|
|
||||||
exception Quit
|
exception Quit
|
||||||
|
|
||||||
let main () =
|
let main () =
|
||||||
info (fun m -> m "initializing");
|
debug (fun m -> m "initializing");
|
||||||
|
let flags = Sdl.Window.(opengl + resizable - shown) in
|
||||||
let flags = Sdl.Window.(shown + opengl + resizable) in
|
|
||||||
let window =
|
let window =
|
||||||
Sdl.create_window_exn
|
Sdl.create_window_exn
|
||||||
~w:1024 ~h:800
|
~w:1024 ~h:800
|
||||||
"Geometra"
|
"GEOMETRA"
|
||||||
flags
|
flags
|
||||||
in
|
in
|
||||||
let event = Sdl.Event.create () in
|
info (fun m -> m "window initialized");
|
||||||
let some_event = Some event in
|
|
||||||
|
|
||||||
let ogl = Sdl.gl_create_context_exn window in
|
let ren = Renderer.make ~window in
|
||||||
Sdl.gl_make_current_exn window ogl;
|
info (fun m -> m "renderer initialized");
|
||||||
Sdl.gl_set_swap_interval_exn 1;
|
|
||||||
|
|
||||||
begin
|
|
||||||
Gl.clear_color 1. 0. 1. 1.;
|
|
||||||
end;
|
|
||||||
|
|
||||||
info (fun m -> m "initialized");
|
|
||||||
try
|
try
|
||||||
|
let event = Sdl.Event.create () in
|
||||||
|
let some_event = Some event in
|
||||||
|
|
||||||
|
Sdl.show_window window;
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
while Sdl.poll_event some_event do
|
while Sdl.poll_event some_event do
|
||||||
match Sdl.Event.(get event typ |> enum) with
|
match Sdl.Event.(get event typ |> enum) with
|
||||||
| `Quit -> raise_notrace Quit
|
| `Quit -> raise_notrace Quit
|
||||||
| _ ->
|
| _ ->
|
||||||
trace (fun m -> m "uncaught event (%d)" (Sdl.Event.(get event typ)));
|
trace (fun m -> m "uncaught event (%d)" Sdl.Event.(get event typ))
|
||||||
()
|
|
||||||
done;
|
done;
|
||||||
|
|
||||||
(* let time = Sdl.get_ticks () |> Int32.to_int in *)
|
(* let time = Sdl.get_ticks () |> Int32.to_int in *)
|
||||||
Gl.clear Gl.color_buffer_bit;
|
Renderer.pre_draw ren;
|
||||||
Sdl.gl_swap_window window;
|
Renderer.clear ren (rgb24 0xff8833);
|
||||||
|
Renderer.post_draw ren;
|
||||||
done
|
done
|
||||||
with Quit ->
|
with Quit ->
|
||||||
()
|
begin
|
||||||
|
info (fun m -> m "quitting");
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Ohlog.init () ~min_level:DEBUG;
|
Ohlog.init () ~min_level:DEBUG;
|
||||||
|
|
||||||
try main () with
|
try main () with
|
||||||
| Sdl.Error msg -> error (fun m -> m "%s" msg)
|
| Failure msg -> error (fun m -> m "%s" msg)
|
||||||
| Failure msg -> error (fun m -> m "failure: %s" msg)
|
| Sdl.Error msg -> error (fun m -> m "SDL error: %s" msg)
|
||||||
|
| Asset.Error (path, msg) -> error (fun m -> m "failed to load %S: %s" path msg)
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
open! Import
|
||||||
|
include (val Ohlog.sublogs logger "Ren")
|
||||||
|
|
||||||
|
type t = {
|
||||||
|
window : Sdl.window;
|
||||||
|
gl_ctx : Sdl.gl_context;
|
||||||
|
}
|
||||||
|
|
||||||
|
let make ~(window : Sdl.window) : t =
|
||||||
|
debug (fun m -> m "initializing");
|
||||||
|
let gl_ctx = Sdl.gl_create_context_exn window in
|
||||||
|
Sdl.gl_make_current_exn window gl_ctx;
|
||||||
|
Sdl.gl_set_swap_interval_exn 1;
|
||||||
|
|
||||||
|
{
|
||||||
|
window;
|
||||||
|
gl_ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
let destroy t =
|
||||||
|
Sdl.gl_delete_context t.gl_ctx
|
||||||
|
|
||||||
|
let pre_draw t =
|
||||||
|
begin
|
||||||
|
Sdl.gl_make_current_exn t.window t.gl_ctx;
|
||||||
|
(* let size = Sdl.get_window_size t.window in *)
|
||||||
|
end
|
||||||
|
|
||||||
|
let clear (_t : t) (bg : color) =
|
||||||
|
begin
|
||||||
|
Gl.clear_color bg.r bg.g bg.b bg.a;
|
||||||
|
Gl.clear Gl.color_buffer_bit;
|
||||||
|
end
|
||||||
|
|
||||||
|
let post_draw t =
|
||||||
|
begin
|
||||||
|
Sdl.gl_swap_window t.window;
|
||||||
|
end
|
Loading…
Reference in New Issue