I begin to learn Opengl. I creat a Object and rotate it. But it has problem when I use glPushMatrix and glPopMatrix. This is my source:
#include <GL/glut.h>
#include <stdlib.h>
#include <iostream.h>
void Init();
void Display();
void Reshape(int Width,int Height);
void Keyboard(unsigned char Key,int X,int Y);
void Mouse(int button,int state,int x,int y);
void Time(int value);
int radian=10;
void main(int Argc,char** Argv)
{
glutInit(&Argc,Argv);
glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGB| GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(200,100);
glutCreateWindow("Solar System Viewer .");
Init();
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutKeyboardFunc(Keyboard);
glutMouseFunc(Mouse);
glutTimerFunc(100,Time,radian);
glCullFace(GL_BACK);
glutMainLoop();
}
void Init()
{
glClearColor(0.0,0.0,0.0,0.0);
}
void Display()
{
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glPushMatrix();
glRotated(10,0.0,0.0,1.0);
glutWireSphere(GLdouble (0.3),25,25);
glPopMatrix();
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glutSwapBuffers();
}
void Reshape(int w,int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,w,h);
gluPerspective(30.0,1.0,1.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(3.0,4.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0);
}
/* key event */
void Keyboard(unsigned char Key,int X,int Y)
{
}
/* mouse event */
void Mouse(int button,int state,int x,int y)
{
}
void Time(int value)
{
Display();
glutTimerFunc(50,Time,value);
}
if i remove glPushMatrix and glPopMatrix. it’s move But i use it, it stop.
// sorry for my poor english. Talk to me if u don’t understand what i said.