Hi, friends,
I need help on this? I am doing simple(be complicated later) animation project using opengl. What I will do is just moving a ball
or cube from left to the right.
I am using
P4 2.0G, 256M PC 133,
inno3d Geforce2MX400 32 M,
with opengl, and glut3.7
The whole program is here"
//the beginning =====================
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
GLboolean pause = GL_FALSE;
GLint shapecode = 1; //default is sphere
GLint control;
GLint draw;
void init(void)
{
glClearColor (1.0, 1.0, 1.0, 0.0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glFrontFace(GL_CW);
glCullFace(GL_BACK);
glMaterialf (GL_FRONT, GL_SHININESS, 64.0);
{
GLfloat pos[] = {0.,150.,1.,1.};
glLightfv(GL_LIGHT0, GL_POSITION, pos);
}
}
void display(void)
/* drawing happens here */
{
static float xpos= -7.0;
static int angle = 0.0;
static float rot = 0.0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if(xpos < 7)
xpos = xpos+0.05;
else
xpos = -7.0;
angle = (angle + 2) % 360;
glTranslatef(xpos, -1.0, -15.0);
glRotatef((GLfloat)angle, 1., 1.,0.);
glutSolidCube(2.0);
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40., 1.0, 10.0, 200.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void animate(void)
{
if (pause != GL_TRUE)
{
glutSetWindow(control);
glutPostRedisplay();
}
}
void mouse(int button, int state, int x, int y)
{
if(state == GLUT_DOWN)
pause = !pause;
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowPosition(10, 10);
glutInitWindowSize(1000,1000);
control = glutCreateWindow("cube View");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(animate);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}
//the end ======================
It is simple, It moves, but not smooth with (1000x1000 window size. Is it because my
animation mothod is not right, or I need do sth else to my hardward setting?
Thanks a lot