Archived

This topic is now archived and is closed to further replies.

Sarcastic Fringehead

Odd Textured Quad Behavior

Recommended Posts

Newbie problem here. I'm using gl to make 2D sprites using textured quads, as I've seen many people do here. To create my sprites I load an image from a BMP, do the standard pixel transformations, add an alpha channel for masking, adjust the dimensions to powers of 2, then pass it to glTexImage2D() after binding a texture object. A peek at memory shows that my pixel data looks correct before it is passed to glTexImage2D(). The alignment is correct, and the alpha bits are set where I want them to be. However, when my quad is drawn, it appears as a solid white square with scattered pixels of other colors. My test image is mostly black (with no alpha set) and grey (with alpha set). What is causing this weirdity? This is the code I use to init gl after getting a window and a context:
glViewport( 0, 0, viewh, viewv );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( 0, viewh - 1, 0, viewv - 1 );
	
glPixelStorei( GL_UNPACK_ALIGNMENT, PICTOR_ALIGNSIZE ); // <- 1
	
glClearColor( 0.0, 0.0, 0.0, 0.0 );
glEnable( GL_ALPHA_TEST );
glAlphaFunc( GL_GREATER, 0 );
glEnable( GL_TEXTURE_2D );
	
glClear( GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
 
And this is how I create my texture:
GLuint texname;
	
glGenTextures( 1, &texname );
glBindTexture( GL_TEXTURE_2D, texname );
	
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
	
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
			hsize, vsize, 0,
			GL_RGBA, GL_UNSIGNED_BYTE, pixels );
  
The memory readout of *pixels shows that the pixels I'm passing in resemble the test image. There are no other gl calls between init and texture creation. glGetError() doesn't return an error anywhere. My drawing code:
glBindTexture( GL_TEXTURE_2D, texname );
	
glBegin( GL_QUADS );
glTexCoord2i( 0, vcortexsize );
glVertex2i( hcorrectpos, vcorrectpos );
glTexCoord2i( hcortexsize, vcortexsize );
glVertex2i( hcorrectpos + hsize, vcorrectpos );
glTexCoord2i( hcortexsize, 0 );
glVertex2i( hcorrectpos + hsize, vcorrectpos - vsize );
glTexCoord2i( 0, 0 );
glVertex2i( hcorrectpos, vcorrectpos - vsize );
glEnd();
 
Any help will be greatly appreciated. [edited by - Sarcastic Fringehead on October 11, 2003 2:31:36 PM]

Share this post


Link to post
Share on other sites
Ilici    862
Use GL_LINEAR instead of GL_NEAREST or use mipmaps.

Delete the glPixelstore stuff it does not do anything.

glTexCoord2i - DELTETE THIS!
use glTexCoord2f it takes params like this:


0,1
+------------+ 1,1
| |
| |
| |
| |
| |
+------------+
0,0 1,0





[edited by - Ilici on October 11, 2003 3:04:27 PM]

Share this post


Link to post
Share on other sites