0

I am making this game using SDL and I need to be able to text displayed for variables and information etc. The problem is I can't render any text while SDL_OPENGL is a parameter in SDL_SetVideoMode().

It works perfectly without but then I cant render any of my graphics. Obviously I need both and I rather not go about drawing images for text.

TL;DR I need to draw text without removing SDL_OPENGL from SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,32,SDL_SWSURFACE | SDL_OPENGL);

I am using C++ and code::blocks if it help. Any other information needed?

Mark Beleski
  • 55
  • 1
  • 9
2GG
  • 23
  • 2

1 Answers1

0

So after a little work I figured out how to fix it on my own, I just converted the surfaces like i did with my regular pictures. here is the function I used if anyone else is interested or have a similar problem.

GLuint importText(const std::string &text,int font_size,const __int8 red,const __int8 green,const __int8 blue){
SDL_Color font_color = {blue,green,red};
TTF_Font* font=TTF_OpenFont("Font.ttf",font_size);
SDL_Surface *image = TTF_RenderText_Blended(font,text.c_str(),font_color);
SDL_DisplayFormatAlpha(image);
unsigned object(0);
glGenTextures(1,&object);
glBindTexture(GL_TEXTURE_2D, object);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA,image->w,image->h,0,GL_RGBA,GL_UNSIGNED_BYTE,image->pixels);
texture_height=image->h; texture_width=image->w;
SDL_FreeSurface(image);
TTF_CloseFont(font);
return object;}
2GG
  • 23
  • 2