Skip to content

Commit ba026bf

Browse files
committed
Refactored the ViewElement class by moving some rendering code to
Renderer.
1 parent bd9294d commit ba026bf

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

include/Renderer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ GLuint loadImageAsTexture(const std::string& name);
1616
GLuint loadTextAsTexture(const std::string& font, int fontSize, const std::string& text);
1717

1818
void renderText(const std::string& font, int fontSize, const std::pair<float, float> bottomLeft, const std::pair<float, float> topRight, const std::string& text);
19+
void renderText(const std::pair<float, float> bottomLeft, const std::pair<float, float> topRight, const GLuint& texture);
20+
void renderRectangle(const std::pair<float, float> bottomLeft, const std::pair<float, float> topRight, const std::tuple<float, float, float> color);
21+
1922

2023
std::pair<float, float> coordToScreen(const Coordinate& coord);
2124
Coordinate screenToCoord(const std::pair<float, float>&);

src/Renderer.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,49 @@ void renderText(const std::string& fontPath, int fontSize, const std::pair<float
109109
glDeleteTextures(1, &texture);
110110
}
111111

112+
/**
113+
* Render some text on screen.
114+
*
115+
* @param bottomLeft The bottom left screen coordinate of the bounding box to draw to.
116+
* @param topRight The top right screen coordinate of the bounding box to draw to.
117+
* @param texture The texture of text to render.
118+
*/
119+
void renderText(const std::pair<float, float> bottomLeft, const std::pair<float, float> topRight, const GLuint& texture){
120+
glBindTexture(GL_TEXTURE_2D, texture);
121+
glColor3f(1.0, 1.0, 1.0);
122+
123+
glBegin(GL_QUADS);
124+
glTexCoord2i(0, 1);
125+
glVertex2f(bottomLeft.first, bottomLeft.second);
126+
glTexCoord2i(1, 1);
127+
glVertex2f(topRight.first, bottomLeft.second);
128+
glTexCoord2i(1, 0);
129+
glVertex2f(topRight.first, topRight.second);
130+
glTexCoord2i(0, 0);
131+
glVertex2f(bottomLeft.first, topRight.second);
132+
glEnd();
133+
glBindTexture(GL_TEXTURE_2D, 0);
134+
}
135+
136+
/**
137+
* Render a colored rectangle on the screen
138+
*
139+
* @param bottomLeft the bottom left corner of the box
140+
* @param topRight the top right corner of the box
141+
* @param color the rgb color percentages of the box
142+
*/
143+
void renderRectangle(const std::pair<float, float> bottomLeft, const std::pair<float, float> topRight, const std::tuple<float, float, float> color){
144+
glBindTexture(GL_TEXTURE_2D, 0);
145+
glColor3f(std::get<0>(color), std::get<1>(color), std::get<2>(color));
146+
147+
glBegin(GL_QUADS);
148+
glVertex2f(bottomLeft.first, bottomLeft.second);
149+
glVertex2f(topRight.first, bottomLeft.second);
150+
glVertex2f(topRight.first, topRight.second);
151+
glVertex2f(bottomLeft.first, topRight.second);
152+
glEnd();
153+
}
154+
112155
/**
113156
* Loads an image into an OpenGL texture.
114157
* @param name The file name of the texture to load.

0 commit comments

Comments
 (0)