Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Vertex.h
- #pragma once
- #include <glm\glm.hpp>
- struct vertex{
- glm::vec3 position;
- glm::vec3 colour;
- //GLfloat alpha;
- };
- /////////////////////////////////////////////////////////////////////////////////////////////////
- //Shape.h
- #pragma once
- #include <GL/glew.h>
- #include <memory>
- #include "Vertex.h"
- struct shape{
- shape():
- numVerts(0), numIndices(0){}
- std::unique_ptr<vertex> vertices; //Vertex list of this 3D shape
- GLuint numVerts;
- std::unique_ptr<GLushort> indices; //OpenGL indices.
- GLuint numIndices;
- //Enables us to easily get the buffer size required.
- GLsizeiptr vertexBufferSize() const
- {
- return numVerts * sizeof(vertex);
- };
- GLsizeiptr indexBufferSize() const
- {
- return numIndices * sizeof(GLushort);
- };
- |}; <-- Here the cursor ends up when I double click on the first error.
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //GenerateShape.h
- pragma once
- #include "Shape.h"
- class GenerateShape
- {
- public:
- static shape makeCube();
- GenerateShape::GenerateShape(void);
- GenerateShape::~GenerateShape(void);
- };
- -------------------------------------------------
- //GenerateShape.cpp
- #include "GenerateShape.h"
- #include <glm/glm.hpp>
- #include "Vertex.h"
- #define NUM_ELEMENTS_ARRAY(a) sizeof(a)/ sizeof(*a)
- shape GenerateShape::makeCube()
- {
- shape retShape;
- vertex vertices[] = {
- //Position //Colour //Vertex ID
- glm::vec3(0.0f, -0.1f, 0.5f), glm::vec3(1.0f, 1.0f, 1.0f), //0
- glm::vec3(0.5f, 0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.3f), //1
- glm::vec3(0.5f, 0.5f, 0.0f), glm::vec3(1.0f, 0.5f, 0.0f), //2
- glm::vec3(0.0f, 0.6f, 0.5f), glm::vec3(1.0f, 0.5f, 0.3f), //3
- glm::vec3(-0.5f, 0.5f, 0.0f), glm::vec3(0.0f, 0.5f, 0.3f), //4
- glm::vec3(-0.5f, 0.0f, 0.0f), glm::vec3(1.0f, 0.9f, 0.3f), //5
- glm::vec3(0.0f, 0.0f, -0.5f), glm::vec3(1.0f, 0.0f, 0.0f), //6
- glm::vec3(0.0f, 0.5f, -0.5f), glm::vec3(1.0f, 1.0f, 0.3f) //7
- };
- //Triangle sets
- GLushort elements[] = {
- 0, 1, 2,
- 0, 2, 3,
- 0, 4, 5,
- 0, 3, 4,
- 0, 5, 6,
- 0, 6, 1,
- 1, 2, 7,
- 2, 3, 7,
- 3, 4, 7,
- 4, 5, 7,
- 5, 6, 7,
- 6, 1, 7
- };
- retShape.numVerts = NUM_ELEMENTS_ARRAY(vertices);
- retShape.vertices = std::unique_ptr<vertex>(new vertex[retShape.numVerts]);
- retShape.numIndices = NUM_ELEMENTS_ARRAY(elements);
- retShape.indices = std::unique_ptr<GLushort>(new GLushort[retShape.numIndices]);
- memcpy(retShape.vertices.get(), vertices, sizeof(vertices));
- memcpy(retShape.indices.get(), elements, sizeof(elements));
- return retShape;
- }
- GenerateShape::GenerateShape(void)
- {
- }
- GenerateShape::~GenerateShape(void)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment