Jump to content
  • Advertisement
Sign in to follow this  
Shiran

glTexImage2D border problem

This topic is 4153 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

First of all I have an nvidia card and my writing partner has an ati card. I wanted to load textures into our game and wrote this code which recives the name of a .raw file. The size of the picture that i gave is 512*512. When i set the border to 0 in glTexImage2D we both could see the texture but there was a seam between textures (I put in a skybox). When I set the border to 1 and left everything the same including the picture I could see everything fine and the seams were gone but my partner couldn't see anything and when i looked at the error created it was that the width and height were no good. From what i understand i need the picture to be of size 2^n+2 because of the border, so i resized the picture to 514 and tried that, but then i see the picture very distorted, in black and white. When i tried to resize it to 1024 it looks fine, when i resize it to 600 it has tiny almost invisible lines going throw it. I use IrfanView to convert my pictures, and my original pictures are jpg, but I did try to convert from .bmp and that was no good either. When i try to open a .bmp with the same code i get the picture in different colors. Please help, I really want to get rid of the seams. This is the code bool loadTexture(const char* filename,int width,int height, GLuint& texture) { FILE* file = fopen( filename, "rb" ); if (file == NULL) return false; int dataSize = width*height*3; unsigned char* pixels = (unsigned char*)malloc(dataSize); if (pixels == NULL) { fclose(file); return false; } // read texture data fread(pixels,dataSize,1,file); fclose(file); glGenTextures( 1, &texture ); // select our current texture glBindTexture( GL_TEXTURE_2D, texture ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // select modulate to mix texture with color for shading glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, width, height, 1, GL_RGB, GL_UNSIGNED_BYTE,pixels); // free buffer free(pixels); return true; }

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You don't need to use the border set it to zero and just pass your picture's width and height (512,512 in your case). Use GL_CLAMP_TO_EDGE instead of GL_CLAMP:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

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!