Skip to content

Instantly share code, notes, and snippets.

@jeandudey
Created March 3, 2015 00:08
Show Gist options
  • Save jeandudey/21947298559ff0f90777 to your computer and use it in GitHub Desktop.
Save jeandudey/21947298559ff0f90777 to your computer and use it in GitHub Desktop.
OpenGL
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);
}
@jeandudey
Copy link
Author

Help me with this scrap :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment