Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. void Renderer::flush() {
  2. if (vertices.size() > 0) {
  3. glBindTexture(GL_TEXTURE_2D, texManager->getTexture(currentTexture).getID());
  4. normal->setInt("image", 0);
  5. glBindBuffer(GL_ARRAY_BUFFER, VBO);
  6. glBufferData(GL_ARRAY_BUFFER, sizeof(texVec2) * vertices.size(), &vertices[0], GL_STATIC_DRAW);
  7. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
  8. glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indices.size(), &indices[0], GL_STATIC_DRAW);
  9. glBindVertexArray(VAO);
  10. glEnableVertexAttribArray(0);
  11. glEnableVertexAttribArray(1);
  12. glEnableVertexAttribArray(2);
  13. glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(texVec2), NULL);
  14. glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(texVec2), (void*)(2 * sizeof(float)));
  15. glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(texVec2), (void*)(6 * sizeof(float)));
  16. glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
  17. indices.clear();
  18. vertices.clear();
  19. }
  20. fontManager->flushFonts();
  21. }
  22.  
  23. void Renderer::renderTexture(Sprite sprite, BBox destination, BBox source, Color color) {
  24. if (currentTexture != sprite.getName()) {
  25. flush();
  26. currentTexture = sprite.getName();
  27. }
  28.  
  29. if (destination.x + destination.w < 0 || destination.y + destination.h < 0 || destination.x > m_data.width || destination.y > m_data.height) return;
  30. if (source.w == 0.0f && source.h == 0.0f) {
  31. source.w = sprite.getWidth();
  32. source.h = sprite.getHeight();
  33. }
  34. int i = vertices.size();
  35. indices.push_back(i + 0);
  36. indices.push_back(i + 1);
  37. indices.push_back(i + 3);
  38. indices.push_back(i + 1);
  39. indices.push_back(i + 2);
  40. indices.push_back(i + 3);
  41. vertices.push_back(texVec2(destination.x + destination.w, destination.y, color.r, color.g, color.b, color.a, source.x + source.w, source.y));
  42. vertices.push_back(texVec2(destination.x + destination.w, destination.y + destination.h, color.r, color.g, color.b, color.a, source.x + source.w, source.y + source.h));
  43. vertices.push_back(texVec2(destination.x, destination.y + destination.h, color.r, color.g, color.b, color.a, source.x, source.y + source.h));
  44. vertices.push_back(texVec2(destination.x, destination.y, color.r, color.g, color.b, color.a, source.x, source.y));
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement