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

Thread: What is the reason?

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2004
    Location
    Shanghai in China
    Posts
    15

    What is the reason?

    GLuint vertexArray[] = { 0, 1, 2, 3, 4, 5 };

    glDrawRangleElements(GL_POLYGON, 2, 5, 4,
    GL_UNSIGNED_INT, vertexArray);

    But it will draw vertexArray[0123], what is the
    reason?

  2. #2
    Junior Member Regular Contributor
    Join Date
    May 2004
    Location
    Renkum
    Posts
    193

    Re: What is the reason?

    Maybe the coordinates aren't correct(check the OpenGL red book for valid and invalid polygons).

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2004
    Location
    Shanghai in China
    Posts
    15

    Re: What is the reason?

    Thank you for your help. But if I changed GL_POLYGON to GL_LINES, the result is same.

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2004
    Location
    Shanghai in China
    Posts
    15

    Re: What is the reason?

    This is the code.

    #include <gl/glut.h>
    #include <gl/glprocs.h>

    static GLint vertices[] = { 25, 25,
    100, 325,
    175, 25,
    175, 325,
    250, 25,
    325, 325 };

    static GLfloat colors[] = { 1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0,
    0.75, 0.75, 0.75,
    0.35, 0.35, 0.35,
    0.5, 0.5, 0.5 };

    void setupVertex()
    {
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    glVertexPointer(2, GL_INT, 0, vertices);
    glColorPointer(3, GL_FLOAT, 0, colors);
    }

    void init()
    {
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_SMOOTH);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 400.0, 0.0, 400.0);
    setupVertex();
    }

    void display()
    {
    glClear(GL_COLOR_BUFFER_BIT);
    GLuint front[] = {0, 1, 2, 3, 4, 5 };
    //glDrawElements(GL_LINES, 6, GL_UNSIGNED_INT, front);
    glDrawRangeElements(GL_LINES, 2, 5, 4, GL_UNSIGNED_INT, front);
    glFlush();
    }

    int main(int argc, char **argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(400, 400);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("");

    init();
    glutDisplayFunc(display);
    glutMainLoop();

    return 0;
    }

  5. #5
    Intern Contributor
    Join Date
    Feb 2000
    Location
    England
    Posts
    72

    Re: What is the reason?

    Your arguments are wrong for glDrawRangeElements.

    The second parameter is the minimum index you use, not where you start from.
    The third parameter is the maximum index you use.

    The code you supplied will indeed render 0,1,2,3 but will also supply an incorrect range.

    glDrawRangeElements will always start from the pointer you give it. It is used to tell the graphics card that you will not use indices outside the supplied range (potential for optimisation).

    To render three lines you call:
    glDrawRangeElements(GL_LINES, 0, 5, 6, front);

    To render just the last two lines you use
    glDrawRangeElements(GL_LINES, 2, 5, 4, &front[2]);

    Matt

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2004
    Location
    Shanghai in China
    Posts
    15

    Re: What is the reason?

    Thanks.

Posting Permissions

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