-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUITextLoader.cpp
More file actions
70 lines (50 loc) · 1.9 KB
/
UITextLoader.cpp
File metadata and controls
70 lines (50 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "UITextLoader.h"
#include "Texture.h"
#include <stdexcept>
TextLoader::TextLoader() = default;
TextLoader::~TextLoader() = default;
TextInfo* TextLoader::drawText(Shader& shader, std::string text, float x, float y)
{
//currentIndex += 1;
if (currentIndex > 9)
throw std::runtime_error("This engine only supports less than 10 text bro");
TextInfo editedText;
editedText.text = text;
editedText.x = x;
editedText.y = y;
currentText[currentIndex] = editedText;
shader.Activate();
glUniform1i(glGetUniformLocation(shader.ID, "useTexture"), 1);
glDisable(GL_DEPTH_TEST);
float quadVertices[] = {
// pos // uv
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.0f, 1.0f, 1.0f,
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f
};
unsigned int quadIndices[] = {
0, 1, 2,
2, 3, 0
};
GLuint quadVBO, quadEBO;
glGenBuffers(1, &quadVBO);
glGenBuffers(1, &quadEBO);
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), quadVertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadEBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quadIndices), quadIndices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
glDeleteBuffers(1, &quadVBO);
glDeleteBuffers(1, &quadEBO);
return ¤tText[currentIndex];
}