diff --git a/build-unix-debug.sh b/build-unix-debug.sh index 642b991..9ddbd60 100755 --- a/build-unix-debug.sh +++ b/build-unix-debug.sh @@ -4,5 +4,4 @@ mlton -const 'Exn.keepHistory true' -link-opt "$(pkg-config --cflags glfw3) $(pk shf.mlb \ ffi/glad.c \ ffi/glfw-export.c \ - ffi/gles3-export.c \ ffi/glfw-input.c diff --git a/ffi/gles3-export.c b/ffi/gles3-export.c deleted file mode 100644 index 4515f05..0000000 --- a/ffi/gles3-export.c +++ /dev/null @@ -1,99 +0,0 @@ -#include "export.h" -#include "glad.h" -#include -#include - -// OpenGL constants used below -unsigned int VERTEX_SHADER = GL_VERTEX_SHADER; -unsigned int FRAGMENT_SHADER = GL_FRAGMENT_SHADER; -unsigned int TRIANGLES = GL_TRIANGLES; -unsigned int STATIC_DRAW = GL_STATIC_DRAW; -unsigned int DYNAMIC_DRAW = GL_DYNAMIC_DRAW; - -// OpenGL functions used below -void loadGlad() { - gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); - glEnable(GL_DEPTH_TEST); -} - -void viewport(int width, int height) { - glViewport(0, 0, width, height); -} - -void clearColor(float r, float g, float b, float a) { - glClearColor(r, g, b, a); -} - -void clear() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -} - -unsigned int createBuffer() { - unsigned int buffer; - glGenBuffers(1, &buffer); - return buffer; -} - -void bindBuffer(unsigned int buffer) { - glBindBuffer(GL_ARRAY_BUFFER, buffer); -} - -void bufferData(float* vector, int vectorLength, unsigned int updateMode) { - glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vectorLength, vector, updateMode); -} - -unsigned int createShader(unsigned int shaderType) { - return glCreateShader(shaderType); -} - -void shaderSource(unsigned int shader, const char *sourceString) { - glShaderSource(shader, 1, &sourceString, NULL); -} - -void compileShader(unsigned int shader) { - glCompileShader(shader); -} - -void deleteShader(unsigned int shader) { - glDeleteShader(shader); -} - -void vertexAttribPointer(int location, int numVecComponents, int stride, int offset) { - glVertexAttribPointer(location, numVecComponents, GL_FLOAT, GL_FALSE, stride * sizeof(float), (void*)offset); -} - -void enableVertexAttribArray(int location) { - glEnableVertexAttribArray(location); -} - -unsigned int createProgram() { - return glCreateProgram(); -} - -void attachShader(unsigned int program, unsigned int shader) { - glAttachShader(program, shader); -} - -void linkProgram(unsigned int program) { - glLinkProgram(program); -} - -void useProgram(unsigned int program) { - glUseProgram(program); -} - -void deleteProgram(unsigned int program) { - glDeleteProgram(program); -} - -void drawArrays(unsigned int drawMode, int startIndex, int numVertices) { - glDrawArrays(drawMode, startIndex, numVertices); -} - -int getUniformLocation(unsigned int program, const char *uniformName) { - glGetUniformLocation(program, uniformName); -} - -void uniform4f(int uniformLocation, float a, float b, float c, float d) { - glUniform4f(uniformLocation, a, b, c, d); -} diff --git a/ffi/gles3-import.sml b/ffi/gles3-import.sml index 1afc329..357977a 100644 --- a/ffi/gles3-import.sml +++ b/ffi/gles3-import.sml @@ -29,8 +29,8 @@ struct val DYNAMIC_DRAW = DYNAMIC_DRAW () (* OpenGL functions used. *) - val loadGlad = _import "loadGlad" public : unit -> unit; val viewport = _import "viewport" public : int * int -> unit; + val enableDepthTest = _import "enableDepthTest" : unit -> unit; val createBuffer = _import "createBuffer" public : unit -> buffer; val bindBuffer = _import "bindBuffer" public : buffer -> unit; diff --git a/ffi/glfw-export.c b/ffi/glfw-export.c index 648bfff..d1334f5 100644 --- a/ffi/glfw-export.c +++ b/ffi/glfw-export.c @@ -1,6 +1,8 @@ #include #define GLFW_INCLUDE_NONE +#include "glad.h" #include +#include // GLFW constants used below int CONTEXT_VERSION_MAJOR = GLFW_CONTEXT_VERSION_MAJOR; @@ -44,3 +46,100 @@ void setClipboardString (GLFWwindow *window, const char *copyString) { glfwSetClipboardString(window, copyString); } +void loadGlad() { + gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); +} + +// OpenGL constants used below +unsigned int VERTEX_SHADER = GL_VERTEX_SHADER; +unsigned int FRAGMENT_SHADER = GL_FRAGMENT_SHADER; +unsigned int TRIANGLES = GL_TRIANGLES; +unsigned int STATIC_DRAW = GL_STATIC_DRAW; +unsigned int DYNAMIC_DRAW = GL_DYNAMIC_DRAW; + +// OpenGL functions used below +void enableDepthTest() { + glEnable(GL_DEPTH_TEST); +} + +void viewport(int width, int height) { + glViewport(0, 0, width, height); +} + +void clearColor(float r, float g, float b, float a) { + glClearColor(r, g, b, a); +} + +void clear() { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +unsigned int createBuffer() { + unsigned int buffer; + glGenBuffers(1, &buffer); + return buffer; +} + +void bindBuffer(unsigned int buffer) { + glBindBuffer(GL_ARRAY_BUFFER, buffer); +} + +void bufferData(float* vector, int vectorLength, unsigned int updateMode) { + glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vectorLength, vector, updateMode); +} + +unsigned int createShader(unsigned int shaderType) { + return glCreateShader(shaderType); +} + +void shaderSource(unsigned int shader, const char *sourceString) { + glShaderSource(shader, 1, &sourceString, NULL); +} + +void compileShader(unsigned int shader) { + glCompileShader(shader); +} + +void deleteShader(unsigned int shader) { + glDeleteShader(shader); +} + +void vertexAttribPointer(int location, int numVecComponents, int stride, int offset) { + glVertexAttribPointer(location, numVecComponents, GL_FLOAT, GL_FALSE, stride * sizeof(float), (void*)offset); +} + +void enableVertexAttribArray(int location) { + glEnableVertexAttribArray(location); +} + +unsigned int createProgram() { + return glCreateProgram(); +} + +void attachShader(unsigned int program, unsigned int shader) { + glAttachShader(program, shader); +} + +void linkProgram(unsigned int program) { + glLinkProgram(program); +} + +void useProgram(unsigned int program) { + glUseProgram(program); +} + +void deleteProgram(unsigned int program) { + glDeleteProgram(program); +} + +void drawArrays(unsigned int drawMode, int startIndex, int numVertices) { + glDrawArrays(drawMode, startIndex, numVertices); +} + +int getUniformLocation(unsigned int program, const char *uniformName) { + glGetUniformLocation(program, uniformName); +} + +void uniform4f(int uniformLocation, float a, float b, float c, float d) { + glUniform4f(uniformLocation, a, b, c, d); +} diff --git a/ffi/glfw-import.sml b/ffi/glfw-import.sml index 44ece82..b8ff24a 100644 --- a/ffi/glfw-import.sml +++ b/ffi/glfw-import.sml @@ -21,4 +21,5 @@ struct val waitEvents = _import "waitEvents" public reentrant : unit -> unit; val swapBuffers = _import "swapBuffers" public : window -> unit; val setClipboardString = _import "setClipboardString" public : window * string -> unit; + val loadGlad = _import "loadGlad" public : unit -> unit; end diff --git a/ffi/rgfw-export.c b/ffi/rgfw-export.c index 69c728d..35ee9b1 100644 --- a/ffi/rgfw-export.c +++ b/ffi/rgfw-export.c @@ -27,3 +27,97 @@ bool shouldCloseWindow(RGFW_window* window) { void swapBuffers(RGFW_window* window) { RGFW_window_swapBuffers_OpenGL(window); } + +// OpenGL constants used below +unsigned int VERTEX_SHADER = GL_VERTEX_SHADER; +unsigned int FRAGMENT_SHADER = GL_FRAGMENT_SHADER; +unsigned int TRIANGLES = GL_TRIANGLES; +unsigned int STATIC_DRAW = GL_STATIC_DRAW; +unsigned int DYNAMIC_DRAW = GL_DYNAMIC_DRAW; + +// OpenGL functions used below +void enableDepthTest() { + glEnable(GL_DEPTH_TEST); +} + +void viewport(int width, int height) { + glViewport(0, 0, width, height); +} + +void clearColor(float r, float g, float b, float a) { + glClearColor(r, g, b, a); +} + +void clear() { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +unsigned int createBuffer() { + unsigned int buffer; + glGenBuffers(1, &buffer); + return buffer; +} + +void bindBuffer(unsigned int buffer) { + glBindBuffer(GL_ARRAY_BUFFER, buffer); +} + +void bufferData(float* vector, int vectorLength, unsigned int updateMode) { + glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vectorLength, vector, updateMode); +} + +unsigned int createShader(unsigned int shaderType) { + return glCreateShader(shaderType); +} + +void shaderSource(unsigned int shader, const char *sourceString) { + glShaderSource(shader, 1, &sourceString, NULL); +} + +void compileShader(unsigned int shader) { + glCompileShader(shader); +} + +void deleteShader(unsigned int shader) { + glDeleteShader(shader); +} + +void vertexAttribPointer(int location, int numVecComponents, int stride, int offset) { + glVertexAttribPointer(location, numVecComponents, GL_FLOAT, GL_FALSE, stride * sizeof(float), (void*)offset); +} + +void enableVertexAttribArray(int location) { + glEnableVertexAttribArray(location); +} + +unsigned int createProgram() { + return glCreateProgram(); +} + +void attachShader(unsigned int program, unsigned int shader) { + glAttachShader(program, shader); +} + +void linkProgram(unsigned int program) { + glLinkProgram(program); +} + +void useProgram(unsigned int program) { + glUseProgram(program); +} + +void deleteProgram(unsigned int program) { + glDeleteProgram(program); +} + +void drawArrays(unsigned int drawMode, int startIndex, int numVertices) { + glDrawArrays(drawMode, startIndex, numVertices); +} + +int getUniformLocation(unsigned int program, const char *uniformName) { + glGetUniformLocation(program, uniformName); +} + +void uniform4f(int uniformLocation, float a, float b, float c, float d) { + glUniform4f(uniformLocation, a, b, c, d); +} diff --git a/ffi/rgfw-export.sml b/ffi/rgfw-import.sml similarity index 100% rename from ffi/rgfw-export.sml rename to ffi/rgfw-import.sml diff --git a/shell/glfw-loop.sml b/shell/glfw-loop.sml index 504ed9f..64a8807 100644 --- a/shell/glfw-loop.sml +++ b/shell/glfw-loop.sml @@ -170,7 +170,8 @@ struct val _ = Glfw.windowHint (Glfw.DEPRECATED (), Glfw.FALSE ()) val window = Glfw.createWindow (1920, 1080, "shf") val _ = Glfw.makeContextCurrent window - val _ = Gles3.loadGlad () + val _ = Glfw.loadGlad () + val _ = Gles3.enableDepthTest () (* load file intol gap buffer and create initial app *) val io = TextIO.openIn "temp.txt" diff --git a/shf-rgfw b/shf-rgfw index 7565d3a..1df92f1 100755 Binary files a/shf-rgfw and b/shf-rgfw differ diff --git a/shf-rgfw.mlb b/shf-rgfw.mlb index cc6957e..bd2f422 100644 --- a/shf-rgfw.mlb +++ b/shf-rgfw.mlb @@ -5,6 +5,7 @@ $(SML_LIB)/basis/mlton.mlb ann "allowFFI true" in - ffi/rgfw-export.sml + ffi/rgfw-import.sml + ffi/gles3-import.sml end shell/rgfw-loop.sml