Added cglm as a math dependency, Added transform based rendering of penger

This commit is contained in:
2026-01-18 16:52:47 +01:00
parent de60139030
commit 8953d8a098
3 changed files with 44 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ target_link_libraries( Pacman
target_include_directories(Pacman
PRIVATE "libs/rgfw/"
PRIVATE "libs/glad/include"
PRIVATE "libs/cglm"
)

View File

@@ -2,9 +2,11 @@
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTex;
uniform mat4 transform;
out vec2 texCoord;
void main(){
gl_Position = vec4(aPos, 1.0);
gl_Position = transform * vec4(aPos, 1.0);
texCoord = aTex;
}

View File

@@ -6,6 +6,9 @@
#include "RGFW.h"
#include <glad/glad.h>
#include <stdio.h>
#include "cam.h"
#include "affine.h"
#include "mat4.h"
uint CompileShader(const char *FilePath, GLenum ShaderType) ;
float vertices[] = {
0.5f, 0.5f, 0.0f, 0.5f, -0.5f, 0.0f, -0.5f, -0.5f, 0.0f, -0.5f, 0.5f, 0.0f,
@@ -19,6 +22,14 @@ float texCoords [] ={
uint indices[] = {0, 1, 3, 1, 2, 3};
// TODO: Efficiently align it!!
typedef struct {
float scale;
vec3 position;
mat4 matrix;
} Transform_t;
struct {
unsigned int shaderProgram;
unsigned int VAO;
@@ -183,11 +194,39 @@ void clearScreen(){
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
mat4 transform;
void calcTransform(){
mat4 ortho;
const float asp_ratio = 0.75f;
glm_ortho_default(asp_ratio,ortho);
glm_translate_z(ortho, 1);
mat4 scale ;
glm_mat4_identity(scale);
float s = .25f;
glm_scale(scale, &s);
mat4 local ;
glm_mat4_identity (local);
glm_translate(local, (vec3){2.0,0.0,0.0});
mat4 temp;
glm_mat4_mul( scale, local, temp);
glm_mat4_mul(temp ,ortho , transform);
}
void Render(RGFW_window * win){
glUseProgram(RenderVariables.shaderProgram);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glUniform1i(glGetUniformLocation(RenderVariables.shaderProgram, "image"), 0);
glUniformMatrix4fv (glGetUniformLocation(RenderVariables.shaderProgram, "transform" ),1,GL_FALSE, transform[0]);
glBindVertexArray(RenderVariables.VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
RGFW_window_swapBuffers_OpenGL(win);
@@ -202,6 +241,7 @@ void Update(){
int main(int argc, char **argv) {
RGFW_window *win = SetupWindow();
Setup();
calcTransform();
while (RGFW_window_shouldClose(win) == RGFW_FALSE) {
RGFW_event event;
RGFW_pollEvents();