Results 1 to 6 of 6

Thread: Texturing a cylinder

  1. #1
    Junior Member Newbie
    Join Date
    May 2001
    Location
    Germany
    Posts
    14

    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...?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    352

    Re: Texturing a cylinder

    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 ...

  3. #3
    Junior Member Newbie
    Join Date
    May 2001
    Location
    Germany
    Posts
    14

    Re: Texturing a cylinder

    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....

  4. #4
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    352

    Re: Texturing a cylinder

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

  5. #5
    Junior Member Newbie
    Join Date
    May 2001
    Location
    Germany
    Posts
    14

    Re: Texturing a cylinder

    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);

  6. #6
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    352

    Re: Texturing a cylinder

    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).

Similar Threads

  1. Texturing the inside of cylinder
    By Neuron in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-12-2012, 03:18 AM
  2. Multi-Texturing and .... normal texturing?
    By Andy Gilbert in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-06-2010, 05:30 PM
  3. Texturing a cylinder
    By brett01 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-23-2009, 09:01 PM
  4. Multiple-texturing on cylinder.
    By Ravikishore in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 12-20-2009, 10:53 PM
  5. cylinder help
    By brett01 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-14-2008, 08:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean