NoobsDeSroobs

Untitled

Jul 27th, 2014
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.68 KB | None | 0 0
  1. //Vertex.h
  2. #pragma once
  3. #include <glm\glm.hpp>
  4.  
  5. struct vertex{
  6.     glm::vec3 position;
  7.     glm::vec3 colour;
  8.     //GLfloat alpha;
  9. };
  10.  
  11. /////////////////////////////////////////////////////////////////////////////////////////////////
  12. //Shape.h
  13. #pragma once
  14. #include <GL/glew.h>
  15. #include <memory>
  16. #include "Vertex.h"
  17.  
  18.  
  19.  
  20. struct shape{
  21.     shape():
  22.         numVerts(0), numIndices(0){}
  23.  
  24.     std::unique_ptr<vertex> vertices; //Vertex list of this 3D shape
  25.     GLuint numVerts;
  26.     std::unique_ptr<GLushort> indices; //OpenGL indices.
  27.     GLuint numIndices; 
  28.     //Enables us to easily get the buffer size required.
  29.     GLsizeiptr vertexBufferSize() const
  30.     {
  31.         return numVerts * sizeof(vertex);
  32.     };
  33.     GLsizeiptr indexBufferSize() const
  34.     {
  35.         return numIndices * sizeof(GLushort);
  36.     };
  37. |}; <-- Here the cursor ends up when I double click on the first error.
  38. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  39. //GenerateShape.h
  40. pragma once
  41.  
  42. #include "Shape.h"
  43.  
  44. class GenerateShape
  45. {
  46. public:
  47.     static shape makeCube();
  48.     GenerateShape::GenerateShape(void);
  49.  
  50.     GenerateShape::~GenerateShape(void);
  51. };
  52.  
  53. -------------------------------------------------
  54. //GenerateShape.cpp
  55. #include "GenerateShape.h"
  56. #include <glm/glm.hpp>
  57. #include "Vertex.h"
  58.  
  59. #define NUM_ELEMENTS_ARRAY(a) sizeof(a)/ sizeof(*a)
  60.  
  61. shape GenerateShape::makeCube()
  62. {
  63.     shape retShape;
  64.     vertex vertices[] = {
  65.         //Position            //Colour              //Vertex ID
  66.         glm::vec3(0.0f, -0.1f, 0.5f), glm::vec3(1.0f, 1.0f, 1.0f)//0
  67.         glm::vec3(0.5f, 0.0f, 0.0f),  glm::vec3(1.0f, 0.0f, 0.3f)//1
  68.         glm::vec3(0.5f, 0.5f, 0.0f),  glm::vec3(1.0f, 0.5f, 0.0f)//2
  69.         glm::vec3(0.0f, 0.6f, 0.5f),  glm::vec3(1.0f, 0.5f, 0.3f)//3
  70.                                    
  71.         glm::vec3(-0.5f, 0.5f, 0.0f), glm::vec3(0.0f, 0.5f, 0.3f)//4
  72.         glm::vec3(-0.5f, 0.0f, 0.0f), glm::vec3(1.0f, 0.9f, 0.3f)//5
  73.         glm::vec3(0.0f, 0.0f, -0.5f), glm::vec3(1.0f, 0.0f, 0.0f)//6
  74.         glm::vec3(0.0f, 0.5f, -0.5f), glm::vec3(1.0f, 1.0f, 0.3f)   //7
  75.  
  76.     };
  77.  
  78.     //Triangle sets
  79.     GLushort elements[] = {
  80.         0, 1, 2,
  81.         0, 2, 3,
  82.         0, 4, 5,
  83.         0, 3, 4,
  84.         0, 5, 6,
  85.         0, 6, 1,
  86.  
  87.         1, 2, 7,
  88.         2, 3, 7,
  89.         3, 4, 7,
  90.         4, 5, 7,
  91.         5, 6, 7,
  92.         6, 1, 7
  93.  
  94.     };
  95.  
  96.     retShape.numVerts = NUM_ELEMENTS_ARRAY(vertices);
  97.     retShape.vertices = std::unique_ptr<vertex>(new vertex[retShape.numVerts]);
  98.     retShape.numIndices = NUM_ELEMENTS_ARRAY(elements);
  99.     retShape.indices = std::unique_ptr<GLushort>(new GLushort[retShape.numIndices]);
  100.  
  101.     memcpy(retShape.vertices.get(), vertices, sizeof(vertices));
  102.     memcpy(retShape.indices.get(), elements, sizeof(elements));
  103.  
  104.  
  105.     return retShape;
  106. }
  107.  
  108. GenerateShape::GenerateShape(void)
  109. {
  110. }
  111.  
  112.  
  113. GenerateShape::~GenerateShape(void)
  114. {
  115. }
Advertisement
Add Comment
Please, Sign In to add comment