Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Simple Vertex Problem

  1. #1
    Intern Newbie
    Join Date
    Sep 2005
    Posts
    33

    Simple Vertex Problem

    Why would the following code draw line but the bottow one does not.
    glBegin(GL_LINES);
    glVertex3f( 0.0,0.0, 0.0 );
    glVertex3f( 10.0, 10.0, 0.0 );

    glBegin(GL_LINES);
    glVertex3f( 10.0,0.0, 0.0 );
    glVertex3f( 10.0, 10.0, 0.0 );

    Does every line has to be started from 0,0,0 coordinates?

    Even this one does not work-
    glBegin( GL_TRIANGLES );
    glVertex3f(0.0f, 0.0f, 60.0f);
    glVertex3f(-15.0f, 0.0f, 30.0f);
    glVertex3f(15.0f,0.0f,30.0f);

  2. #2
    Guest

    Re: Simple Vertex Problem

    Don't forget you need a glEnd(); command after ever line or poly you draw to tell OpenGL you've finished drawing that object.

    Try that first.

  3. #3
    Intern Newbie
    Join Date
    Sep 2005
    Posts
    33

    Re: Simple Vertex Problem

    oh yes. i have glEnd() at the end. but point being why the bottom 2 does not draw, are coordinates off?

  4. #4
    Junior Member Regular Contributor
    Join Date
    Aug 2005
    Posts
    148

    Re: Simple Vertex Problem

    Post the rest of your render code. You've probably done something silly like drawing black lines on a black background, or misconfigured your projection/camera matrix, or tried to begin a primitive in the middle of another one, or some sinister combination of all the above.

    Is your app running without errors?

    :-)

  5. #5
    Intern Newbie
    Join Date
    Sep 2005
    Posts
    33

    Re: Simple Vertex Problem

    void drawScene( void )
    {

    glClear( GL_COLOR_BUFFER_BIT );
    //Use black pen
    glColor3f( 0.0. 0.0,0.0 );

    //Working
    glBegin(GL_LINES);
    glVertex3f( 0.0,0.0, 0.0 );
    glVertex3f( 10.0, 10.0, 0.0 );

    //Not working
    //glBegin(GL_LINES);
    //glVertex3f( 10.0,0.0, 0.0 );
    //glVertex3f( 10.0, 10.0, 0.0 );

    //Even this one does not work-
    //glBegin( GL_TRIANGLES );
    //glVertex3f(0.0f, 0.0f, 60.0f);
    //glVertex3f(-15.0f, 0.0f, 30.0f);
    //glVertex3f(15.0f,0.0f,30.0f);

    glFlush();
    glutSwapBuffers();
    }

    void init(void )
    {

    glClearColor( 1.0,1.0,1.0,1.0);
    }

  6. #6
    Intern Newbie
    Join Date
    Sep 2005
    Posts
    33

    Re: Simple Vertex Problem

    and the last part is

    int main( int argc, char** argv )
    {
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
    glutCreateWindow("test");
    glutDisplayFunc( drawScene );
    Init();
    glutMainLoop();
    return 0;
    }

  7. #7
    Intern Newbie
    Join Date
    Sep 2005
    Posts
    33

    Re: Simple Vertex Problem

    hmm, i again forgot glEnd() at my drawScene(), assume it is there.

  8. #8
    Guest

    Re: Simple Vertex Problem

    Each glBegin() has to be closed by an glEnd(). Calling glBegin() twice without an closing glEnd() will result in an GL_INVALID_OPERATION condition and all following commands will be ignored.

    So try this instead:

    Code :
    void drawScene( void )
    {
      glClear( GL_COLOR_BUFFER_BIT );
      //Use black pen
      glColor3f( 0.0. 0.0,0.0 );
     
      //Working
      glBegin(GL_LINES);
        glVertex3f( 0.0,0.0, 0.0 );
        glVertex3f( 10.0, 10.0, 0.0 );
      glEnd();
     
      glBegin(GL_LINES);
        glVertex3f( 10.0,0.0, 0.0 );
        glVertex3f( 10.0, 10.0, 0.0 );
      glEnd();
     
      glBegin(GL_TRIANGLES);
        glVertex3f(0.0f, 0.0f, 60.0f);
        glVertex3f(-15.0f, 0.0f, 30.0f);
        glVertex3f(15.0f,0.0f,30.0f); 
      glEnd();
     
      glutSwapBuffers();
    }

  9. #9
    Intern Newbie
    Join Date
    Sep 2005
    Posts
    33

    Re: Simple Vertex Problem

    I understand there should be only one glBegin() and glEnd(). My problem is some where, probably with vertex coordinates. Try the following code, if it draws for you or not. Supposed to draw a triangle, but it does not render.

    void drawScene( void )

    {

    glClear( GL_COLOR_BUFFER_BIT );

    //Use black pen

    glColor3f( 0.0. 0.0,0.0 );

    //Working

    glBegin(GL_TRIANGLES);

    glVertex3f(0.0f, 0.0f, 60.0f);

    glVertex3f(-15.0f, 0.0f, 30.0f);

    glVertex3f(15.0f,0.0f,30.0f);

    glEnd();

    glutSwapBuffers();

    }

  10. #10
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Simple Vertex Problem

    If this is all your code (matrix setup at default) it's obvious why the first line draws (one tenth of its actual length) and no other.
    Having the default identity matrix in both projection and modelview means the same as an glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0) setup with no changes to input vertex coordinates.
    That is, everything which is not in the range between -1.0 and 1.0 in (x,y,z) is outside the viewing frustum.

Posting Permissions

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