PDA

View Full Version : What use of glutTimerFunc()? It do not do job. 8(



Suvcon
01-17-2001, 07:38 AM
it do not do any job except once.

glutTimerFunc(),how to use?


=================================


#include <gl/glut.h>
#include <gl/glaux.h>
#include <windows.h>
#include <stdio.h>
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
float xx(-1.0f);

void renderScene(void)
{

glClear(GL_COLOR_BUFFER_BIT);

glColor4f(1.0f,0.0f,0.0f,0.0f);
glBegin(GL_LINES);
glVertex3f(0.0f,-1.0f,0.0f);
glVertex3f(xx,1.0f,0.0f);
glEnd();

glFinish();


}

void pp(int k)
{
if(xx>=2.0f)xx=-1.5f;
xx+=0.5f;
renderScene();
}
void keyfunc(unsigned char key,int x,int y)
{
}


void changeSize(int w, int h)
{
if(h == 0) h = 1; float ratio = 1.0* w / h;
glMatrixMode(GL_PROJECTION);glLoadIdentity();
glViewport(0, 0, w, h);

gluPerspective(45,ratio,1,10);

glMatrixMode(GL_MODELVIEW);glLoadIdentity();
gluLookAt(0.0,0.0,5.0, 0.0,0.0,-1.0, 0.0f,1.0f,0.0f);
}

void main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("!!");
glClearColor(1.0f,1.0f,1.0f,1.0f);
glEnable(GL_TEXTURE_2D);
glutKeyboardFunc(keyfunc);
glutReshapeFunc(changeSize);
/////////////////////////////////////////////
///here i call glutTimerFun(),but is do no job but first time.
glutTimerFunc(1,pp,1);
//////////////////////////////////////////////
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutMainLoop();

}

zed
01-17-2001, 10:47 AM
in the pp function stick another call to
glutTimerFunc(1,pp,1);