[SDL] [1.2] SDL /OpenGL texture and primitive drawing problem

Odiee simula47 at gmail.com
Thu Jul 14 04:22:34 PDT 2011


Hi

I have a problem where I can't set the color of the drawing primitive when I load some texture before drawing.
e.g. 
LoadBackTex();
DrawBack();
DrawSquare();

where LoadBackTex() loads the *.png image, sets texture format, bind texture, calls glTexImage2D with appropriate parameters. (format is GL_RGB) 

DrawBack:

Code:


void drawBackground(void)
{
glBindTexture( GL_TEXTURE_2D, ID_BACK_TEXTURE );
glBegin( GL_QUADS );
	glTexCoord2i( 0, 0 );
	glVertex3f( 0.f, 0.f, 0.0f );
 
	glTexCoord2i( 1, 0 );
	glVertex3f( 640, 0, 0.f );
 
	glTexCoord2i( 1, 1 );
	glVertex3f( 640, 480.f, 0.f );
 
	glTexCoord2i( 0, 1 );
	glVertex3f( 0, 480, 0.f );
glEnd();
SDL_GL_SwapBuffers();
}




DrawSquare:

Code:

void drawSquare(void)
{
 glColor3f(1,0,0);	
 glBegin(GL_QUADS);						
 		glVertex3f(100, 100, 0.0f);				
		glVertex3f( 150, 100, 0.0f);				
		glVertex3f( 150,150, 0.0f);				
		glVertex3f( 100,150, 0.0f);				
glEnd();	
SDL_GL_SwapBuffers();
}




The problem is I can't set the color of the square. It draws right, but the color remains unchanged.
It has something with glTexImage2D function because when I disable it, it draws fine. I figured it's something with the pixel format but I just can't get my finger on it.


opengl is initialized with

Code:

void InitGL(void)
{
glEnable( GL_TEXTURE_2D );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glViewport( 0, 0, 640, 480 );
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(0.0f, 640, 480, 0.0f, -1.0f, 1.0f);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}




and SDL with


Code:

int InitSDL(void)
{
 if (SDL_Init(SDL_INIT_VIDEO) != 0)
    {
     return -1;
    }
    
 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

 screen = SDL_SetVideoMode(640,480, bpp, SDL_HWSURFACE  | SDL_OPENGL);
 if (!screen) 
    {
     gData->AppendLog("set video mode fail");
     return -1;
    }  
    
 return 0;
}







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20110714/554edf53/attachment-0007.htm>


More information about the SDL mailing list