diff --git a/src/engine/display/shader.c b/src/engine/display/shader.c index b43db529..23a0cb9d 100644 --- a/src/engine/display/shader.c +++ b/src/engine/display/shader.c @@ -78,10 +78,14 @@ shader_t * shaderCompile(char *vertexShaderSource, char* fragmentShaderSource) { shader->uniProj = glGetUniformLocation(shader->shaderProgram, SHADER_UNI_PROJ); shader->uniView = glGetUniformLocation(shader->shaderProgram, SHADER_UNI_VIEW); shader->uniText = glGetUniformLocation(shader->shaderProgram, SHADER_UNI_TEXT); + shader->uniModl = glGetUniformLocation(shader->shaderProgram, SHADER_UNI_MODL); // Bind the shader shaderUse(shader); + // Reset position + shaderUsePosition(shader, 0, 0, 0, 0, 0, 0); + // Fetch the uniforms. return shader; } @@ -102,9 +106,36 @@ void shaderUseCamera(shader_t *shader, camera_t *camera) { glUniformMatrix4fv(shader->uniView, 1, GL_FALSE, (float*)camera->view); glUniformMatrix4fv(shader->uniProj, 1, GL_FALSE, (float*)camera->projection); } + void shaderUseTexture(shader_t *shader, texture_t *texture) { // OpenGL requires us to set the active texure. glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture->id); glUniform1i(shader->uniText, 0); +} + +void shaderUsePosition(shader_t *shader, + float x, float y, float z, + float pitch, float yaw, float roll +) { + mat4 MATRIX_POSITION; + vec3 axis; + + // Identify mat. + glm_mat4_identity(MATRIX_POSITION); + + //Position + axis[0] = x, axis[1] = y, axis[2] = z; + glm_translate(MATRIX_POSITION, axis); + + //Rotation, we do each axis individually + axis[0] = 1, axis[1] = 0, axis[2] = 0; + glm_rotate(MATRIX_POSITION, pitch, axis); + axis[0] = 0, axis[1] = 1; + glm_rotate(MATRIX_POSITION, yaw, axis); + axis[1] = 0, axis[2] = 1; + glm_rotate(MATRIX_POSITION, roll, axis); + + //Send to the shader. + glUniformMatrix4fv(shader->uniModl, 1, GL_FALSE, (float*)MATRIX_POSITION); } \ No newline at end of file diff --git a/src/engine/display/shader.h b/src/engine/display/shader.h index 427ead4c..a7644fbf 100644 --- a/src/engine/display/shader.h +++ b/src/engine/display/shader.h @@ -17,6 +17,7 @@ #define SHADER_UNI_VIEW "u_View" #define SHADER_UNI_PROJ "u_Proj" #define SHADER_UNI_TEXT "u_Text" +#define SHADER_UNI_MODL "u_Modl" /** * Structure containing information about an OpenGL Shader. For simplicity sake @@ -40,6 +41,9 @@ typedef struct { /** Uniform for the current texture */ GLint uniText; + + /** Uniform for the current model world position */ + GLint uniModl; } shader_t; /** @@ -78,4 +82,9 @@ void shaderUseCamera(shader_t *shader, camera_t *camera); * @param shader Shader to attach to. * @param texture Texture to attach. */ -void shaderUseTexture(shader_t *shader, texture_t *texture); \ No newline at end of file +void shaderUseTexture(shader_t *shader, texture_t *texture); + +void shaderUsePosition(shader_t *shader, + float x, float y, float z, + float pitch, float yaw, float roll +); \ No newline at end of file diff --git a/src/engine/engine.c b/src/engine/engine.c index 2540b6db..ffa1e9f1 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -10,6 +10,9 @@ camera_t *camera; shader_t *shader; primitive_t *cube; +texture_t *texture; + +float bruh; engine_t * engineInit(platform_t *platform, char *name, uint32_t inputCount) { // Create the engine instance. @@ -43,9 +46,13 @@ engine_t * engineInit(platform_t *platform, char *name, uint32_t inputCount) { cameraPerspective(camera, 45.0f, 1920.0f/1080.0f, 0.5f, 100.0f); shaderUseCamera(shader, camera); + texture = assetTextureLoad("bruh.png"); + shaderUseTexture(shader, texture); + // cube = quadCreate(0, 0, 0, 0, 1, 1, 1, 1); cube = cubeCreate(1, 1, 1); - + bruh = 0; + return engine; } @@ -53,6 +60,8 @@ uint32_t engineUpdate(engine_t *engine) { shaderUse(shader); renderFrame(engine->render); + shaderUsePosition(shader, 0, 0, 0, bruh, bruh / 2.0f, bruh / 3.0f); + bruh += 0.0001f; primitiveDraw(cube, 0, cube->indiceCount); inputUpdate(engine->input);