Jump to content
  • Advertisement
Sign in to follow this  
mello

Cube with textures

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

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

Share this post


Link to post
Share on other sites
Advertisement
Hi !

*just guessing*

What exactly does not show ? The textures or the faces all together ?

Have you checked the error state with glGetError()? Mostly when stuff doesnt show up correctly its due to an error. If you experience this only when you dont have defined the first texture, its properly somewhere in the else - clause of your top face.

Are the "GRASS_LIGHT" - ids proper opengl texture objects ?

Would be nice if you could describe your error in more detail, the code as such looks fine at first sight.

P.S: You might try using GL_QUADS instead of GL_POLYGON, seems more appropriate for the matter :)

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!