PDA

View Full Version : 3D display of objects



Raman
11-06-2010, 12:05 PM
Hi, I am writing up with my first OpenGL program.
My project due date is on November 30, 2010.

How to make a square that is not in Z plane appear on window?

This following code works out fine.


#include<gl/glut.h>

void init(void)
{
glClearColor(0.0,0.0,0.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 600, 0, 600, 0, 600);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
glColor3f(0.0,0.0,1.0);
glVertex3i(200,200,0);
glVertex3i(200,250,0);
glVertex3i(250,250,0);
glVertex3i(250,200,0);
glEnd();
glFlush();
}

int main(int argc,char **argv)
{
glutInit(&amp;argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(600,600);
glutCreateWindow("Rubik Cube");
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}


But if in case that I replace the Z coordinate for that polygon to 200, then it is not displayed at all.
How to make this appear?


glVertex3i(200,200,200);
glVertex3i(200,250,200);
glVertex3i(250,250,200);
glVertex3i(250,200,200);

Thanks for any help.

BionicBytes
11-06-2010, 06:37 PM
Try -200 as negative z is into the screen znd positive z is towards the screen in OpenGL.