Texturing a cylinder

I have a problem with a cylinder.
I already could put a texture on one that had the same radius at both ends. It was wrapped around it like paper around a pipe.
But now I have a very flat cylinder - almost like a disc. The problem is that the texture should be applied like one that is drawn on a disc.
So it should not be wrapped around the outer side but layed on it (like a label on a CD).
Is there a way I can do this…?

You could draw a textured square over the cylinder’s face on which you want to draw.
If you do it, be careful about the glDepthFunc …

:frowning: I didn’t work - I don’t know why.
All I see is a textured square with a cylinder behind it. The square is textured ok - the cylinder not.
I played a little with my test program:
First I tried to use a disc instead of GL_QUADS to apply the texture to, but it didn’t change anything.
Then I tried some other parameters in glDepthFunc. Only GL_NOTEQUAL looked a little like what I was expecting but nothing really made me feel that I am on the right way…

Maybe I should post my test program and hope that somebody tells me what I am doing wrong… :slight_smile:

It seems that DFrey, on the advanced forum, has found a good idea for you : use glPolygonOffset !

No sorry, I can’t make it work.
So here it is: The drawing routine that I used in my test program.
Could you please take a look at it? I just want to be sure that we’re talking about the same thing…


glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, texName);

GLUquadricObj *qobj;
qobj=gluNewQuadric();
gluQuadricTexture(qobj, GL_TRUE);

glDepthFunc(GL_LEQUAL);

GLfloat r = 0.9;
GLfloat h = 0.2;

glPolygonOffset(1.0, 1.0); // ?

// cylinder that is to be textured…
gluCylinder(qobj, 0.3*r, r, h, 20, 1);

glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3f(-r, -r, h);
glTexCoord2f(1.0, 0.0);
glVertex3f( r, -r, h);
glTexCoord2f(1.0, 1.0);
glVertex3f( r, r, h);
glTexCoord2f(0.0, 1.0);
glVertex3f(-r, r, h);
glEnd();

// I also tried this instead of the GL_QUADS
// gluDisk(qobj, 0.0, r, 20, 1);

glDisable(GL_TEXTURE_2D);

gluDeleteQuadric(qobj);

I’m not used to work with glPolygonOffset so you should ask to DFrey. But if I’m not mistaken, it seems that you use the same polygon offset for both your cylinder and square, so that could explain why it does not work. Try using 0,0 for the cylinder and 1,1 (as you do) for the square (or the opposite, i don’t know).