Vis 2 Demo  1.0
Technical illustration type real-time rendering of geometry
 All Classes Namespaces Files Functions Variables Typedefs Macros
QuadTextured.cpp
Go to the documentation of this file.
1 #include "QuadTextured.h"
2 
3 using namespace vis2;
4 
5 QuadTextured::QuadTextured(glm::mat4 _modelMatrix, ShaderController* _shader_ctrl, bool _b_fill_window)
6  : DrawableObject(_modelMatrix), shader_ctrl(_shader_ctrl), b_fill_window(_b_fill_window),
7  vao_handle(0), vao_setup_done(false),
8  position_buffer_handle(0), normal_buffer_handle(0), uv_buffer_handle(0), index_buffer_handle(0)
9 {
10  // ------------------------- LOAD VBOs ----------------------------------- //
11 
12  // load positions to buffer
13  glGenBuffers(1,&position_buffer_handle); // takes n, array of handles as well
14  glBindBuffer(GL_ARRAY_BUFFER, position_buffer_handle); // activate buffer
15  if (b_fill_window)
16  glBufferData(GL_ARRAY_BUFFER, QUAD_TEXTURED_VERTEX_COUNT * 3 * sizeof(float), generic_positions_full, GL_STATIC_DRAW); // load data
17  else
18  glBufferData(GL_ARRAY_BUFFER, QUAD_TEXTURED_VERTEX_COUNT * 3 * sizeof(float), generic_positions, GL_STATIC_DRAW); // load data
19  glBindBuffer(GL_ARRAY_BUFFER,0); // deactivate buffer
20 
21  // load normals to buffer
22  glGenBuffers(1,&normal_buffer_handle);
23  glBindBuffer(GL_ARRAY_BUFFER, normal_buffer_handle);
24  glBufferData(GL_ARRAY_BUFFER, QUAD_TEXTURED_VERTEX_COUNT * 3 * sizeof(float), generic_normlas, GL_STATIC_DRAW);
25  glBindBuffer(GL_ARRAY_BUFFER,0);
26 
27  // load texture coordinates to buffer
28  glGenBuffers(1,&uv_buffer_handle);
29  glBindBuffer(GL_ARRAY_BUFFER, uv_buffer_handle);
30  glBufferData(GL_ARRAY_BUFFER, QUAD_TEXTURED_VERTEX_COUNT * 2 * sizeof(float), generic_uv, GL_STATIC_DRAW);
31  glBindBuffer(GL_ARRAY_BUFFER,0);
32 
33  // load face indices to buffer
34  glGenBuffers(1,&index_buffer_handle);
35  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer_handle);
36  glBufferData(GL_ELEMENT_ARRAY_BUFFER, QUAD_TEXTURED_INDEX_COUNT * sizeof(unsigned int), generic_indices, GL_STATIC_DRAW);
37  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
38 
39  // ------------------------- BIND VBOs to VAO ----------------------------------- //
44  if (success != VIS2_SHADER_INVARS_SETUP_SUCCESS)
45  {
46  std::cout << "Failed to set up the shader program for QuadTextured !" << std::endl;
47  system("PAUSE");
48  exit(-1);
49  }
51  vao_setup_done = true;
52 
53 }
54 
56 {
57  // first VBOs, then VAOs !!!
58  glDeleteBuffers(1,&position_buffer_handle);
59  glDeleteBuffers(1,&normal_buffer_handle);
60  glDeleteBuffers(1,&uv_buffer_handle);
61  glDeleteBuffers(1,&index_buffer_handle);
62 
63  glDeleteVertexArrays(1,&vao_handle);
64 }
65 
66 
67 void QuadTextured::update(double _deltaT)
68 {
69 }
70 
71 void QuadTextured::draw(glm::mat4 & _projectionMatrix)
72 {
73  draw(_projectionMatrix, glm::vec3(0.0f, 0.0f, 0.0f));
74 }
75 
76 void QuadTextured::draw(glm::mat4 & _projectionMatrix, glm::vec3 _edge_color)
77 {
78  if (!vao_setup_done)
79  return;
80 
81  // activate shader
83  // setup of Uniforms
84  int success = this->shader_ctrl->updateShaderUniforms(_projectionMatrix, this->modelMatrix, glm::vec3(0.0f, 0.0f, 0.0f), _edge_color);
86  {
87  std::cout << "Failed to update uniforms for QuadTextured!" << std::endl;
88  return;
89  }
90 
91  // activate vao
92  glBindVertexArray(vao_handle);
93  // place draw call with the vao above
94  glDrawElements(GL_TRIANGLES, QUAD_TEXTURED_INDEX_COUNT, GL_UNSIGNED_INT,0);
95  // deactivate vao
96  glBindVertexArray(0);
97 
98  // deactivate shader
100 }
101 
102 
103 // ------------------- the static arrays --------------------------- //
104 
106 {
107  0.0f, 0.0f, 0.1f,
108  0.0f, 0.5f, 0.1f,
109  0.5f, 0.0f, 0.1f,
110  0.5f, 0.5f, 0.1f
111 };
112 
114 {
115  0.0f, 0.0f, 0.0f,
116  0.0f, 1.0f, 0.0f,
117  1.0f, 0.0f, 0.0f,
118  1.0f, 1.0f, 0.0f
119 };
120 
122 {
123  0.0f, 0.0f, 1.0f,
124  0.0f, 0.0f, 1.0f,
125  0.0f, 0.0f, 1.0f,
126  0.0f, 0.0f, 1.0f
127 };
128 
130 {
131  0.0f, 1.0f,
132  0.0f, 0.0f,
133  1.0f, 1.0f,
134  1.0f, 0.0f
135 };
136 
138 {
139  0, 3, 2,
140  0, 1, 3
141 };