Results 1 to 2 of 2

Thread: GL_QUADS Question

  1. #1
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    GL_QUADS Question

    Can some one help me figure out why this GL_QUAD is not centering in my program:

    #include <gl/glut.h>

    void quad();
    void init();
    void display();

    void quad() {
    glBegin( GL_QUADS );
    glTexCoord2f( 0.0, 0.0 ); glVertex3f( -1.0, 1.0, -1.0 );
    glTexCoord2f( 0.0, 1.0 ); glVertex3f( 1.0, 1.0, -1.0 );
    glTexCoord2f( 1.0, 1.0 ); glVertex3f( 1.0, -1.0, -1.0 );
    glTexCoord2f( 0.0, 1.0 ); glVertex3f( -1.0, -1.0, -1.0 );
    glEnd();
    }

    void keyboard( unsigned char key, int x, int y ) {
    switch( key ) {
    case 27:
    exit( 0 );
    break;
    default:
    break;
    }
    }

    void init() {
    glClearColor( 0.0, 0.0, 0.0, 0.0 );
    glEnable( GL_DEPTH_TEST );
    glShadeModel( GL_SMOOTH );
    }

    void display() {
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    quad();
    glFlush();
    }

    void reshape( int h, int w ) {
    float ratio = 1.0* w / h;

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();

    glViewport( 0, 0, w, h );

    gluPerspective( 25, ratio, 1, 1000 );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    gluLookAt( 0.0,0.0,5.0,
    0.0,0.0,-1.0,
    0.0f,1.0f,0.0f );
    glutSwapBuffers();
    }

    int main( int argc, char** argv ) {
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH );
    glutEnterGameMode();
    init();
    glutDisplayFunc( display );
    glutReshapeFunc( reshape );
    glutKeyboardFunc( keyboard );
    glutMainLoop();
    return 0;
    }

  2. #2
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Re: GL_QUADS Question

    I just figured it out:

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

    void reshape( int w, int h ) {
    if( h == 0 )
    h = 1;

    float ratio = 1.0* w / h;

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();

    glViewport( 0, 0, w, h );

    gluPerspective( 25, ratio, 1, 1000 );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    gluLookAt( 0.0, 0.0, 5.0, 0.0, 0.0, -1.0, 0.0f, 1.0f, 0.0f );
    }

    void display( void ) {
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glPushMatrix();

    glBegin( GL_QUADS );
    glTexCoord2f( 0.0, 0.0 ); glVertex3f( -1.0, 1.0, -1.0 );
    glTexCoord2f( 0.0, 1.0 ); glVertex3f( 1.0, 1.0, -1.0 );
    glTexCoord2f( 1.0, 1.0 ); glVertex3f( 1.0, -1.0, -1.0 );
    glTexCoord2f( 0.0, 1.0 ); glVertex3f( -1.0, -1.0, -1.0 );
    glEnd();

    glPopMatrix();

    glutSwapBuffers();
    }

    void keyboard( unsigned char key, int x, int y ) {
    switch ( key ) {
    case 27: // On 'Esc'
    exit( 0 ); // Quit
    break;
    }
    }

    void main( int argc, char **argv ) {
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );
    glutEnterGameMode();
    glutDisplayFunc( display );
    glutIdleFunc( display );
    glutReshapeFunc( reshape );
    glutKeyboardFunc( keyboard );

    glutMainLoop();
    }

Similar Threads

  1. Do not deprecate GL_QUADS please
    By l_belev in forum OpenGL: General
    Replies: 49
    Last Post: 09-03-2011, 02:20 AM
  2. GL_QUADS not how they should be
    By PSMMet in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-11-2009, 02:38 AM
  3. OpenGL 3.1 question regarding GL_QUADS
    By nullsmind in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-21-2009, 08:02 AM
  4. question on glRasterPos function & GL_QUADS
    By Rectless in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-12-2005, 04:25 AM
  5. speed of GL_QUADS
    By rgreene in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 09-27-2002, 01:38 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