Hi guys,
I've a little problem, here... I think I'm missing something!
I want to write a function with the following prototype:
void draw_texture_cube(GLubyte color[], float size[], float translation[], int texture[], int rep_texture[])
It receives a the color, the size, the translation, an array with textures (one per cube face) and another array with the repetition of the texture (one per face).
Here's the declaration of the texture and repetition arrays:
int lgp_texture[] = {0, GRASS_LIGHT, GRASS_LIGHT, GRASS_LIGHT, GRASS_LIGHT, GRASS_LIGHT};
int lgp_rep_texture[] = {0, 5, 5, 5, 5, 5};
In the next example the bottom, front, right, back and left faces should pick the same (or different) textures (GRASS_LIGHT) and repeat them 5 times.
And here's some of the code of my function:
void draw_texture_cube(GLubyte color[], float size[], float translation[], int texture[], int rep_texture[])
{
glPushMatrix();
glTranslatef(translation[0], translation[1], translation[2]);
//top face
if(texture[0] != 0)
{
glDisable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
int rep0 = rep_texture[0];
glBegin(GL_POLYGON);
glNormal3d(0.0, 1.0, 0.0);
glTexCoord2f(0.0,0.0); glVertex3d(-size[0]/2, size[1]/2, size[2]/2);
glTexCoord2f(rep0,0.0); glVertex3d(size[0]/2, size[1]/2, size[2]/2);
glTexCoord2f(rep0,rep0); glVertex3d(size[0]/2, size[1]/2, -size[2]/2);
glTexCoord2f(0.0,rep0); glVertex3d(-size[0]/2, size[1]/2, -size[2]/2);
glEnd();
} else
{
glDisable(GL_TEXTURE_2D);
glEnable(GL_COLOR_MATERIAL);
glColor3ubv(color);
glBegin(GL_POLYGON);
glNormal3d(0.0, 1.0, 0.0);
glVertex3d(-size[0]/2, size[1]/2, size[2]/2);
glVertex3d(size[0]/2, size[1]/2, size[2]/2);
glVertex3d(size[0]/2, size[1]/2, -size[2]/2);
glVertex3d(-size[0]/2, size[1]/2, -size[2]/2);
glEnd();
}
//bottom face
if(texture[1] != 0)
{
glDisable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[1]);
int rep1 = rep_texture[1];
glBegin(GL_POLYGON);
glNormal3d(0.0, -1.0, 0.0);
glTexCoord2f(0.0,0.0); glVertex3d(size[0]/2, -size[1]/2, size[2]/2);
glTexCoord2f(rep1,0.0); glVertex3d(-size[0]/2, -size[1]/2, size[2]/2);
glTexCoord2f(rep1,rep1); glVertex3d(-size[0]/2, -size[1]/2, -size[2]/2);
glTexCoord2f(0.0,rep1); glVertex3d(size[0]/2, -size[1]/2, -size[2]/2);
glEnd();
}
else
{
glDisable(GL_TEXTURE_2D);
glEnable(GL_COLOR_MATERIAL);
glColor3ubv(color);
glBegin(GL_POLYGON);
glNormal3d(0.0, -1.0, 0.0);
glVertex3d(size[0]/2, -size[1]/2, size[2]/2);
glVertex3d(-size[0]/2, -size[1]/2, size[2]/2);
glVertex3d(-size[0]/2, -size[1]/2, -size[2]/2);
glVertex3d(size[0]/2, -size[1]/2, -size[2]/2);
glEnd();
}
//more code here
glDisable(GL_TEXTURE_2D);
glEnable(GL_COLOR_MATERIAL);
glPopMatrix();
}
The problem is that when the first texture isn't defined the rest don't display.
I'm sure this is just something that I'm missing.. any ideas?
Thanks a lot,
mello