Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Texture on a disk

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    4

    Texture on a disk

    I have defined a disk with a triangle fan and I want to put a texture on it. Unfortunately, I can't figure out how to define the texture coordinates.

    Can anyone help me?

    Thanks in advance for the time you will spend trying to help me.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    It depends on how you want to texture. Do you want to drap a square raster over the circle?

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    4
    Quote Originally Posted by tonyo_au View Post
    It depends on how you want to texture. Do you want to drap a square raster over the circle?
    My texture image represents a circular picture and I want this circular area to be drawn on the surface of my disk. Let's say I want to put the texture on both faces of a coin.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    Then the center of your disk has UV if 0.5,0.5 and the other vertices lie on a circle where the vertex (radius,0,0) maps to UV (1,0.)

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    4
    Quote Originally Posted by tonyo_au View Post
    Then the center of your disk has UV if 0.5,0.5 and the other vertices lie on a circle where the vertex (radius,0,0) maps to UV (1,0.)
    Sorry but I don't understand your answer.

    My disk is made of n triangles, and triangle i has the center of the disk as the first vertex, (radius*cos((i-1)*a),radius*sin((i-1)a)) as second vertex and (radius*cos(i*a),radius*sin(i*a)) for third vertex. Can you please explicitely tell me what the texture coordinates should be to have the disk drawn in my texture image to be pasted over my 3D disk?

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    If my maths is right, the each vertex the uv will be( (cos((i-1)*a)+1)/2, (sin((i-1)a)+1)/2)

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    4
    Then your math is wrong...

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    I don't think so
    Code :
      double a = DEGREES2RADIANS(45);
     
     
      float ox = 200;
      float oy = 200;
      float r = 100;
     
      glBegin(GL_TRIANGLE_FAN);
        glColor3f(0.5,.5f,0.0f);
        glVertex3f(ox,oy,0);
     
        for (int i = 0; i < 7; i++)
        {
          float u = (float(cos((i-1)*a))+1.0)/2.0;
          float v = (float(sin((i-1)*a))+1.0)/2.0;
          float cx = float(cos((i-1)*a)) * r;
          float cy = float(sin((i-1)*a))* r;
          glColor3f(u,v,0);
          glVertex3f(cx+ox,cy+oy,0);
      }
      glEnd();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •