Code: Select all
SDL_Surface *initial;
SDL_Surface *intermediary;
SDL_Surface *temp;
GLtexture texture;
SDL_Color temporary = { blue, green, red };
initial = TTF_RenderText_Blended( font, text, temporary );
texture.w = NextPowerof2( initial->w );
texture.h = NextPowerof2( initial->h );
intermediary = SDL_CreateRGBSurface( NULL, texture.w, texture.h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 );
SDL_BlitSurface( initial, 0, intermediary, 0 );
glEnable( GL_TEXTURE_2D );
int mode;
texture.surface = intermediary;
texture.w = texture.surface->w;
texture.h = texture.surface->h;
if( texture.surface->format->BytesPerPixel == 3 )
{
mode = GL_RGB;
}
else if( texture.surface->format->BytesPerPixel == 4 )
{
mode = GL_RGBA;
}
else
{
SDL_FreeSurface( texture.surface );
}
glDeleteTextures( 1, &texture.id );
glGenTextures( 1, &texture.id );
glBindTexture( GL_TEXTURE_2D, texture.id );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, texture.surface->w, texture.surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.surface->pixels );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
texture.rotation = 0;
texture.scale = 1;
texture.alpha = 1;
glPushMatrix();
glBindTexture( GL_TEXTURE_2D, texture.id );
glDisable( GL_DEPTH_TEST );
glEnable( GL_BLEND );
glBlendFunc( GL_ONE, GL_ONE );
glTranslatef( (float)x + ( texture.w / 2 ), (float)y + ( texture.h / 2 ), 0 );
glRotatef( rotation, 0, 0, 1 );
glColor4f( 1, 1, 1, alpha );
glBegin( GL_QUADS );
glTexCoord2i( 0, 0 );
glVertex3f( (float)-texture.w / 2, (float)-texture.h / 2, 0 );
glTexCoord2i( 1, 0 );
glVertex3f( (float)texture.w / 2, (float)-texture.h / 2, 0 );
glTexCoord2i( 1, 1 );
glVertex3f( (float)texture.w / 2, (float)texture.h / 2, 0 );
glTexCoord2i( 0, 1 );
glVertex3f( (float)-texture.w / 2, (float)texture.h / 2, 0 );
glEnd();
glDisable( GL_TEXTURE_2D );
glDisable( GL_BLEND );
glPopMatrix();
SDL_FreeSurface( initial );
SDL_FreeSurface( intermediary );
glDeleteTextures( 1, &texture.id );
What am I doing wrong?