added rotation

This commit is contained in:
2026-04-16 01:41:31 +02:00
parent 952c5062bc
commit 3fb766de7c
3 changed files with 18 additions and 11 deletions

View File

@@ -10,6 +10,8 @@
#include "Shader.hpp"
#define STB_IMAGE_IMPLEMENTATION
#include "../libs/stb_image.hpp"
#include "../libs/glm/glm.hpp"
#include "../libs/glm/ext/matrix_transform.hpp"
void openGLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) {
if (severity == GL_DEBUG_SEVERITY_NOTIFICATION) return; //ignore notifications (mostly performance information)
@@ -105,22 +107,17 @@ int main() {
Vertex{-0.5f, -0.5f, 0.0f,
0.0f, 0.0f,
1.0f, 0.0f, 0.0f, 1.0f},
Vertex{-0.5f, 0.5f, 0.0f,
Vertex{0.5f, -0.5f, 0.0f,
0.0f, 1.0f,
0.0, 1.0f, 0.0f, 1.0f},
Vertex{0.5f, -0.5f, 0.0f,
Vertex{0.0f, 0.5f, 0.0f,
1.0f, 0.0f,
0.0f, 0.0f, 1.0f, 1.0f},
Vertex{0.5f, 0.5f, 0.0f,
1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f},
};
uint32 numVertices = sizeof(vertices) / sizeof(Vertex);
uint32 indices[] = {
0, 1, 2,
1, 2, 3
};
uint32 numIndices = sizeof(indices) / sizeof(uint32);
@@ -168,6 +165,11 @@ int main() {
uint64 lastCounter = SDL_GetPerformanceCounter();
float32 delta = 0.0f;
glm::mat4 model = glm::mat4(1.0f);
model = glm::scale(model, glm::vec3(1.2f));
int modelMatrixLocation = glGetUniformLocation(shader.getShaderId(), "u_model");
// WIREFRAME
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
@@ -180,6 +182,8 @@ int main() {
glClear(GL_COLOR_BUFFER_BIT);
time += delta;
model = glm::rotate(model, 1.0f*delta, glm::vec3(0.0f, 1.0f, 0.0f));
if (colorUniformLocation != 1) {
glUniform4f(colorUniformLocation, sinf(time)*sinf(time), 0.0f, 1.0f, 1.0f);
}
@@ -187,8 +191,9 @@ int main() {
// FRAME GENERATION
vertexBuffer.bind();
indexBuffer.bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureId);
glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &model[0][0]);
//glActiveTexture(GL_TEXTURE0);
//glBindTexture(GL_TEXTURE_2D, textureId);
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0);
vertexBuffer.unbind();
indexBuffer.unbind();