ks554
01-26-2009, 02:13 PM
following gluLookat does not work....can any1 see the problem?
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#define ESCAPE 27 //use escape key to exit program
GLint Xsize = 400;
GLint Ysize = 400;
GLint window_name; //name of our window
GLvoid InitWindow(GLfloat Width, GLfloat Height)
{
glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,Width/Height,0.0, 200.0);
glMatrixMode(GL_MODELVIEW);
}
GLvoid ResizeScene(GLint Width, GLint Height)
{
if (Height == 0) Height = 1; //prevent division by zero
if (Width == 0) Width = 1;
InitWindow(Width, Height); //reset perspective projection
}
GLvoid DrawScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -100.0f);
glColor3ub(255, 0, 0);
glutSolidSphere(3.0f, 15, 15);
glutSwapBuffers();
}
void NormalKey(GLubyte key, GLint x, GLint y)
{
switch( key)
{
case ESCAPE:
printf("Escape pressed, exiting..\n");
glutDestroyWindow(window_name);
exit(0);
break;
case 'd':
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(10.0f, 0.0f, -100.0f, 0.0f, 0.0f, -100.0f, 0.0f, 0.0f, 1.0f);
break;
default:
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(Xsize, Ysize);
glutInitWindowPosition(0,0);
window_name = glutCreateWindow("Title");
//Initialise window
InitWindow(Xsize, Ysize);
//Callback functions (Resize & Draw screen)
glutReshapeFunc(ResizeScene);
glutDisplayFunc(DrawScene);
//glutIdleFunc(DrawScene);
//Callback function when a key is pressed
glutKeyboardFunc(NormalKey);
glutMainLoop();
return 1;
}
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#define ESCAPE 27 //use escape key to exit program
GLint Xsize = 400;
GLint Ysize = 400;
GLint window_name; //name of our window
GLvoid InitWindow(GLfloat Width, GLfloat Height)
{
glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,Width/Height,0.0, 200.0);
glMatrixMode(GL_MODELVIEW);
}
GLvoid ResizeScene(GLint Width, GLint Height)
{
if (Height == 0) Height = 1; //prevent division by zero
if (Width == 0) Width = 1;
InitWindow(Width, Height); //reset perspective projection
}
GLvoid DrawScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -100.0f);
glColor3ub(255, 0, 0);
glutSolidSphere(3.0f, 15, 15);
glutSwapBuffers();
}
void NormalKey(GLubyte key, GLint x, GLint y)
{
switch( key)
{
case ESCAPE:
printf("Escape pressed, exiting..\n");
glutDestroyWindow(window_name);
exit(0);
break;
case 'd':
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(10.0f, 0.0f, -100.0f, 0.0f, 0.0f, -100.0f, 0.0f, 0.0f, 1.0f);
break;
default:
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(Xsize, Ysize);
glutInitWindowPosition(0,0);
window_name = glutCreateWindow("Title");
//Initialise window
InitWindow(Xsize, Ysize);
//Callback functions (Resize & Draw screen)
glutReshapeFunc(ResizeScene);
glutDisplayFunc(DrawScene);
//glutIdleFunc(DrawScene);
//Callback function when a key is pressed
glutKeyboardFunc(NormalKey);
glutMainLoop();
return 1;
}