Jump to content
  • Advertisement
Sign in to follow this  
HimberJack

help with textures

This topic is 3800 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, I have copied the following code: // load a 256x256 RGB .RAW file as a texture GLuint LoadTextureRAW( const char * filename, int wrap ) { int width, height; unsigned char * data; FILE * file; // open texture data file = fopen( filename, "rb" ); if ( file == NULL ) return 0; // allocate buffer width = 256; height = 256; data = (unsigned char *) malloc( width * height * 4 ); // read texture data fread( data, width * height * 4, 1, file ); fclose( file ); // allocate a texture name glGenTextures( 1, &texture ); // select our current texture glBindTexture( GL_TEXTURE_2D, texture ); // select modulate to mix texture with color for shading glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); // when texture area is small, bilinear filter the closest MIP map glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); // when texture area is large, bilinear filter the first MIP map glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); // if wrap is true, the texture wraps over at the edges (repeat) // ... false, the texture ends at the edges (clamp) glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap ? GL_REPEAT : GL_CLAMP ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ? GL_REPEAT : GL_CLAMP ); // build our texture MIP maps gluBuild2DMipmaps( GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data ); // free buffer free( data ); return texture; } and void drawBasePic(){ glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, texture ); glTranslatef(0,0,-0.29); glBegin( GL_QUADS ); glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-0.5); glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-0.5); glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+0.5); glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+0.5); glEnd(); glDisable(GL_TEXTURE_2D); glTranslatef(0,0,0.29); } the thing is the image is shown, but it has like purple color on it. i draw it on SOLID objects I created. i do not have red lights whatsoever... other images are drawn in green... its like something is wrong. thanks

Share this post


Link to post
Share on other sites
Advertisement
Are you loading RGBA texture? or BGRA?
if RGBA, then use
gluBuild2DMipmaps( GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data );
else if you're loading BGRA texture
gluBuild2DMipmaps( GL_TEXTURE_2D, 4, width, height, GL_BGRA, GL_UNSIGNED_BYTE, data );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!