Hey,
I was doing my opengl program and I happen to have a problem,
can you find what is the matter with it?
It rotates a plane with the y axis as the centre when I am using glortho it is working fine, but gluPerspective it is not.
There is some problem with the gluPerspective because when I change the angle to 0 I can just see something but not the whole thing. But when I change it to 45. Nothing comes on the screen and I'm not getting the clue about the near and far values.
Thanks in advance
#include iostream
#include "Xlib.h"
#include "gl.h"
#include "glu.h"
#include "glut.h"
#include math.h
void setupRC()
{
glClearColor(1,0,0,1);
glColor3f(0,0,0);
}
void timerfunc(int value)
{
glutPostRedisplay();
glutTimerFunc(1, timerfunc ,1);
}
void RenderScene()
{
glColor3f(0,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
static GLfloat rot = 0.0f,x =0.0f , y=1.0f , z=0.0f;
rot++;
glPushMatrix();
glRotatef(rot,0.0,1.0,0.0);
glBegin(GL_POLYGON);
glVertex3i(1,-1,0);
glVertex3i(1,1,0);
glVertex3i(-1,1,0);
glVertex3i(-1,-1,0);
glVertex3i(1,-1,0);
glEnd();
glPopMatrix();
if (rot == 360)
rot = 0;
glutSwapBuffers();
}
void ChangeSize(GLint w, GLint h)
{
if(h==0)
h = 1;
GLfloat aspectratio = (GLfloat)w/(GLfloat)h;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, aspectratio, 1,1000);
/*if(w <= h)
glOrtho(-100,100,-100/aspectratio, 100/aspectratio, 1,-1);
else
glOrtho(-100*aspectratio, 100*aspectratio , -100,100,1,-1);*/
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc , char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(0,0);
glutCreateWindow("chelsea");
glutTimerFunc(1, timerfunc , 1);
setupRC();
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
glutMainLoop();
return 0;
}