X-Git-Url: http://git.lukelau.me/?p=wasm.git;a=blobdiff_plain;f=test.cpp;fp=test.cpp;h=cbdf3707e6cd47a2a6259809024a112009c61135;hp=065ed80de76182eded8aab8c084ba78751d82050;hb=1f4d729cfaaed2c371065bad05fe1f345d3b26ee;hpb=54f82247de6f51a7e30a935d3a533745691bcbb6 diff --git a/test.cpp b/test.cpp index 065ed80..cbdf370 100644 --- a/test.cpp +++ b/test.cpp @@ -1,11 +1,15 @@ #include #include #include +#include +#include +#include const char* vertShaderSrc = R"( attribute vec4 vertPos; +uniform mat4 model; void main() { - gl_Position = vertPos; + gl_Position = model * vertPos; } )"; @@ -15,6 +19,8 @@ void main() { } )"; +GLuint program; + extern "C" void setup() { GLuint vertShader = glCreateShader(GL_VERTEX_SHADER); const char* sources[1] = { vertShaderSrc }; @@ -28,7 +34,7 @@ extern "C" void setup() { new const GLint[1] { (GLint)strlen(fragShaderSrc) }); glCompileShader(fragShader); - GLuint program = glCreateProgram(); + program = glCreateProgram(); glAttachShader(program, vertShader); glAttachShader(program, fragShader); glLinkProgram(program); @@ -48,3 +54,9 @@ extern "C" void setup() { glEnableVertexAttribArray(vertPosLoc); glVertexAttribPointer(vertPosLoc, 3, GL_FLOAT, false, 0, 0); } + +extern "C" void update(int tick) { + GLuint modelLoc = glGetUniformLocation(program, "model"); + const glm::mat4 model = glm::rotate(glm::mat4(1), (float)tick * 0.001f, glm::vec3(0, 0, 1)); + glUniformMatrix4fv(modelLoc, 1, false, glm::value_ptr(model)); +}