added perspective

This commit is contained in:
2026-04-16 02:04:32 +02:00
parent 71753ea29b
commit af1e96ce6d
3 changed files with 18 additions and 8 deletions

View File

@@ -9,9 +9,10 @@
#include "VertexBuffer.hpp"
#include "Shader.hpp"
#define STB_IMAGE_IMPLEMENTATION
#include "../libs/stb_image.hpp"
#include "../libs/glm/glm.hpp"
#include "../libs/glm/ext/matrix_transform.hpp"
#include "stb_image.hpp"
#include "glm/glm.hpp"
#include "glm/ext/matrix_transform.hpp"
#include "glm/gtc/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)
@@ -165,10 +166,17 @@ int main() {
uint64 lastCounter = SDL_GetPerformanceCounter();
float32 delta = 0.0f;
glm::mat4 model = glm::mat4(1.0f);
auto model = glm::mat4(1.0f);
model = glm::scale(model, glm::vec3(1.2f));
int modelMatrixLocation = glGetUniformLocation(shader.getShaderId(), "u_model");
auto projection = glm::ortho(-2.0f, 2.0f, -2.0f, 2.0f, -10.0f, 100.0f);
projection = glm::perspective(glm::radians(45.0f), 4.0f/3.0f, 0.1f, 100.0f);
auto view = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -3.0f));
auto modelViewProj = projection * view * model;
int modelViewProjMatrixLocation = glGetUniformLocation(shader.getShaderId(), "u_modelViewProj");
// WIREFRAME
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
@@ -183,6 +191,7 @@ int main() {
time += delta;
model = glm::rotate(model, 1.0f*delta, glm::vec3(0.0f, 1.0f, 0.0f));
modelViewProj = projection * view * model;
if (colorUniformLocation != 1) {
glUniform4f(colorUniformLocation, sinf(time)*sinf(time), 0.0f, 1.0f, 1.0f);
@@ -191,7 +200,7 @@ int main() {
// FRAME GENERATION
vertexBuffer.bind();
indexBuffer.bind();
glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &model[0][0]);
glUniformMatrix4fv(modelViewProjMatrixLocation, 1, GL_FALSE, &modelViewProj[0][0]);
//glActiveTexture(GL_TEXTURE0);
//glBindTexture(GL_TEXTURE_2D, textureId);
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0);