Skip to content
Snippets Groups Projects
Commit a843dd8a authored by Martin Štourač's avatar Martin Štourač
Browse files

draw uses object atributes

parent 55425c62
No related branches found
No related tags found
No related merge requests found
...@@ -15,10 +15,6 @@ class Object ...@@ -15,10 +15,6 @@ class Object
std::vector<float> vertices; std::vector<float> vertices;
std::vector<unsigned int> indices; std::vector<unsigned int> indices;
// VAO VAO;
// VBO VBO;
// EBO EBO;
public: public:
Object(glm::vec3 position, std::vector<float> &_vertices, std::vector<unsigned int> &_indices); Object(glm::vec3 position, std::vector<float> &_vertices, std::vector<unsigned int> &_indices);
......
...@@ -11,9 +11,7 @@ ...@@ -11,9 +11,7 @@
#include <iostream> #include <iostream>
Shader create_shader_program(); Shader create_shader_program();
void get_vertices(float*& vertices, unsigned int &size);
void get_indices(unsigned int*& indices, unsigned int &size);
bool create_buffer(VAO &VAO, VBO &VBO, EBO &EBO); bool create_buffer(VAO &VAO, VBO &VBO, EBO &EBO);
void gfx_draw(Shader &myShader, VAO &VAO, Camera camera); void gfx_draw(Shader &myShader, VAO &VAO, Camera camera, Object object);
#endif #endif
\ No newline at end of file
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <gfx/vao.hpp> #include <gfx/vao.hpp>
#include <gfx/vbo.hpp> #include <gfx/vbo.hpp>
#include <gfx/ebo.hpp> #include <gfx/ebo.hpp>
#include <gfx/camera.hpp>
#include <gfx/object.hpp>
#include <gfx/render.hpp> // Order important for compile #include <gfx/render.hpp> // Order important for compile
#include <gfx/shader.hpp> #include <gfx/shader.hpp>
#include <iostream> #include <iostream>
...@@ -23,77 +25,6 @@ Shader create_shader_program() ...@@ -23,77 +25,6 @@ Shader create_shader_program()
return myShader; return myShader;
} }
void get_vertices(float*& vertices, unsigned int &size)
{
// TRIANGLE
float traingle[] = {
-0.5f, -0.5f, 0.0f, // left
0.5f, -0.5f, 0.0f, // right
0.0f, 0.5f, 0.0f // top
};
// RECTANGLE
float rectangle[] = {
0.5f, 0.5f, 0.0f, // top right
0.5f, -0.5f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, // bottom left
-0.5f, 0.5f, 0.0f // top left
};
// CUBE
float cube[] =
{
// positions // texture coords
//front
0.2f, 0.2f, 0.0f, // top right
0.2f, -0.2f, 0.0f, // bottom right
-0.2f, -0.2f, 0.0f, // bottom left
-0.2f, 0.2f, 0.0f, // top left
//back
0.2f, 0.2f, -0.4f, // top right
0.2f, -0.2f, -0.4f, // bottom right
-0.2f, -0.2f, -0.4f, // bottom left
-0.2f, 0.2f, -0.4f // top left
};
vertices = cube;
size = sizeof(vertices);
}
void get_indices(unsigned int*& indices, unsigned int &size)
{
unsigned int triangle[] = { // note that we start from 0!
0, 1, 3, // first triangle
1, 2, 3 // second triangle
};
unsigned int cube[] =
{
// front
0, 1, 3,
1, 2, 3,
// back
4, 5, 7,
5, 6, 7,
// right
0, 1, 4,
1, 4, 5,
// left
2, 3, 7,
2, 6, 7,
// top
0, 3, 4,
3, 4, 7,
// bottom
1, 2, 5,
2, 5, 6
};
indices = cube;
size = sizeof(indices);
}
bool create_buffer(VAO &VAO, VBO &VBO, EBO &EBO) // UNUSED bool create_buffer(VAO &VAO, VBO &VBO, EBO &EBO) // UNUSED
{ {
VAO.LinkVBO(VBO); VAO.LinkVBO(VBO);
...@@ -115,7 +46,7 @@ void send_matrices_to_shader(Shader &myShader, glm::mat4 &model, glm::mat4 &view ...@@ -115,7 +46,7 @@ void send_matrices_to_shader(Shader &myShader, glm::mat4 &model, glm::mat4 &view
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection)); glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));
} }
void gfx_draw(Shader &myShader, VAO &VAO, Camera camera) void gfx_draw(Shader &myShader, VAO &VAO, Camera camera, Object object)
{ {
glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
...@@ -130,6 +61,7 @@ void gfx_draw(Shader &myShader, VAO &VAO, Camera camera) ...@@ -130,6 +61,7 @@ void gfx_draw(Shader &myShader, VAO &VAO, Camera camera)
glm::mat4 model = glm::mat4(1.0f); glm::mat4 model = glm::mat4(1.0f);
model = glm::rotate(model, glm::radians(-55.0f), glm::vec3(1.0f, 0.0f, 0.0f)); model = glm::rotate(model, glm::radians(-55.0f), glm::vec3(1.0f, 0.0f, 0.0f));
model = glm::translate(model, object.getPosition());
//model = glm::rotate(model, ((float)SDL_GetTicks() / 1000) * glm::radians(50.0f), glm::vec3(0.5f, 1.0f, 0.0f)); //model = glm::rotate(model, ((float)SDL_GetTicks() / 1000) * glm::radians(50.0f), glm::vec3(0.5f, 1.0f, 0.0f));
// // glm::mat4 view = glm::mat4(1.0f); // // glm::mat4 view = glm::mat4(1.0f);
...@@ -160,7 +92,10 @@ void gfx_draw(Shader &myShader, VAO &VAO, Camera camera) ...@@ -160,7 +92,10 @@ void gfx_draw(Shader &myShader, VAO &VAO, Camera camera)
VAO.Bind(); VAO.Bind();
//glDrawArrays(GL_TRIANGLES, 0, 3); //glDrawArrays(GL_TRIANGLES, 0, 3);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES,
static_cast<GLsizei>(object.getIndices().size()),
GL_UNSIGNED_INT,
0);
ASSUMPTION(glGetError() == GL_NO_ERROR); ASSUMPTION(glGetError() == GL_NO_ERROR);
//glBindVertexArray(0); //glBindVertexArray(0);
} }
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
namespace studio { namespace studio {
// OBJECT // OBJECT
glm::vec3 obj_position = { 2.0f, -1.0f, 0.0f }; glm::vec3 obj_position = { 1.0f, -1.0f, 0.0f };
// rotation ? // rotation ? TO DO
std::vector<float> obj_vertices = std::vector<float> obj_vertices =
{ {
// positions // positions
...@@ -58,9 +58,6 @@ Simulator::Simulator() ...@@ -58,9 +58,6 @@ Simulator::Simulator()
, camera{cam_position, cam_direction, FOV} , camera{cam_position, cam_direction, FOV}
, object{obj_position, obj_vertices, obj_indices} , object{obj_position, obj_vertices, obj_indices}
{ {
// get_vertices(vertices, v_size); TO DO
// get_indices(indices, i_size); TO DO
// TO DO: Following paragraph has to happen elsewhere // TO DO: Following paragraph has to happen elsewhere
// eg. create_buffer(myVAO, myVBO, myEBO); //bool // eg. create_buffer(myVAO, myVBO, myEBO); //bool
myVAO.Bind(); myVAO.Bind();
...@@ -106,7 +103,7 @@ void Simulator::present() ...@@ -106,7 +103,7 @@ void Simulator::present()
camera.setWindowSize(window().size()); camera.setWindowSize(window().size());
} }
gfx_draw(myShader, myVAO, camera); gfx_draw(myShader, myVAO, camera, object);
} }
void Simulator::process_input() void Simulator::process_input()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment