Sign in to follow this  
coderWalker

No textures?

Recommended Posts

coderWalker    127
For some reason the textures are not showing on my cube? Do I have the calls arranged wrong? Drawing 1 side shows the texture, however drawing 6 sides does not.

//==Shows texture correctly
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D,grid[3].tex);
//Front
glBegin( GL_QUADS );
glNormal3f(0.0f, 0.0f, -1.0f);
glTexCoord2d(1.0,1.0);glVertex3f(1, 1, 0 );
glTexCoord2d(1.0,0.0);glVertex3f(1, 0, 0 );
glTexCoord2d(0.0,0.0);glVertex3f(0, 0, 0 );
glTexCoord2d(0.0,1.0);glVertex3f(0, 1, 0 );
glEnd();
glPopMatrix();

//==Shows White untextured objects
glPushMatrix();
glTranslatef(grid[a].x,grid[a].y,grid[a].z);
glBindTexture( GL_TEXTURE_2D,grid[position].tex );
//Front
glBegin( GL_QUADS );
glNormal3f(0.0f, 0.0f, -1.0f);
glTexCoord2d(1.0,1.0);glVertex3f(1, 1, 0 );
glTexCoord2d(1.0,0.0);glVertex3f(1, 0, 0 );
glTexCoord2d(0.0,0.0);glVertex3f(0, 0, 0 );
glTexCoord2d(0.0,1.0);glVertex3f(0, 1, 0 );
glEnd();
//Back
glBegin( GL_QUADS );
glNormal3f(0.0f, 0.0f, 1.0f);
glTexCoord2d(1.0,1.0);glVertex3f(1, 1, 1 );
glTexCoord2d(1.0,0.0);glVertex3f(1, 0, 1 );
glTexCoord2d(0.0,0.0);glVertex3f(0, 0, 1 );
glTexCoord2d(0.0,1.0);glVertex3f(0, 1, 1 );
glEnd();
//Top
glBegin( GL_QUADS );
glNormal3f(0.0f, 1.0f, 0.0f);
glTexCoord2d(1.0,1.0);glVertex3f(1, 1, 1 );
glTexCoord2d(1.0,0.0);glVertex3f(1, 1, 0 );
glTexCoord2d(0.0,0.0);glVertex3f(0, 1, 0 );
glTexCoord2d(0.0,1.0);glVertex3f(0, 1, 1 );
glEnd();
//Bottom
glBegin( GL_QUADS );
glNormal3f(0.0f, -1.0f, 0.0f);
glTexCoord2d(1.0,1.0);glVertex3f(1, 0, 1 );
glTexCoord2d(1.0,0.0);glVertex3f(1, 0, 0 );
glTexCoord2d(0.0,0.0);glVertex3f(0, 0, 0 );
glTexCoord2d(0.0,1.0);glVertex3f(0, 0, 1 );
glEnd();
//Left
glBegin( GL_QUADS );
glNormal3f(-1.0f, 0.0f, 0.0f);
glTexCoord2d(1.0,1.0);glVertex3f(0, 1, 1 );
glTexCoord2d(1.0,0.0);glVertex3f(0, 1, 0 );
glTexCoord2d(0.0,0.0);glVertex3f(0, 0, 0 );
glTexCoord2d(0.0,1.0);glVertex3f(0, 0, 1 );
glEnd();
//Right
glBegin( GL_QUADS );
glNormal3f(1.0f, 0.0f, 0.0f);
glTexCoord2d(1.0,1.0);glVertex3f(1, 1, 1 );
glTexCoord2d(1.0,0.0);glVertex3f(1, 1, 0 );
glTexCoord2d(0.0,0.0);glVertex3f(1, 0, 0 );
glTexCoord2d(0.0,1.0);glVertex3f(1, 0, 1 );
glEnd();
glPopMatrix();

Share this post


Link to post
Share on other sites
Geometrian    1810
Hi,

You may get this result if:
-You're not enabling GL_TEXTURE_2D in your second code
-grid[position].tex doesn't exist (or doesn't work right). Try drawing the second code with grid[3].tex, and see if that fixes it.
-you're drawing these two methods from different places.
-the glTranslatef(...) call in the second method alters the rendering (i.e., if you have white fog enabled, and you move it further away, you'll get problems).

Also, for optimization, you only need one glBegin(...)/glEnd() wrapper for ALL of those polygons.

-G

Share this post


Link to post
Share on other sites
Daaark    3553
Are you enabling texturing in the second example? It's hard to see if it might be elsewhere in your code or not. Also, is the position variable pointing to the right texture?

Use the [ source ] tags next time too.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this