I am a beginner of OPenGL and now nearly learn it about two months.
This is a simple program that drawing a wired sphere with briefly rotation and scale
what i want to know is why the sphere keeping FLASH during its moving?
How to avoid flash and make it became more smooth?
any idea is welcome!
here is all, click left button on the window’s client area will start the animation
#include "windows.h"
#include "GL/glut.h"
//sphere radius
GLfloat radius = 1.0 ;
void init(void)
{
//background color
glClearColor(0.6, 0.0, 0.0, 0.0) ;
}
void display(void)
{
//clear buffers
glClear(GL_COLOR_BUFFER_BIT) ;
//execute
glFlush() ;
}
void spinDisplay(void)
{
//draw a wired sphere
glutWireSphere(radius, 12, 8) ;
//rotation
glRotated(1.0, 1.0, 1.0, 1.0) ;
//zoom
glScalef(1.001, 1.001, 1.001) ;
//deferment
Sleep(10) ;
//redraw
glutPostRedisplay() ;
}
//handle mouse event, start when left button down, do not respond other clicks
void mouse(int button, int state, int x, int y)
{
switch(button)
{
case GLUT_LEFT_BUTTON:
if(state==GLUT_DOWN)
glutIdleFunc(spinDisplay) ;
break ;
default:
if(state==GLUT_DOWN)
glutIdleFunc(NULL) ;
break ;
}
}
//reshape window function
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h) ;
glMatrixMode(GL_PROJECTION) ;
glLoadIdentity() ;
if(w<=h)
glOrtho(-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w,
1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0) ;
else
glOrtho(-1.5*(GLfloat)w/(GLfloat)h,
1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0) ;
glMatrixMode(GL_MODELVIEW) ;
glLoadIdentity() ;
}
int main(int argc, char **argv)
{
//Call this function at first
glutInit(&argc, argv) ;
//window pattern
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH) ;
//window size
glutInitWindowSize(800, 500) ;
//window position
glutInitWindowPosition(0, 0) ;
//create window
glutCreateWindow("sphere") ;
//initialization
init() ;
//redraw funtion
glutDisplayFunc(display) ;
//call this function when window size changed or window moved
glutReshapeFunc(reshape) ;
//mouse event function
glutMouseFunc(mouse) ;
//loop function
glutMainLoop() ;
return 0 ;
}