Results 1 to 3 of 3

Thread: OpenGL: problem with glVertex2iv()

  1. #1
    Join Date
    Aug 2005
    Location
    India
    Beans
    419

    OpenGL: problem with glVertex2iv()

    Hi,

    I'm learning OpenGL, and I'm having some trouble using the glVertex2iv() function:

    Code:
    #include<GL/gl.h>
    #include<GL/glu.h>
    #include<GL/glut.h>
    
    void init()
    {
      glClearColor(0.0, 0.0, 0.0, 0.0);
      glShadeModel(GL_FLAT);
    }
    
    void display()
    {
      glClear (GL_COLOR_BUFFER_BIT);
      glColor3f (1.0, 1.0, 1.0);
      GLint foo[] = {100,100,300,300};
      glBegin(GL_LINES);
       glVertex2iv(foo);
       //glVertex2i(100,100);
       //glVertex2i(300,300);
      glEnd();
      glFlush();
    }
    
    void reshape(int w, int h)
    {
      glViewport(0,0, (GLsizei) w, (GLsizei) h);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h);
    }
    
    int main(int argc, char** argv)
    {
      glutInit(&argc, argv);
      glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
      glutInitWindowSize(640,480);
      glutInitWindowPosition(100,100);
      glutCreateWindow(argv[0]);
      init();
      glutDisplayFunc(display);
      glutReshapeFunc(reshape);
      glutMainLoop();
      return 0;
    }
    The line in red doesn't work, but the lines in green work. I'm quite new to graphics programming. Am I doing something wrong here?

  2. #2
    Join Date
    Dec 2007
    Location
    Gainesville, Florida
    Beans
    Hidden!
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: OpenGL: problem with glVertex2iv()

    glVertext2iv wants a pointer to an array of two elements.

    Code:
    GLint foo1[] = {100, 100};
    GLint foo2[] = {300, 300};
    glVertex2iv(foo1);
    glVertex2iv(foo2);
    you may want to look at vertex arrays

  3. #3
    Join Date
    Aug 2005
    Location
    India
    Beans
    419

    Re: OpenGL: problem with glVertex2iv()

    Thanks for the help It works now. I did check out vertex arrays, I was getting confused between the two.

Tags for this Thread

Bookmarks

Posting Permissions

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