-
Notifications
You must be signed in to change notification settings - Fork 3
/
GUI.cpp
53 lines (41 loc) · 2.02 KB
/
GUI.cpp
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
#include "GUI.hpp"
#include "WorldConstants.hpp"
// Vertex information for GUI
GLfloat crosshairVertices[] = {
// Horizontal crosshair line.
-World::crosshairLength, -World::crosshairThickness, // bottom-left
World::crosshairLength, -World::crosshairThickness, // bottom-right
World::crosshairLength, World::crosshairThickness, // top-right
World::crosshairLength, World::crosshairThickness, // top-right
-World::crosshairLength, World::crosshairThickness, // top-left
-World::crosshairLength, -World::crosshairThickness, // bottom-left
// Vertical crosshair line.
// The 1350 and 850 are the width and height of the window.
// We multiply by it so that we scale the vertical line by the window resolution
// Make the horizontal and vertical crosshairs the same size
-World::crosshairThickness, -World::crosshairLength * ((GLfloat)1350 / 850), // bottom-left
World::crosshairThickness, -World::crosshairLength * ((GLfloat)1350 / 850), // bottom-right
World::crosshairThickness, World::crosshairLength * ((GLfloat)1350 / 850), // top-right
World::crosshairThickness, World::crosshairLength * ((GLfloat)1350 / 850), // top-right
-World::crosshairThickness, World::crosshairLength * ((GLfloat)1350 / 850), // top-left
-World::crosshairThickness, -World::crosshairLength * ((GLfloat)1350 / 850), // bottom-left
};
GUI::GUI() : guiShaderProgram("shaders/gui.vert", "shaders/gui.frag") // Member-Initializer List
{
GuiVAO.Bind();
GuiVBO.Bind();
// Links VBO attributes such as coordinates and colors to VAO
GuiVBO.InitVBO(crosshairVertices, sizeof(crosshairVertices));
GuiVAO.LinkAttrib(GuiVBO, 0, 2, GL_FLOAT, 2 * sizeof(GLfloat), (void*)0);
// Unbind all to prevent accidentally modifying them
GuiVBO.Unbind();
GuiVAO.Unbind();
}
void GUI::RenderCrosshair()
{
// Render the crosshair
GuiVAO.Bind();
guiShaderProgram.Activate();
glDrawArrays(GL_TRIANGLES, 0, sizeof(crosshairVertices) / sizeof(GLfloat) / 2);
GuiVAO.Unbind();
}