hello,
I really dont know whats wrong with the code.I am new to opengl and could not figure out ,why I am not seeing anything on screen.
#include<Windows.h>
#include<stdlib.h>
#include<gl/GL.h>
#include<gl/GLU.h>
#include<gl/glut.h>
using namespace std;
void initrendering()
{
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glClearColor(1.0,0.3,0.8,1.0);
}
void keypres(unsigned char key, int w,int h)
{
switch(key){
case 27:exit(0);
}
}
void resize(int w,int h)
{
glViewport(0,0,w,h);
gluPerspective(60,(double)w/h,1.0,200.0);
}
bool movingup=false;
float trans=0.0f;
float rotat=0.0f;
void drawscene()
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glTranslatef(0.0,0.0,-5.0);
glTranslatef(0.0,trans,0.0);
glRotatef(rotat,0.0,1.0,0.0);
glutWireCube(1.0);
glPopMatrix();
// glFlush();
if (movingup)
trans -= 0.005f;
else
trans += 0.005f;
if (trans < -3.0f)
movingup = false;
else if (trans > 3.0f)
movingup = true;
rotat += 0.005f;
if (rotat > 360.0f)
rotat -= 360.0f;
glutSwapBuffers();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(400, 400);
glutCreateWindow("UP AND DOWN");
initrendering();
glutDisplayFunc(drawscene);
glutIdleFunc(drawscene);
glutKeyboardFunc(keypres);
glutReshapeFunc(resize);
glutMainLoop();
return 0;
}
Please help, most of my codes are not rendering anything on screen.
Regards
Abhinav