I'm writing a class called TextRenderer
to render text with OpenGL.
Here's my TextRenderer.hpp
file
class TextRenderer
{
public:
void renderText(std::string text, int x, int y);
private:
void setup();
GLuint program;
};
Here's my TextRenderer.cpp
file:
#include "TextRenderer.hpp"
#include <string>
#include <GL/glew.h>
void TextRenderer::setup()
{
}
Here's my main file:
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include "TextRenderer.hpp"
int main()
{
//Init GLFW
glfwInit();
//Set OpenGL version to 3.2
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
//Make window un-resizable
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
//Create GLFW window in fullscreen mode
GLFWwindow* window = glfwCreateWindow(800, 600, "MOBA", glfwGetPrimaryMonitor(), nullptr);
glfwMakeContextCurrent(window);
//Init FreeType
FT_Library ft;
if (FT_Init_FreeType(&ft)) {
fprintf(stderr, "FATAL: Could not init FreeType");
return 1;
}
//Init Arial FreeType Face
FT_Face arial;
if (FT_New_Face(ft, "Arial", 0, &arial))
{
fprintf(stderr, "FATAL: Could not init font \"Arial\"");
return 1;
}
//Main loop
while (!glfwWindowShouldClose(window))
{
glfwSwapBuffers(window);
glfwPollEvents();
//Close on Esc key press
//TODO: Bring up quit dialog
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
{
glfwSetWindowShouldClose(window, GL_TRUE);
}
}
//Terminate GLFW
glfwTerminate();
return 0;
}
Notice how I have a private
GLuint
, program
. To do this I have to #include <GL/glew.h>
(in TextRenderer.cpp
), and I already have GL/glew.h
included in my main.cpp
file. What's the best way to do this?
TextRenderer.cpp
. As I've always been told, you're supposed to put the includes in thecpp
file. Is this incorrect? – Thomas Ross Jan 4 at 21:26