diff --git a/shell/gl-draw.sml b/shell/gl-draw.sml new file mode 100644 index 0000000..4367f79 --- /dev/null +++ b/shell/gl-draw.sml @@ -0,0 +1,50 @@ +structure GlDraw = +struct + (* The name doesn't make it clear, but this structure + * couples GLFW and OpenGL. + * I'm not sure if I will use native windowing systems + * or other graphics APIs at a later stage, + * but the current priority is GLFW + OpenGL. + * *) + type t = + { textVertexBuffer: Word32.word + , textProgram: Word32.word + , textDrawLength: int + , window: MLton.Pointer.t + } + + fun createShader (shaderType, shaderString) = + let + val shader = Gles3.createShader Gles3.VERTEX_SHADER + val _ = Gles3.shaderSource (shader, shaderString) + val _ = Gles3.compileShader shader + in + shader + end + + fun createProgram (vertexShader, fragmentShader) = + let + val program = Gles3.createProgram () + val _ = Gles3.attachShader (program, vertexShader) + val _ = Gles3.attachShader (program, fragmentShader) + val _ = Gles3.linkProgram program + in + program + end + + fun create () = + let + (* Set up GLFW. *) + val _ = Glfw.init () + val _ = Glfw.windowHint (Glfw.CONTEXT_VERSION_MAJOR (), 3) + val _ = Glfw.windowHint (Glfw.DEPRECATED (), Glfw.FALSE ()) + val _ = Glfw.windowHint (Glfw.SAMPLES (), 4) + val window = Glfw.createWindow (1600, 900, "shf") + val _ = Glfw.makeContextCurrent window + val _ = Gles3.loadGlad () + + (* todo: create vertex buffer, program, etc. for text. *) + in + {window = window} + end +end diff --git a/shf b/shf index baa6fde..7a67f0d 100755 Binary files a/shf and b/shf differ diff --git a/shf.mlb b/shf.mlb index 8f0d450..0f263bb 100644 --- a/shf.mlb +++ b/shf.mlb @@ -15,4 +15,5 @@ in end shell/gl-shaders.sml +shell/gl-draw.sml shell/shell.sml