Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to map a brick texture on the edge of a fountain and I'm using gluDisk for that. How can I make the right coordinates for the disk? My code looks like this and I have only found a function that takes the texture along with the camera.

I want the cubic texture to be alongside of the fountain, but gluDisk does a linear mapping. How do I get a circular mapping?

void Fountain::Draw()
{
    glPushMatrix(); // push 1
    this->ApplyWorldMatrixGL();
    glEnable(GL_TEXTURE_2D); // enable texturing
    glPushMatrix(); // push 2
    glRotatef(90,-1,0,0); // rotate 90 for the quadric

    // also drawing more here...

    // stone texture
    glBindTexture(GL_TEXTURE_2D, texIDs[0]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);   

    glPushMatrix(); // push 3
    glTranslatef(0,0,height);

    // spherical texture generation
    // this piece of code doesn't work as I intended
    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);

    GLUquadric *tub = gluNewQuadric();
    gluQuadricTexture(tub, GL_TRUE);
    gluDisk(tub, radius, outerR, nrVertices, nrVertices);
    gluDeleteQuadric(tub);
    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);

    glPopMatrix(); // pop 3
    // more drawing here...
    glPopMatrix(); // pop 2
    // more drawing here...
    glPopMatrix(); // pop 1
}

To refine my question a bit. This is an image of what it is at default (left) and of what I want (right). The texture should fit in the border of the disk, a lot of times. If this is possible with the texture matrix, than that's fine with me as well. Left is the default texCoords, right is what I want

share|improve this question

1 Answer 1

I'm not sure I understand your diagram. Are you saying you want the image to repeat along the edge of the disk (i.e. the lines represent the borders of the image?) If so, that may produce visual artifacts that you might want to consider first.

The way you've drawn it here, the image will compress near the inner part of the disk, and stretch near the outer part. The different radii of the inner/outer circle causes the arc lengths to be different. You're essentially mapping a square to a trapezoid. I would post an image, but my account is too new. Argh.

I don't think GLU offers any other form of texture mapping for disks. If you want that kind of custom texture coordinates, you probably need to roll your own form of disk generation, which isn't that bad anyways. Still, you might want to reconsider using GLU for actual geometry anyways.

share|improve this answer
    
That is indeed exactly what I want. Why shouldn't I use Quadrics? I thought it was better than doing it by myself with a glBegin(). I already have the code for my own ring, which is very easy with a quad strip, but I was just curious if you can change these texture coordinate generations. If it really is a no-go, then I would accept that. –  Marnix Mar 6 '11 at 20:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.