資源描述:
《簡(jiǎn)單Opengl時(shí)鐘時(shí)鐘源代碼 可以運(yùn)行》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、#pragmacomment(lib,"glut32.lib")#pragmacomment(lib,"glu32.lib")#pragmacomment(lib,"opengl32.lib")#include#include#definePI3.14159GLfloatm_rotAngle=0.0;voidDisplay(void){glClear(GL_COLOR_BUFFER_BIT
2、GL_DEPTH_BUFFER_BIT);glLineWidth(5);GLfloati,angle;GLintcircle_point
3、s=100;GLintcircle_point=60;glBegin(GL_LINE_LOOP);//繪制鬧鐘的外圓for(i=0;i4、;}glEnd();glMatrixMode(GL_MODELVIEW);glLoadIdentity();glPointSize(1);glBegin(GL_POINTS);//繪制秒針刻度for(i=0;i5、度for(i=0;i<12;i++){angle=2*PI*i/12;glVertex2f(95*cos(angle),95*sin(angle));}glEnd();glMatrixMode(GL_MODELVIEW);glLoadIdentity();glColor3f(1.f,1.f,0.f);glPushMatrix();//繪制秒針glRotatef(m_rotAngle,0.0f,0.0f,1.0f);glTranslatef(0.0f,10.0f,0.0f);glBegin(GL_TRIANGLES);glVertex3f(0,-100,0);gl
6、Vertex3f(1,0,0);glVertex3f(-1,0,0);glEnd();glPopMatrix();//繪制分針glColor3f(1.f,0.f,0.f);glPushMatrix();glRotatef(m_rotAngle/60,0.0f,0.0f,1.0f);glTranslatef(0.0f,10.0f,0.0f);glBegin(GL_TRIANGLES);glVertex3f(0,-80,0);glVertex3f(1,0,0);glVertex3f(-1,0,0);glEnd();glPopMatrix();glColor3f(0.
7、f,0.f,1.f);glPushMatrix();//繪制時(shí)針glRotatef(m_rotAngle/3600,0.0f,0.0f,1.0f);glTranslatef(0.0f,10.0f,0.0f);glBegin(GL_TRIANGLES);glVertex3f(0,-60,0);glVertex3f(1,0,0);glVertex3f(-1,0,0);glEnd();glPopMatrix();m_rotAngle+=6.0f;if(m_rotAngle>216000.0f)m_rotAngle=0.0f;glutSwapBuffers();}voi
8、dInit(){glEnable(GL_DEPTH_TEST);//啟用隱藏面移除glClearColor(0.0f,0.0f,0.0f,1.0f);}voidGLTimer(intvalue){glutPostRedisplay();glutTimerFunc(100,GLTimer,1);}voidReshape(intw,inth){GLfloatnRange=100.0f;if(h==0)h=1;glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();if(w<=h)glOrtho
9、(-nRange,nRa