Added objects
This commit is contained in:
parent
f86fcad89f
commit
107e207a83
5 changed files with 53 additions and 10 deletions
|
@ -65,7 +65,7 @@ int main(int argc, char** argv)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Make a square
|
// Make a square
|
||||||
oglu::VertexArray square = oglu::MakeVertexArray(vertices, sizeof(vertices), indices, sizeof(indices), topology, sizeof(topology));
|
oglu::Object square(vertices, sizeof(vertices), indices, sizeof(indices), topology, sizeof(topology));
|
||||||
|
|
||||||
// Create a shader
|
// Create a shader
|
||||||
oglu::Shader shader;
|
oglu::Shader shader;
|
||||||
|
@ -83,17 +83,12 @@ int main(int argc, char** argv)
|
||||||
oglu::Texture crate = oglu::MakeTexture("assets/crate.jpg");
|
oglu::Texture crate = oglu::MakeTexture("assets/crate.jpg");
|
||||||
oglu::Texture opengl = oglu::MakeTexture("assets/opengl.png");
|
oglu::Texture opengl = oglu::MakeTexture("assets/opengl.png");
|
||||||
|
|
||||||
oglu::Transformable model;
|
|
||||||
//model.SetRotation(-55.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
glm::mat4 view = glm::mat4(1.0f);
|
glm::mat4 view = glm::mat4(1.0f);
|
||||||
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));
|
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));
|
||||||
|
|
||||||
glm::mat4 projection;
|
glm::mat4 projection;
|
||||||
projection = glm::perspective(glm::radians(45.f), 1.0f, 0.1f, 100.0f);
|
projection = glm::perspective(glm::radians(45.f), 1.0f, 0.1f, 100.0f);
|
||||||
|
|
||||||
glm::mat4 test = glm::make_mat4(model.GetMatrix());
|
|
||||||
|
|
||||||
// Window loop
|
// Window loop
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
|
@ -101,16 +96,16 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
oglu::ClearScreen(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f));
|
oglu::ClearScreen(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f));
|
||||||
|
|
||||||
model.Rotate(6.0f, 0.0f, 0.0f);
|
square.Rotate(6.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
shader->Use();
|
shader->Use();
|
||||||
shader->SetUniform("texture1", crate, 0);
|
shader->SetUniform("texture1", crate, 0);
|
||||||
shader->SetUniform("texture2", opengl, 1);
|
shader->SetUniform("texture2", opengl, 1);
|
||||||
shader->SetUniformMatrix4fv("model", 1, GL_FALSE, model.GetMatrix());
|
shader->SetUniformMatrix4fv("model", 1, GL_FALSE, square.GetMatrix());
|
||||||
shader->SetUniformMatrix4fv("view", 1, GL_FALSE, glm::value_ptr(view));
|
shader->SetUniformMatrix4fv("view", 1, GL_FALSE, glm::value_ptr(view));
|
||||||
shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, glm::value_ptr(projection));
|
shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, glm::value_ptr(projection));
|
||||||
|
|
||||||
square->BindAndDraw();
|
square.Render();
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
24
include/object.hpp
Normal file
24
include/object.hpp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef OBJECT_HPP
|
||||||
|
#define OBJECT_HPP
|
||||||
|
|
||||||
|
#include <core.hpp>
|
||||||
|
#include <transformable.hpp>
|
||||||
|
#include <vertexArray.hpp>
|
||||||
|
|
||||||
|
namespace oglu
|
||||||
|
{
|
||||||
|
class OGLU_API Object : public Transformable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Object(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize);
|
||||||
|
Object(const Object& other);
|
||||||
|
~Object();
|
||||||
|
|
||||||
|
void Render();
|
||||||
|
|
||||||
|
private:
|
||||||
|
VertexArray VAO;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -12,6 +12,7 @@
|
||||||
#include <vertexArray.hpp>
|
#include <vertexArray.hpp>
|
||||||
#include <shader.hpp>
|
#include <shader.hpp>
|
||||||
#include <texture.hpp>
|
#include <texture.hpp>
|
||||||
|
#include <object.hpp>
|
||||||
|
|
||||||
namespace oglu
|
namespace oglu
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace oglu
|
||||||
/**
|
/**
|
||||||
* @brief Structure to store topology data.
|
* @brief Structure to store topology data.
|
||||||
*/
|
*/
|
||||||
OGLU_API struct VertexAttribute {
|
struct OGLU_API VertexAttribute {
|
||||||
/*@{*/
|
/*@{*/
|
||||||
GLuint index; ///< Index of the vertex attribute
|
GLuint index; ///< Index of the vertex attribute
|
||||||
GLint size; ///< Number of elements in this attribute
|
GLint size; ///< Number of elements in this attribute
|
||||||
|
|
23
src/object.cpp
Normal file
23
src/object.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include "object.hpp"
|
||||||
|
|
||||||
|
namespace oglu
|
||||||
|
{
|
||||||
|
Object::Object(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize) :
|
||||||
|
VAO(MakeVertexArray(vertices, verticesSize, indices, indicesSize, topology, topologySize))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::Object(const Object& other) :
|
||||||
|
VAO(other.VAO)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::~Object()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Object::Render()
|
||||||
|
{
|
||||||
|
VAO->BindAndDraw();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue