added rotation
This commit is contained in:
@@ -10,5 +10,5 @@ uniform vec4 u_color;
|
||||
|
||||
void main() {
|
||||
vec4 texColor = texture(u_texture, v_texCoord);
|
||||
f_color = texColor;
|
||||
f_color = v_color;
|
||||
}
|
||||
@@ -7,8 +7,10 @@ layout(location = 2) in vec4 a_color;
|
||||
out vec4 v_color;
|
||||
out vec2 v_texCoord;
|
||||
|
||||
uniform mat4 u_model;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_position, 1.0f);
|
||||
gl_Position = u_model * vec4(a_position, 1.0f);
|
||||
v_color = a_color;
|
||||
v_texCoord = a_texCoord;
|
||||
}
|
||||
23
src/main.cpp
23
src/main.cpp
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user