#define PI_ 3.14159265358979323846 class ,咨信网zixin.com.cn" /> #define PI_ 3.141592653589"/>
收藏 分销(赏)

OpenGL ES画球.doc

上传人:s4****5z 文档编号:8054085 上传时间:2025-02-02 格式:DOC 页数:5 大小:66.50KB 下载积分:10 金币
下载 相关 举报
OpenGL ES画球.doc_第1页
第1页 / 共5页
OpenGL ES画球.doc_第2页
第2页 / 共5页


点击查看更多>>
资源描述
#include "PVRShell.h" #include "PVRShellAPI.h" #include <math.h> #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 mat[3] = {0.1745, 0.01175, 0.01175}; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, mat);//环境光 mat[0] = 0.04136; mat[1] = 0.04136; mat[2] = 0.61424; glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, mat);//散射光 mat[0] = 0.727811; mat[1] = 0.626959; mat[2] = 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 GLuint[g_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 = (255L<<24) + ((255L-j*2)<<16) + ((255L-i)<<8) + (255L-i*2); if( ((i*j)/8) % 2 ) col = 0xffff00ff; pTexData[j*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_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); return true; } 球一定要有光照,没有光照不叫球。你看太阳能看出是个球么?他更像圆盘,其实他确实是球。光照效果没有把他呈现成球。我还加了纹理效果,当然看官们可以把纹理关闭。
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服