PDA

View Full Version : Not drawing anything.



Chayan Vinayak
07-17-2011, 06:48 PM
Hello,
I am trying to write a very basic point drawing OpenGL program. But it is not drawing anything.
Following is the code.

Thanks





#include <stdio.h>
#include <glut.h>


void handleResize(int w, int h){
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,double(w)/double(h),1, 100 );
}

void handleKeypress(unsigned char key,int x, int y){
switch(key){
case 27:
exit(0);

}

}
void init(){
glEnable(GL_DEPTH_TEST);
}

void drawScene(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glBegin(GL_POINTS);
glVertex3f(10.0f, 20.0f, -5.1f);
glVertex3f(50.0f, 50.0f, 5.1f);
glEnd();

glBegin(GL_QUADS);
glVertex3f(10.0f, 20.0f, -5.0f);
glVertex3f(50.0f, -50.0f, 5.1f);
glVertex3f(-10.0f, 20.0f, -5.1f);
glVertex3f(-50.0f, -50.0f, 5.1f);
glEnd();

glutSwapBuffers();



}

void main (int argc, char** argv){

glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEP TH);
glutInitWindowSize(400,400);


glutCreateWindow("Chayan Vinayak's OpenGL tutorial ");
init();


glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);
glutMainLoop();


}

xiphos
07-17-2011, 10:47 PM
Points and Quad you are trying to render is not inside camera's frustum.

put glTranslatef(0,0,-90.0f) after glLoadIdentity() in function drawScene(), you can see quad rendered.