fork download
  1. /* ASTEROIDS ONLY */
  2.  
  3. for (std::vector<RenderObject *>::iterator iter = objects.begin(); iter != objects.end(); ++iter) {
  4.  
  5. RenderObject * obj = *iter;
  6.  
  7. if (dynamic_cast<Asteroid *>(obj) == NULL) {
  8. continue;
  9. }
  10.  
  11. // Get the original untransformed model.
  12. std::vector<glm::vec3> vecModel = obj->Model;
  13.  
  14. float angle = obj->Props.Pos.Angle;
  15.  
  16. glm::mat4 transl = glm::translate(glm::mat4(1.0f), glm::vec3(obj->Props.Pos.X, obj->Props.Pos.Y, 0.0f));
  17.  
  18. for (size_t i = 0; i < vecModel.size(); i++) {
  19.  
  20. glm::vec4 vec_temp = glm::vec4(vecModel[i], 0.0f);
  21.  
  22. vec_temp = glm::vec4(glm::rotateZ(glm::vec3(vec_temp[0], vec_temp[1], vec_temp[3]), -angle), 0.0f);
  23.  
  24. vec_temp = transl * glm::vec4(vec_temp[0], vec_temp[1], vec_temp[2], 1.0f); // The "1.0f" at the end is important!
  25.  
  26. vecAllAsteroids_pos.push_back(glm::vec2(vec_temp[0], vec_temp[1]));
  27. }
  28.  
  29. for (size_t i = 0; i < vecModel.size(); i = i + 3) {
  30.  
  31. vecAllAsteroids_tex.push_back(glm::vec2(0.0f, 0.0f));
  32. vecAllAsteroids_tex.push_back(glm::vec2(0.0f, 1.0f));
  33. vecAllAsteroids_tex.push_back(glm::vec2(1.0f, 1.0f));
  34. }
  35. }
  36.  
  37. assert(vecAllAsteroids_pos.size() == vecAllAsteroids_tex.size());
  38.  
  39. glUseProgram(asteroid_prog_id);
  40.  
  41. glActiveTexture(GL_TEXTURE0);
  42. glBindTexture(GL_TEXTURE_2D, asteroid_tex_id);
  43. glUniform1i(asteroid_uniform_id, 0);
  44.  
  45. glBindBuffer(GL_ARRAY_BUFFER, asteroid_vertex_buffer);
  46. glBufferData(GL_ARRAY_BUFFER, vecAllAsteroids_pos.size() * sizeof(glm::vec2), &vecAllAsteroids_pos[0], GL_STATIC_DRAW);
  47.  
  48. glEnableVertexAttribArray(0);
  49. glVertexAttribPointer(
  50. 0, // index: the index of the attribute to be modified
  51. 2, // size: the number of components per attribute
  52. GL_FLOAT, // type: the data type of each component
  53. GL_FALSE, // normalized: whether or not to normalize data points
  54. 0, // stride: the byte offset between attributes
  55. (void*)0 // pointer: the offset of the first component of the first array attribute
  56. );
  57.  
  58. glBindBuffer(GL_ARRAY_BUFFER, asteroid_texture_buffer);
  59. glBufferData(GL_ARRAY_BUFFER, vecAllAsteroids_tex.size() * sizeof(glm::vec2), &vecAllAsteroids_tex[0], GL_STATIC_DRAW);
  60.  
  61. glEnableVertexAttribArray(1);
  62. glVertexAttribPointer(
  63. 1, // index: the index of the attribute to be modified
  64. 2, // size: the number of components per attribute
  65. GL_FLOAT, // type: the data type of each component
  66. GL_FALSE, // normalized: whether or not to normalize data points
  67. 0, // stride: the byte offset between attributes
  68. (void *)0 // pointer: the offset of the first component of the first array attribute
  69. );
  70.  
  71. //glVertexAttribDivisor(1, 0); // Advance by '1' on vertex attribute array '0'.
  72. //glVertexAttribDivisor(1, 1); // Advance by '1' on vertex attribute array '1'.
  73.  
  74. glDrawArrays(GL_TRIANGLES, 0, GLsizei(vecAllAsteroids_pos.size()));
  75.  
  76. glDisableVertexAttribArray(0);
  77. glDisableVertexAttribArray(1);
  78.  
  79. /* ASTEROIDS ONLY */
  80.  
  81. frc.log();
  82.  
  83. std::stringstream ss;
  84.  
  85. ss << frc.get();
  86.  
  87. PrintText(ss.str().c_str(), 10, 860, 30);
  88.  
  89. glfwSwapBuffers(window);
  90. glfwPollEvents();
  91.  
  92. vecAllParticles.clear();
  93. vecAllRegulars.clear();
  94. vecAllAsteroids_pos.clear();
  95. vecAllAsteroids_tex.clear();
  96.  
  97. return 0;
  98.  
  99. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:2: error: expected unqualified-id before ‘for’
  for (std::vector<RenderObject *>::iterator iter = objects.begin(); iter != objects.end(); ++iter) {
  ^
prog.cpp:3:69: error: ‘iter’ does not name a type
  for (std::vector<RenderObject *>::iterator iter = objects.begin(); iter != objects.end(); ++iter) {
                                                                     ^
prog.cpp:3:92: error: expected unqualified-id before ‘++’ token
  for (std::vector<RenderObject *>::iterator iter = objects.begin(); iter != objects.end(); ++iter) {
                                                                                            ^
stdout
Standard output is empty