|
|
@ -80,12 +80,16 @@ namespace Renderer { |
|
|
|
glEnableVertexAttribArray(2); |
|
|
|
glEnableVertexAttribArray(2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RenderObject::preRenderHook() {} |
|
|
|
|
|
|
|
|
|
|
|
void RenderObject::render(GLFWwindow* win, glm::mat4 cameraTransform, glm::mat4 projectionTransform) { |
|
|
|
void RenderObject::render(GLFWwindow* win, glm::mat4 cameraTransform, glm::mat4 projectionTransform) { |
|
|
|
shader.setMat4("view", cameraTransform); |
|
|
|
shader.setMat4("view", cameraTransform); |
|
|
|
shader.setMat4("projection", projectionTransform); |
|
|
|
shader.setMat4("projection", projectionTransform); |
|
|
|
|
|
|
|
|
|
|
|
shader.use(); |
|
|
|
shader.use(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preRenderHook(); |
|
|
|
|
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); |
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); |
|
|
|
glDrawElements(GL_TRIANGLES, indicesVec.size(), GL_UNSIGNED_INT, 0); |
|
|
|
glDrawElements(GL_TRIANGLES, indicesVec.size(), GL_UNSIGNED_INT, 0); |
|
|
|
} |
|
|
|
} |
|
|
@ -94,65 +98,16 @@ namespace Renderer { |
|
|
|
shader.setMat4("model", T); |
|
|
|
shader.setMat4("model", T); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Obj2D::transform(glm::mat4 T) { |
|
|
|
// Obj2D
|
|
|
|
shader.setMat4("model", T); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Obj2D::setTexture(const char* t_src) { |
|
|
|
void Obj2D::setTexture(const char* t_src) { |
|
|
|
texture.texture_src = t_src; |
|
|
|
texture.texture_src = t_src; |
|
|
|
texture.load(); |
|
|
|
texture.load(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Obj2D::render(GLFWwindow* win) { |
|
|
|
void Obj2D::preRenderHook() { |
|
|
|
int width, height; |
|
|
|
printf("OBJ2D was here!\n"); |
|
|
|
|
|
|
|
|
|
|
|
// Camera
|
|
|
|
|
|
|
|
glm::mat4 view = glm::mat4(1.0f); |
|
|
|
|
|
|
|
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -8.0f)); // Camera position
|
|
|
|
|
|
|
|
shader.setMat4("view", view); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glfwGetWindowSize(win, &width, &height); |
|
|
|
|
|
|
|
glm::mat4 projection = glm::perspective(glm::radians(45.0f), (float)width / (float)height, 0.1f, 100.0f); |
|
|
|
|
|
|
|
shader.setMat4("projection", projection); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Use the shader etc
|
|
|
|
|
|
|
|
shader.use(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (texture.loaded) |
|
|
|
if (texture.loaded) |
|
|
|
texture.bind(); |
|
|
|
texture.bind(); |
|
|
|
|
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); |
|
|
|
|
|
|
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Obj2D::Obj2D(unsigned int indices[], unsigned int icount, float verts[], unsigned int vcount)
|
|
|
|
|
|
|
|
: shader(VERT_SHADER_SRC_FILE, FRAG_SHADER_SRC_FILE) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Vertex Array Object
|
|
|
|
|
|
|
|
glGenVertexArrays(1, &VAO); // gen the VAO
|
|
|
|
|
|
|
|
glBindVertexArray(VAO); // bind it
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Copy the verts into the buffer
|
|
|
|
|
|
|
|
glGenBuffers(1, &VBO); |
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, VBO); |
|
|
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, vcount, verts, GL_DYNAMIC_DRAW); // for moving stuff
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Copy the indices for the verts into another buffer
|
|
|
|
|
|
|
|
glGenBuffers(1, &EBO); |
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); |
|
|
|
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, icount, indices, GL_STATIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pos
|
|
|
|
|
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, VERTEX_ATTRIB_PTR_SIZE, (void*)0); |
|
|
|
|
|
|
|
glEnableVertexAttribArray(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Color
|
|
|
|
|
|
|
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, VERTEX_ATTRIB_PTR_SIZE, (void*)(3*sizeof(float))); |
|
|
|
|
|
|
|
glEnableVertexAttribArray(1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Texture
|
|
|
|
|
|
|
|
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, VERTEX_ATTRIB_PTR_SIZE, (void*)(6*sizeof(float))); |
|
|
|
|
|
|
|
glEnableVertexAttribArray(2); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Private stuff
|
|
|
|
// Private stuff
|
|
|
|