Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Renderer::flush() {
- if (vertices.size() > 0) {
- glBindTexture(GL_TEXTURE_2D, texManager->getTexture(currentTexture).getID());
- normal->setInt("image", 0);
- glBindBuffer(GL_ARRAY_BUFFER, VBO);
- glBufferData(GL_ARRAY_BUFFER, sizeof(texVec2) * vertices.size(), &vertices[0], GL_STATIC_DRAW);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indices.size(), &indices[0], GL_STATIC_DRAW);
- glBindVertexArray(VAO);
- glEnableVertexAttribArray(0);
- glEnableVertexAttribArray(1);
- glEnableVertexAttribArray(2);
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(texVec2), NULL);
- glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(texVec2), (void*)(2 * sizeof(float)));
- glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(texVec2), (void*)(6 * sizeof(float)));
- glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
- indices.clear();
- vertices.clear();
- }
- fontManager->flushFonts();
- }
- void Renderer::renderTexture(Sprite sprite, BBox destination, BBox source, Color color) {
- if (currentTexture != sprite.getName()) {
- flush();
- currentTexture = sprite.getName();
- }
- if (destination.x + destination.w < 0 || destination.y + destination.h < 0 || destination.x > m_data.width || destination.y > m_data.height) return;
- if (source.w == 0.0f && source.h == 0.0f) {
- source.w = sprite.getWidth();
- source.h = sprite.getHeight();
- }
- int i = vertices.size();
- indices.push_back(i + 0);
- indices.push_back(i + 1);
- indices.push_back(i + 3);
- indices.push_back(i + 1);
- indices.push_back(i + 2);
- indices.push_back(i + 3);
- vertices.push_back(texVec2(destination.x + destination.w, destination.y, color.r, color.g, color.b, color.a, source.x + source.w, source.y));
- 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));
- vertices.push_back(texVec2(destination.x, destination.y + destination.h, color.r, color.g, color.b, color.a, source.x, source.y + source.h));
- vertices.push_back(texVec2(destination.x, destination.y, color.r, color.g, color.b, color.a, source.x, source.y));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement