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

@@ -18,6 +18,7 @@ add_executable(${PROJECT_NAME} src/main.cpp
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:Debug>:_DEBUG>)
target_include_directories(${PROJECT_NAME} PRIVATE include)
target_include_directories(${PROJECT_NAME} PRIVATE libs)
target_include_directories(${PROJECT_NAME} PRIVATE shaders)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD

View File

@@ -7,10 +7,10 @@ layout(location = 2) in vec4 a_color;
out vec4 v_color;
out vec2 v_texCoord;
uniform mat4 u_model;
uniform mat4 u_modelViewProj;
void main() {
gl_Position = u_model * vec4(a_position, 1.0f);
gl_Position = u_modelViewProj * vec4(a_position, 1.0f);
v_color = a_color;
v_texCoord = a_texCoord;
}

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);