PDA

View Full Version : i have a problem with glortho



airseb
06-25-2002, 05:58 AM
the cube that i want to do haven't the depth wished. but by changing glortho 's values we get something better, but i don't understand that. Somebody can explain me why ? and give me the appropriate values ?

by changing -1 by less.(but the result is not perfect http://www.opengl.org/discussion_boards/ubb/frown.gif

#include <GL/glut.h>
#include <stdlib.h>


void display (void)
{


static GLint vertices [] = {1,1,0, 10,1,0, 10,10,0, 1,10,0, -2,8,10, 7,8,10,
7,17,10, -2,17,10};

static GLfloat colors_RGB [] = {1.0,0.2,0.2, 0.2,0.2,1.0, 0.8,1.0,0.2, 0.75,0.75,0.75,
0.35,0.35,0.35, 0.5,0.5,0.5};

glEnableClientState (GL_COLOR_ARRAY);
glEnableClientState (GL_VERTEX_ARRAY);
glColorPointer (3, GL_FLOAT, 0, colors_RGB);
glVertexPointer (3, GL_INT, 0, vertices);

static GLubyte toutLesSommets [] = { 0,1,2,3, 4,0,3,7, 5,1,2,6, 4,0,1,5, 7,3,2,6, 4,7,6,5};

glPolygonMode (GL_FRONT , GL_FILL) ;
glFrontFace (GL_CCW) ;
glEnable (GL_CULL_FACE) ;
glCullFace (GL_BACK) ;

glDrawElements (GL_QUADS, 24, GL_UNSIGNED_BYTE, toutLesSommets) ;

glutSwapBuffers() ;
glFlush () ;
}

void main (int argc, char** argv)

{
glutInit (&argc, argv) ;
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) ;
glutInitWindowSize (640, 480) ;
glutInitWindowPosition (250,250) ;
glutCreateWindow (argv [0]) ;

glClearColor (1.0, 1.0, 1.0, 1.0) ;
glClear (GL_COLOR_BUFFER_BIT) ;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho (-5.0, 16.0, -5.0, 16.0, -1.0, 16.0) ;

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glutDisplayFunc (display) ;
glutMainLoop () ;

}

nexusone
06-25-2002, 07:58 AM
I have not tried it but these numbers look odd in your glOrtho (-5.0, 16.0, -5.0, 16.0, -1.0, 16.0) ;

Try something like this glOrtho(20.0 , -20.0, 20.0, -20.0, -5.0, 16.0);

Also have you tried changing from glortho mode to gluPerspective mode to get better depth.



Originally posted by airseb:
the cube that i want to do haven't the depth wished. but by changing glortho 's values we get something better, but i don't understand that. Somebody can explain me why ? and give me the appropriate values ?

by changing -1 by less.(but the result is not perfect http://www.opengl.org/discussion_boards/ubb/frown.gif

#include <GL/glut.h>
#include <stdlib.h>


void display (void)
{


static GLint vertices [] = {1,1,0, 10,1,0, 10,10,0, 1,10,0, -2,8,10, 7,8,10,
7,17,10, -2,17,10};

static GLfloat colors_RGB [] = {1.0,0.2,0.2, 0.2,0.2,1.0, 0.8,1.0,0.2, 0.75,0.75,0.75,
0.35,0.35,0.35, 0.5,0.5,0.5};

glEnableClientState (GL_COLOR_ARRAY);
glEnableClientState (GL_VERTEX_ARRAY);
glColorPointer (3, GL_FLOAT, 0, colors_RGB);
glVertexPointer (3, GL_INT, 0, vertices);

static GLubyte toutLesSommets [] = { 0,1,2,3, 4,0,3,7, 5,1,2,6, 4,0,1,5, 7,3,2,6, 4,7,6,5};

glPolygonMode (GL_FRONT , GL_FILL) ;
glFrontFace (GL_CCW) ;
glEnable (GL_CULL_FACE) ;
glCullFace (GL_BACK) ;

glDrawElements (GL_QUADS, 24, GL_UNSIGNED_BYTE, toutLesSommets) ;

glutSwapBuffers() ;
glFlush () ;
}

void main (int argc, char** argv)

{
glutInit (&argc, argv) ;
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) ;
glutInitWindowSize (640, 480) ;
glutInitWindowPosition (250,250) ;
glutCreateWindow (argv [0]) ;

glClearColor (1.0, 1.0, 1.0, 1.0) ;
glClear (GL_COLOR_BUFFER_BIT) ;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho (-5.0, 16.0, -5.0, 16.0, -1.0, 16.0) ;

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glutDisplayFunc (display) ;
glutMainLoop () ;

}

velco
06-25-2002, 10:32 PM
Originally posted by nexusone:
Try something like this glOrtho(20.0 , -20.0, 20.0, -20.0, -5.0, 16.0);


Or rather
glOrtho (-20, 20, -20, 20, 5, 16);

06-26-2002, 03:23 AM
Are you sure you want an orthographic projection and not a perspective projection?