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 3 of 3

Thread: How to creat Gradients in 2D primitives in GLUT

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2001
    Location
    Islamabad,capital,Pakistan.
    Posts
    14

    How to creat Gradients in 2D primitives in GLUT

    can anyone tell me how to create Gradients in openGL primitives in GLUT?
    Only Human

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2002
    Location
    Recife - PE - Brazil
    Posts
    15

    Re: How to creat Gradients in 2D primitives in GLUT

    Just a sample:

    Enable Blend
    Define Blend funcion
    Begin draw primive
    Set color with alpha
    Draw bottom vertexs
    Set new alpha
    Draw remind vertexs
    End draw

    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glBegin (GL_QUADS);
    glColor4f (0.0, 1.0, 0.0, 0.0);
    glVertex3f (0.0, 0.0, 0.0);
    glVertex3f (0.5, 0.0, 0.0);
    glColor4f (0.0, 1.0, 0.0, 1.0);
    glVertex3f (0.5, 0.5, 0.0);
    glVertex3f (0.0, 0.5, 0.0);
    glEnd ();

  3. #3
    Junior Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Holland
    Posts
    184

    Re: How to creat Gradients in 2D primitives in GLUT

    Originally posted by onlyhuman23:
    can anyone tell me how to create Gradients in openGL primitives in GLUT?
    If you are talking about color-gradients (like a fade from dark blue to white, or from red to yellow), the quickest way is to enable GL_SMOOTH shading (glShadeModel( GL_SMOOTH) ) and draw the corners of your primitives in the right color (one side col1, opposite side col2).

    A more advanced way to do this is to define a 1-dimensional texture that contains the gradient you want to display and use that to texture the primitives that need the gradient. This allows you to let the gradient fade across different colors (like a rainbow).
    This latter method works best when combined with texture coordinate generation, but supplying your own texture coordinates can produce quite good results too depending on the geometry you use and the required direction of the gradiens (i.e. if they are aligned with the primitives or not).

    (as an aside: GLUT doesn't help you creating gradients, once you have a working window to draw onto, it's just OpenGL)

    HTH

    Jean-Marc

Posting Permissions

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