added perspective
This commit is contained in:
@@ -18,6 +18,7 @@ add_executable(${PROJECT_NAME} src/main.cpp
|
|||||||
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:Debug>:_DEBUG>)
|
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:Debug>:_DEBUG>)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE include)
|
target_include_directories(${PROJECT_NAME} PRIVATE include)
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE libs)
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE shaders)
|
target_include_directories(${PROJECT_NAME} PRIVATE shaders)
|
||||||
|
|
||||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ layout(location = 2) in vec4 a_color;
|
|||||||
out vec4 v_color;
|
out vec4 v_color;
|
||||||
out vec2 v_texCoord;
|
out vec2 v_texCoord;
|
||||||
|
|
||||||
uniform mat4 u_model;
|
uniform mat4 u_modelViewProj;
|
||||||
|
|
||||||
void main() {
|
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_color = a_color;
|
||||||
v_texCoord = a_texCoord;
|
v_texCoord = a_texCoord;
|
||||||
}
|
}
|
||||||
21
src/main.cpp
21
src/main.cpp
@@ -9,9 +9,10 @@
|
|||||||
#include "VertexBuffer.hpp"
|
#include "VertexBuffer.hpp"
|
||||||
#include "Shader.hpp"
|
#include "Shader.hpp"
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "../libs/stb_image.hpp"
|
#include "stb_image.hpp"
|
||||||
#include "../libs/glm/glm.hpp"
|
#include "glm/glm.hpp"
|
||||||
#include "../libs/glm/ext/matrix_transform.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) {
|
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)
|
if (severity == GL_DEBUG_SEVERITY_NOTIFICATION) return; //ignore notifications (mostly performance information)
|
||||||
@@ -165,10 +166,17 @@ int main() {
|
|||||||
uint64 lastCounter = SDL_GetPerformanceCounter();
|
uint64 lastCounter = SDL_GetPerformanceCounter();
|
||||||
float32 delta = 0.0f;
|
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));
|
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
|
// WIREFRAME
|
||||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
@@ -183,6 +191,7 @@ int main() {
|
|||||||
time += delta;
|
time += delta;
|
||||||
|
|
||||||
model = glm::rotate(model, 1.0f*delta, glm::vec3(0.0f, 1.0f, 0.0f));
|
model = glm::rotate(model, 1.0f*delta, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
modelViewProj = projection * view * model;
|
||||||
|
|
||||||
if (colorUniformLocation != 1) {
|
if (colorUniformLocation != 1) {
|
||||||
glUniform4f(colorUniformLocation, sinf(time)*sinf(time), 0.0f, 1.0f, 1.0f);
|
glUniform4f(colorUniformLocation, sinf(time)*sinf(time), 0.0f, 1.0f, 1.0f);
|
||||||
@@ -191,7 +200,7 @@ int main() {
|
|||||||
// FRAME GENERATION
|
// FRAME GENERATION
|
||||||
vertexBuffer.bind();
|
vertexBuffer.bind();
|
||||||
indexBuffer.bind();
|
indexBuffer.bind();
|
||||||
glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &model[0][0]);
|
glUniformMatrix4fv(modelViewProjMatrixLocation, 1, GL_FALSE, &modelViewProj[0][0]);
|
||||||
//glActiveTexture(GL_TEXTURE0);
|
//glActiveTexture(GL_TEXTURE0);
|
||||||
//glBindTexture(GL_TEXTURE_2D, textureId);
|
//glBindTexture(GL_TEXTURE_2D, textureId);
|
||||||
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user