Created
March 3, 2015 00:08
-
-
Save jeandudey/21947298559ff0f90777 to your computer and use it in GitHub Desktop.
OpenGL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Text::glRenderText(std::string text, TTF_Font *font, SDL_Color color, SDL_Rect *location) | |
{ | |
int w, | |
h; | |
SDL_Surface *FontSurface; | |
GLuint TextureID; | |
FontSurface = TTF_RenderText_Blended(font, text.c_str(), color); | |
w = Math::nextpoweroftwo(FontSurface->w); | |
h = Math::nextpoweroftwo(FontSurface->h); | |
glGenTextures(1, &TextureID); | |
glBindTexture(GL_TEXTURE_2D, TextureID); | |
glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, FontSurface->pixels); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
glEnable(GL_TEXTURE_2D); | |
glBindTexture(GL_TEXTURE_2D, TextureID); | |
glColor3f(1.0f, 1.0f, 1.0f); | |
glBegin(GL_QUADS); | |
glTexCoord2f(0.0f, 1.0f); glVertex2f(location->x, location->y); | |
glTexCoord2f(1.0f, 1.0f); glVertex2f(location->x + w, location->y); | |
glTexCoord2f(1.0f, 0.0f); glVertex2f(location->x + w, location->y + h); | |
glTexCoord2f(0.0f, 0.0f); glVertex2f(location->x, location->y + h); | |
glEnd(); | |
glFinish(); | |
SDL_FreeSurface(FontSurface); | |
glDeleteTextures(1, &TextureID); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Help me with this scrap :(