Results 1 to 2 of 2

Thread: glortho ?!

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2001
    Location
    Halifax,NS,Canada
    Posts
    16

    glortho ?!

    Following is the a portion of my code ..
    The size of the view port is 500, 500 ..

    I'm trying to center the image on the viewport ..

    I have not been able to see the image .. am I doin something wrong ?! Could someone help please ?

    //------------------------------------>

    double world_xmin, world_xmax, world_ymin, world_ymax;
    double range, avg;

    double world_zmin = -20.;
    double world_zmax = +10.;


    double xmin = 57.1044016670;
    double xmax = 57.1047319402;
    double ymin = 1.9807138864;
    double ymax = 1.9809711113;
    double zmin = 88.47;
    double zmax = 89.28;

    double world_ratio;
    double screen_ratio;


    void GLView::initializeGL()
    {
    qglClearColor( black ); // Let OpenGL clear to black
    object = makeObject(); // Generate an OpenGL display list
    glShadeModel( GL_FLAT );
    }

    void GLView::resizeGL( int w, int h )
    {
    world_ratio = (xmax - xmin)/(ymax-ymin);
    screen_ratio = (float) w /(float) h;

    // Modify the world coordinates so they fill as much of the viewport
    // as possible and so that a square in world coordinates will remain
    // a square in the viewport.
    if ( world_ratio >= screen_ratio )
    {
    // The world x size will match the viewport x size. Scale y accordingly.
    range = (xmax - xmin) / screen_ratio ;
    avg = (ymin+ymax)*.5;
    world_xmin = xmin;
    world_xmax = xmax;
    world_ymin = (avg - range*.5);
    world_ymax = (avg + range*.5);
    }
    else
    {
    // The world y size will match the viewport y size. Scale x accordingly.
    range = (ymax - ymin) * screen_ratio ;
    avg = ( xmin + xmax)*.5;
    world_xmin = (avg - .5*range);
    world_xmax = (avg + .5*range);
    world_ymin = ymin;
    world_ymax = ymax;
    }

    glViewport( 0, 0, (GLint)w, (GLint)h );
    glMatrixMode( GL_PROJECTION );

    // Tell OPENGL what the world coordinates are in the viewport
    glOrtho((GLdouble)world_xmin,(GLdouble)world_xmax,
    (GLdouble)world_ymin,(GLdouble)world_ymax,
    (GLdouble)1., (GLdouble)(zmax-zmin+1.));

    glLoadIdentity();
    glMatrixMode( GL_MODELVIEW );
    }

    void GLView: aintGL()
    {
    glClear( GL_COLOR_BUFFER_BIT );

    glPointSize(1.0);
    glLoadIdentity();

    // transform();

    double cx = .5*(world_xmin + world_xmax);
    double cy = .5*(world_ymin + world_ymax) ;
    double cz = .5*(world_zmin + world_zmax) ;

    gluLookAt( 0.,0., world_zmax+1., 0.,0., 0., 0., 1., 0. );

    glCallList( object );
    }


    GLuint GLView::makeObject()
    {
    input.open();

    glLoadIdentity();
    glMatrixMode( GL_MODELVIEW );

    double x,y,z;

    GLuint list;
    list = glGenLists( 1 );

    glNewList( list, GL_COMPILE );
    qglColor( white ); // Shorthand for glColor3f or glIndex
    glBegin( GL_POINTS );
    for (int i = 0; i < input.getNumRecords(); i++)
    {
    x = (double) input.x[i];
    y = (double) input.y[i];
    z = (double) input.z[i];
    glVertex3d( x, y, z );
    input.nextRecord();
    }
    glEnd();
    glEndList();
    return list;
    }

  2. #2
    Senior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    State College, PA
    Posts
    186

    Re: glortho ?!

    You are calling glOrtho to set up your view, and are immediately destroying it with your call to glLoadIdentity - reverse the order of your calls and see what you get.

    Chris

Similar Threads

  1. glOrtho
    By minidrive in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-27-2013, 09:44 PM
  2. glOrtho
    By Bobalandi in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 02-15-2008, 06:12 PM
  3. glOrtho
    By Woods in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-24-2005, 08:39 AM
  4. glortho
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-15-2002, 12:15 AM
  5. glOrtho
    By snowboy in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 06-30-2001, 12:33 PM

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