#include<GL/glut.h>
#include<stdlib.h>
float move=0.0;
static float movey=0.0;
//initiate property light model of material
void init(void)
{
GLfloat mat_specular[]={1.0,1.0,1.0,1.0};
GLfloat mat_shininess[]={50.0};
GLfloat light_position[]={1.0,1.0,1.0,1.0};
glClearColor(0.5,0.5,0.0,0.0);
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
//use the funtion of GLUT to draft the sphere
void display_old(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.0,0.0,-7.0);
glutSolidSphere(0.5,40,50);
glutSwapBuffers();
glFlush();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.0,0.0,-7.0);
glTranslatef(move,movey,0.0);
glutSolidSphere(0.5,40,50);
glutSwapBuffers();
glFlush();
}
//define the reshape and w is the wide , h is the hight of the window
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();
}
//define the MOveSphere()
void MoveSphere()
{
int i;
for(i=0;i<2;i++)
{
if(move<4.0) move+=0.0009;
else move=0.0;
display();
glLoadIdentity();
}
glLoadIdentity();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(300,300);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(MoveSphere);
glutMainLoop();
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
OpenGL_球的滚动
共13个文件
pdb:2个
exe:1个
dsp:1个
4星 · 超过85%的资源 需积分: 9 24 下载量 61 浏览量
2009-12-09
22:29:59
上传
评论 1
收藏 215KB RAR 举报
温馨提示
在这个程序中使用openGL函数库,调用opengl画圆函数,再将画的圆进行平移和旋转。
资源推荐
资源详情
资源评论
收起资源包目录
Ex2_4.rar (13个子文件)
Ex2_4
4.plg 721B
4.dsw 527B
4.dsp 3KB
4.c 2KB
Debug
4.ilk 234KB
vc60.pdb 44KB
4.pdb 441KB
vc60.idb 33KB
4.exe 184KB
4.pch 327KB
4.obj 10KB
4.ncb 41KB
4.opt 53KB
共 13 条
- 1
资源评论
- cl584540772013-11-06唉,用不了唉,dll文件找不到
- DBMouse2013-03-25虽然不是我要的,不过也确实是会滚动的球,只是我想要3D的,这个是2D的
lgdrj2007
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功