OpenGL step to step(2)
2024-10-21 18:29:25
这是一个类似于地球绕太阳旋转的demo
原有的例子是用键盘接受事件,我做了修改,使用了timer把他变成一个动态旋转的
#import <Foundation/Foundation.h>
#include <GLUT/GLUT.h>
static int year=,day=;
void init()
{
glClearColor(,,,);
glShadeModel(GL_FLAT);
} void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(,,);
glPushMatrix();
glutWireSphere(,,);
glRotatef((GLfloat)year,,,);
glTranslated(,,); glRotatef((GLfloat)day,,,);
glutWireSphere(0.2,,);
glPopMatrix();
glutSwapBuffers(); } void reshape(int w,int h)
{
glViewport(, , (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); gluPerspective(,(GLfloat)w/(GLfloat)h,,);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(,,,,,,,,);
} void fishboard()
{
day=(day+)%;
year=(year+)%;
glutPostRedisplay();
} void timerProc(int id)
{
fishboard();
glutTimerFunc(,timerProc,);//需要在函数中再调用一次,才能保证循环
} int main(int argc,char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(, );
glutInitWindowPosition(,);
glutCreateWindow("Xcode Glut Demo");
init(); glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutTimerFunc(,timerProc,); glutMainLoop();
return ;
}
最新文章
- Android开发中上线后修改应用名称的若干问题
- jquery parent和parents的区别
- Kafka集群部署
- OSG绘制几何图形
- 图解CISCO 3550忘记密码解决方法
- codeforces #305 A Mike and Frog
- Web版RSS阅读器(三)——解析在线Rss订阅
- C socket demo
- VMware 虚拟机(linux)增加根目录磁盘空间 转自
- sass安装步骤
- Android - Get Bluetooth UUID for this device
- 安卓handler、thread实现异步任务
- ssh用法及命令
- python输入字符串
- HD,3G视频数据中行号的插入方法---Verilog代码实现
- centos6.8 固定IP
- Python开发——面向对象【类、实例】
- 发布库到仓库 maven jcenter JitPack MD
- Spark2.0.0源码编译
- SpringBoot(四)-- 整合Servlet、Filter、Listener