View Full Version : Problem with texturing

05-10-2012, 12:32 PM
Hi guys I'm using SDL to load an image and if i use glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,img->w,img->h,0,GL_RGB,GL_UNSIGNED_BYTE,img->pixels); i get an error but when I use glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,img->w,img->h,0,GL_RGB,GL_UNSIGNED_SHORT_5_6_5,img->pixels); it's ok. But it's only for .bmp files. What should I do. Here is the whole function.
unsigned int loadtexture1(const char* filename)
unsigned int num; //the id for the texture
glGenTextures(1,&num); //we generate a unique one
SDL_Surface* img=SDL_LoadBMP(filename); //load the bmp image
glBindTexture(GL_TEXTURE_2D,num); //and use the texture, we have just generated
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR); //if the texture is smaller, than the image, we get the avarege of the pixels next to it
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR); //same if the image bigger
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _CLAMP_TO_EDGE); //we repeat the pixels in the edge of the texture, it will hide that 1px wide line at the edge of the cube, which you have seen in the video
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _CLAMP_TO_EDGE); //we do it for vertically and horizontally (previous line)
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,img->w,img->h,0,GL_RGB,GL_UNSIGNED_BYTE,img->pixels); //we make the actual texture
SDL_FreeSurface(img); //we delete the image, we don't need it anymore
return num; //and we return the id

05-10-2012, 11:45 PM
try checking the

SDL_PixelFormat of the surface and make sure it is what you expect