



免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include PVRShell.h #include PVRShellAPI.h #include #define PI_ 3.14159265358979323846 class CLesson2 : public PVRShell float DegToRad(float deg); public: virtual bool InitApplication(); virtual bool InitView(); virtual bool ReleaseView(); virtual bool QuitApplication(); virtual bool RenderScene(); protected: private: ; bool CLesson2:InitApplication() return true; bool CLesson2:QuitApplication() return true; /这个函数抠至 gult|es void PlotSpherePoints(GLfloat radius, GLint stacks, GLint slices, GLfloat* v, GLfloat* n, GLfloat* t) GLint i, j; GLfloat slicestep, stackstep; stackstep = (GLfloat)PI_) / stacks; slicestep = 2.0f * (GLfloat)PI_) / slices; for (i = 0; i stacks; +i) GLfloat a = i * stackstep; GLfloat b = a + stackstep; GLfloat s0 = (GLfloat)sin(a); GLfloat s1 = (GLfloat)sin(b); GLfloat c0 = (GLfloat)cos(a); GLfloat c1 = (GLfloat)cos(b); for (j = 0; j = slices; +j) GLfloat c = j * slicestep; GLfloat x = (GLfloat)cos(c); GLfloat y = (GLfloat)sin(c); *n = x * s0; *v = *n * radius; n+; v+; *n = y * s0; *v = *n * radius; n+; v+; *n = c0; *v = *n * radius; n+; v+; *n = x * s1; *v = *n * radius; n+; v+; *n = y * s1; *v = *n * radius; n+; v+; *n = c1; *v = *n * radius; n+; v+; *t = 0.0f;t+; *t = 0.0f;t+; *t = 1.0f;t+; *t = 0.0f;t+; *t = 0.5f;t+; *t = -1.0f;t+; int iS = 720; GLint slices = 100;/圆的轴数,轴越多圆弧越弯曲 GLint stacks = 500;/饱和度,值越大,越鼓 GLfloat radius = 0.4f;/半径 static GLfloat* v, *n, *t; GLuint m_ui32Texture; bool CLesson2:InitView() /球顶点 v = (GLfloat*)malloc(stacks*(slices+1)*2*3*sizeof *v); /球法线 n = (GLfloat*)malloc(stacks*(slices+1)*2*3*sizeof *n); /球纹理 t = (GLfloat*)malloc(stacks*(slices+1)*2*3*sizeof *n); PlotSpherePoints(radius, stacks, slices, v, n,t); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); GLfloat position = 0.5, 0.5, -1.0, 0.0 ; glEnable(GL_DEPTH_TEST); glLightfv(GL_LIGHT0, GL_POSITION, position); /* GLfloat mat3 = 0.1745, 0.01175, 0.01175; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, mat);/环境光 mat0 = 0.04136; mat1 = 0.04136; mat2 = 0.61424; glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, mat);/散射光 mat0 = 0.727811; mat1 = 0.626959; mat2 = 0.626959; glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, mat);/聚光 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 0.6*128.0); */ /增加纹理 glEnable(GL_TEXTURE_2D); glGenTextures(1, &m_ui32Texture); int g_i32TexSize = 128; GLuint* pTexData = new GLuintg_i32TexSize*g_i32TexSize; for(int i = 0; i g_i32TexSize; +i) for(int j = 0; j g_i32TexSize; +j) / Fills the data with a fancy pattern GLuint col = (255L24) + (255L-j*2)16) + (255L-i)8) + (255L-i*2); if( (i*j)/8) % 2 ) col = 0xffff00ff; pTexDataj*g_i32TexSize+i = col; glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, g_i32TexSize, g_i32TexSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, pTexData); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); return true; bool CLesson2:ReleaseView() return true; PVRShell * NewDemo(void) return new CLesson2(); bool CLesson2:RenderScene() GLint i, triangles; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glVertexPointer(3, GL_FLOAT, 0, v); glNormalPointer(GL_FLOAT, 0, n); glTexCoordPointer(2,GL_FLOAT,0,t); glEnableClientState (GL_VERTEX_ARRAY); glEnableClientState (GL_NORMAL_ARRAY); glEnableClientState (GL_TEXTURE_COORD_ARRAY); triangles = (slices + 1) * 2; for(i = 0; i stacks; i+) glDrawArrays(GL_TRIANGLE_STRIP, i * triangles, triangles); glDisableClientState(GL_VERTEX_ARRA
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论