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

Thread: Simple Vertex Problem

  1. #1
    Member 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
    Member 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
    Senior Member Regular Contributor
    Join Date
    Aug 2005
    Posts
    145

    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
    Member 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
    Member 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
    Member 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
    Member 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,450

    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.

Page 1 of 2 12 LastLast

Similar Threads

  1. Simple Letter K with vertex
    By stonedunicorn in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-10-2018, 04:03 PM
  2. Vertex Program (should be) simple error
    By SeskaPeel in forum OpenGL: Advanced Coding
    Replies: 13
    Last Post: 08-22-2003, 09:32 AM
  3. Any simple vertex programs?
    By in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 12-10-2002, 09:22 AM
  4. Simple Vertex Program
    By Ninja in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 11-19-2002, 09:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean