PDA

View Full Version : Simple Texture Mapping



elasolova
01-30-2010, 08:39 PM
Hi,

I am trying to apply a simple color map to a side of the cube in my program, but the side appears white. Here is my code:


GLuint textureObject[NUM_TEXS];
void InitTextures ()
{
glEnable(GL_TEXTURE_2D);
GLuint textureObject[NUM_TEXS];
glGenTextures(3,textureObject);
glActiveTexture(GL_TEXTURE0);
Image2D_t* colIm=LoadImage("../data/color.png",false,RGB_IMAGE);

glBindTexture(GL_TEXTURE_2D,textureObject[COLOR_TEX]);
int err=TexImage(colIm);
printf("Error: %d\n", err);
}


void DrawWall (Side_t w)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,textureObject[COLOR_TEX]);

glBegin(GL_QUADS);
glTexCoord2f (0.0, 0.0);
glVertex3fv(Wall[w].corner[0]);
glTexCoord2f (1.0, 0.0);
glVertex3fv(Wall[w].corner[1]);
glTexCoord2f (1.0, 1.0);
glVertex3fv(Wall[w].corner[2]);
glTexCoord2f (0.0, 1.0);
glVertex3fv(Wall[w].corner[3]);
glEnd();

glDisable(GL_TEXTURE_2D);
}

The user-defined functions are working properly I used, but somehow I am not getting any textures. Any suggestions?

ZbuffeR
01-31-2010, 04:53 AM
By default 2d texture need mipmaps, so check if your TexImage function does mipmaps.
Or use min filter GL_LINEAR, but it is ugly and slower.

jean-luc
01-31-2010, 11:51 AM
Hi!
I've the same probleme (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=271210#Post2712 10) I tried with GL_LINEAR but nothing changed.... maybe our issues are related?
thanks
JLM

dletozeun
01-31-2010, 12:43 PM
elasolova, I see nothing wrong in your code except for the glGenTextures call with "3" hard coded whereas everywhere else you are using NUM_TEXS. The gl code is incomplete, please post the content of the TexImage function.