Reverted back to old array thing

pull/1/head
E. Almqvist 2 years ago
parent 902f3484cf
commit 2ad685b874
  1. 5
      headers/renderer.hpp
  2. 26
      src/main.cpp
  3. 18
      src/renderer.cpp

@ -21,16 +21,15 @@
namespace Renderer {
class RenderObject {
public:
RenderObject(std::vector<float> verts, std::vector<unsigned int> indices);
RenderObject(float verts[], unsigned int indices[]);
void render(GLFWwindow* win, glm::mat4 cameraTransform, glm::mat4 projectionTransform);
void transform(glm::mat4 T);
private:
Shaders::Shader shader;
unsigned int vertCount;
unsigned int EBO;
unsigned int VBO;
unsigned int VAO;
std::vector<float> vertsVec;
std::vector<unsigned int> indicesVec;
};
class Renderer3D {

@ -49,8 +49,6 @@ int main() {
return 1;
}
Renderer::Renderer3D renderer(win);
glfwMakeContextCurrent(win);
if ( !gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) ) {
@ -58,18 +56,18 @@ int main() {
return 1;
}
std::vector<float> verts({
float verts[] = {
0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f
});
};
// Vert struc: x y z r g b tx ty
std::vector<unsigned int> indices({
unsigned int indices[] = {
0, 1, 3,
1, 2, 3
});
};
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glfwSetFramebufferSizeCallback(win, framebuffer_size_callback);
@ -77,10 +75,15 @@ int main() {
float borderColor[] = {1.0f, 1.0f, 1.0f, 1.0f};
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
Renderer::RenderObject ro(verts, indices);
renderer.spawnObject(ro);
// ro.setTexture(RUSTY_METAL_TEXTURE);
printf("%u %u\n", sizeof(indices), sizeof(verts));
Renderer::Obj2D ro2(indices, sizeof(indices), verts, sizeof(verts));
ro2.setTexture(RUSTY_METAL_TEXTURE);
// Renderer::RenderObject ro(verts, indices);
// Renderer::Renderer3D renderer(win);
// renderer.spawnObject(ro);
// ro.setTexture(RUSTY_METAL_TEXTURE);
// Window width & height
while (!glfwWindowShouldClose(win)) {
// Handle input
@ -99,9 +102,10 @@ int main() {
glm::mat4 T = glm::mat4(1.0f);
T = glm::rotate(T, rotang, glm::vec3(1.0, 0.0, 1.0));
T = glm::scale(T, glm::vec3(0.5, 0.5, 0.5));
ro.transform(T);
ro2.transform(T);
ro2.render(win);
renderer.render();
//renderer.render();
// glfw
glfwSwapBuffers(win);

@ -1,3 +1,4 @@
#include <cstdio>
#include <glad/glad.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
@ -39,27 +40,26 @@ namespace Renderer {
}
// RenderObject
RenderObject::RenderObject(std::vector<float> verts, std::vector<unsigned int> indices)
RenderObject::RenderObject(float verts[], unsigned int indices[])
: shader(VERT_SHADER_SRC_FILE, FRAG_SHADER_SRC_FILE) {
vertsVec = verts;
indicesVec = indices;
float* vertsArray = &vertsVec[0];
unsigned int* indicesArray = &indicesVec[0];
// Vertex Array Object
glGenVertexArrays(1, &VAO); // gen the VAO
glBindVertexArray(VAO); // bind it
// Copy the verts into the buffer
// unsigned int vertsSize = sizeof(verts);
unsigned int vertsSize = 4;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertsVec.size(), vertsArray, GL_DYNAMIC_DRAW); // for moving stuff
glBufferData(GL_ARRAY_BUFFER, vertsSize, verts, GL_DYNAMIC_DRAW); // for moving stuff
// Copy the indices for the verts into another buffer
// vertCount = sizeof(indices);
vertCount = 6;
glGenBuffers(1, &EBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesVec.size(), indicesArray, GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertCount, indices, GL_STATIC_DRAW);
// Shader stuff
// Pos
@ -82,7 +82,7 @@ namespace Renderer {
shader.use();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glDrawElements(GL_TRIANGLES, indicesVec.size(), GL_UNSIGNED_INT, 0);
glDrawElements(GL_TRIANGLES, vertCount, GL_UNSIGNED_INT, 0);
}
void RenderObject::transform(glm::mat4 T) {

Loading…
Cancel
Save