Show my square
This commit is contained in:
parent
41b99aa442
commit
d5788228f6
@ -1,10 +1,12 @@
|
||||
#include "Ball.h"
|
||||
|
||||
Ball::Ball() {
|
||||
vertices.push_back(Vertex(0.0f, 0.0f, 0.0f));
|
||||
vertices.push_back(Vertex(1.0f, 0.0f, 0.0f));
|
||||
vertices.push_back(Vertex(0.5f, 1.0f, 0.0f));
|
||||
vertices.push_back(Vertex(1.0f, 1.0f, -1.0f));
|
||||
vertices.push_back(Vertex(1.0f, -1.0f, -1.0f));
|
||||
vertices.push_back(Vertex(-1.0f, 1.0f, -1.0f));
|
||||
vertices.push_back(Vertex(-1.0f, -1.0f, -1.0f));
|
||||
|
||||
indices.push_back(Index(0, 1, 2));
|
||||
indices.push_back(Index(1, 2, 3));
|
||||
}
|
||||
|
||||
|
@ -65,9 +65,22 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath) {
|
||||
|
||||
glDeleteShader(vertex);
|
||||
glDeleteShader(fragment);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Shader::Use() {
|
||||
glUseProgram(id);
|
||||
}
|
||||
|
||||
void Shader::UpdateView(Matrix view) {
|
||||
glUniformMatrix4fv(glGetUniformLocation(id, "VIEW"), 1, GL_FALSE, glm::value_ptr(view));
|
||||
}
|
||||
|
||||
void Shader::UpdateModel(Matrix model) {
|
||||
glUniformMatrix4fv(glGetUniformLocation(id, "MODEL"), 1, GL_FALSE, glm::value_ptr(model));
|
||||
}
|
||||
|
||||
void Shader::UpdateProjection(Matrix projection) {
|
||||
glUniformMatrix4fv(glGetUniformLocation(id, "PROJECTION"), 1, GL_FALSE, glm::value_ptr(projection));
|
||||
}
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
class Shader {
|
||||
@ -14,6 +16,9 @@ public:
|
||||
|
||||
Shader(const char *vertexPath, const char *fragmentPath);
|
||||
void Use();
|
||||
void UpdateView(Matrix view);
|
||||
void UpdateModel(Matrix model);
|
||||
void UpdateProjection(Matrix projection);
|
||||
};
|
||||
|
||||
#endif /* SHADER_H */
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include "Shader.h"
|
||||
@ -42,10 +44,18 @@ int main() {
|
||||
Ball ball;
|
||||
ball.SetupMesh();
|
||||
|
||||
Matrix projection = glm::perspective(glm::radians(45.0f), 800.0f/600.0f, 0.1f, 100.0f);
|
||||
shader.UpdateProjection(projection);
|
||||
Matrix view(1.0f);
|
||||
shader.UpdateView(view);
|
||||
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
||||
Matrix model(1.0f);
|
||||
model = glm::translate(model, ball.transform.position);
|
||||
shader.UpdateModel(model);
|
||||
ball.Draw();
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
typedef GLFWwindow Window;
|
||||
typedef glm::vec3 Vector3;
|
||||
typedef glm::mat4 Matrix;
|
||||
typedef GLfloat cfloat;
|
||||
typedef GLuint Id;
|
||||
|
||||
|
@ -2,11 +2,10 @@
|
||||
|
||||
layout (location = 0) in vec3 pos;
|
||||
|
||||
// uniform mat4 MODEL;
|
||||
// uniform mat4 VIEW;
|
||||
// uniform mat4 PROJECTION;
|
||||
uniform mat4 MODEL;
|
||||
uniform mat4 VIEW;
|
||||
uniform mat4 PROJECTION;
|
||||
|
||||
void main() {
|
||||
//gl_Position = MODEL * VIEW * PROJECTION * vec4(pos, 1.0);
|
||||
gl_Position = vec4(pos, 1.0);
|
||||
gl_Position = PROJECTION * VIEW * MODEL * vec4(pos, 1.0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user