博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
代码_多媒体_OPENGL
阅读量:2338 次
发布时间:2019-05-10

本文共 1891 字,大约阅读时间需要 6 分钟。

#include 
#include
#include
#include
#include
#pragma comment( lib, "opengl32.lib")#pragma comment( lib, "glu32.lib")#pragma comment( lib, "glaux.lib")void myinit(){ glClearColor(1,1,0,0); GLfloat ambient[]={0.5,0.5,0.5,0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient); GLfloat mat_ambient[]={0.8,0.8,0.8,1.0}; GLfloat mat_diffuse[]={0.8,0,0.8,1.0}; GLfloat mat_specular[]={1.0,0,1.0,1.0}; GLfloat mat_shininess[]={50.0}; GLfloat light_diffuse[]={0,0,0.5,1}; GLfloat light_position[]={0,0,1.0,0}; glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mat_ambient); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_diffuse); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular); glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,mat_shininess); glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); glLightfv(GL_LIGHT0,GL_POSITION,light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST);}void CALLBACK display(){ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); auxSolidSphere(1.0); glFlush(); auxSwapBuffers(); _sleep(10);}void CALLBACK Idledisplay(){ static float x=-0.1,y=0.0; static bool mark=true; static float step=0.01; x+=step; if(x<=0.1 && x>=-0.1){ if(step>0) y=sqrt(0.01-x*x); else{ y=-sqrt(0.01-x*x); glTranslated(x,y,0); } } else{ step=0-step; } display();}void CALLBACK myReshape(GLsizei w,GLsizei h){ glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) glOrtho(-3.5,3.5,-3.5*(GLfloat)w/(GLfloat)h,3.5*(GLfloat)w/(GLfloat)h,-10,10); else glOrtho(-3.5*(GLfloat)w/(GLfloat)h,3.5*(GLfloat)w/(GLfloat)h,-3.5,3.5,-10,10); glMatrixMode(GL_MODELVIEW); glLoadIdentity();}void main(){ auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA); auxInitPosition(0,0,400,400); auxInitWindow("circle"); myinit(); auxReshapeFunc(myReshape); auxIdleFunc(Idledisplay); auxMainLoop(display);}

转载地址:http://gngpb.baihongyu.com/

你可能感兴趣的文章
C#集合类型总结和性能分析
查看>>
Composite 模式——结构模式
查看>>
Decorator——结构型模式
查看>>
JNI——Java调用DLL
查看>>
CL——Windows下命令行运行C/C++
查看>>
Facade——结构模式
查看>>
享元模式Flyweight——结构型模式
查看>>
代理模式(Proxy)——结构模式
查看>>
定制Notepad++插件实现Fastinfoset显示
查看>>
结构型模式总结
查看>>
职责链——对象行为模式
查看>>
Command——对象行为模式
查看>>
解释器——类行为模式
查看>>
迭代器——对象行为模式
查看>>
中介者——对象行为模式
查看>>
备忘录——对象行为模式
查看>>
观察者——对象行为模式
查看>>
状态——对象行为模式
查看>>
模板方法——对象行为模式
查看>>
访问者——对象行为模式
查看>>