PDA

View Full Version : gluPerspective stuffed up



MrShoe
12-14-2000, 10:09 PM
I made a simple program that draws a dot on the screen. It uses a double buffer. I use gluPerspective(45, w/h, 1, 1000) in my reshape function. But when I run the program, the window is all black, it does not draw anything! When I delete the line gluPerspective... the program works properly. What is wrong??

MrShoe
12-14-2000, 10:19 PM
Heres the source:
#include <stdio.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

void reshape(int w, int h){
if(h == 0){
h = 1;
}
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, w/h, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);

}


void renderScene(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.2);
glutSwapBuffers();
}

int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(400, 400);
glutInitWindowPosition(100, 100);
glutCreateWindow("Stained Demo");
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutReshapeFunc(reshape);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(1.0);
glutMainLoop();
return 1;
}
This source draws a teapot ,however, this is irrelevant.

Bob
12-15-2000, 06:10 AM
Try to set the glClearDepth to 100 or remove it, and also also insert



glLoadIdentity();
glTranslatef(0.0f, 0.0f, 10.0f);

before drawing the teapot. Also try to increase the size of the teapot.