您好,欢迎光临本网站![请登录][注册会员]  
文件名称: openGL程序
  所属分类: 其它
  开发工具:
  文件大小: 1kb
  下载次数: 0
  上传时间: 2014-06-02
  提 供 者: qq_16******
 详细说明: #include #include #include #include #include"../../wgGameLib03/dms/FileImage.h" #include"../../wgGraphLib/GraphElemenfs.h" GLint iWidth, iHeight, iGomponents.h; GLenum eFormat; GLfloat xRot,yRot; GLfloat noLight[4]={0.0f,0.0f,0.0f,1.0f}; GLfloat ambientLight[4]={0.3f,0.3f,0.3f,0.2f}; GLfloat brightLight[4]={1.0f,1.0f,1.0f,0.3f}; static GLfloat lightPos[]={5.0f,5.0f,5.0f,1.0f}; void Init() { glClearColor(0.0f,0.0f,0.0f,1.0f); glCullFace( GL_BACK); glFrontFace(GL_CCW); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glLigntModelfv(GL_LIGHT_MODEL_AMBIENT,noLight); glLightfv(GL_LIGHTO,GL_AMBIENT,ambientLight); glLightfv(GL_LIGHTO,GL_DIFFUSE,diffuseLight); glLightfv(GL_LIGHTO,GL_SPECULAR,brightLight); glLightfv(GL_LIGHTO,GL_POSITION,lightPos); glEnable(GL_COLOR_MATERIAL); glColorMateriali(GL_FRONT,GL_AMBIENT_AND_DIFFUSE); glMaterialfv(GL_FRONT,GL_SPECULAR,brightLight); glMateriali(GL_FRONT,GL_SHININESS,30); glPixelStorei(GL_UNPACK_ALIGHMENT,1); dms::FileImage image("stone.jpg"); if(image.data()) { glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image.width(),image.height(),0,GL_RGBA,GL_UNSIGNED_BYTE,image.data()); //glTexImage2D(GL_TEXTURE_2D,0,iComponents,iWidth,iHeight,0,eFormat,GL_UNSIGNED_BYTE,pImage); free(image.data()); } float colorl[4]={1.0,0.1,0.1,1.0}; glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_BLEND); glEnable(GL_TEXTURE_2D); } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); float vertices[5][3]={{0.0f,0.8f,0.0f}, {-0.50f,0.0f,-0.50f}, {0.5f,0.0f,-0.5f}, {0.50f,0.0f,0.50f}}; float normal[3]; glPushMatrix(); glTranslatef(0.0f,-0.3f,-4.0f); if(xRot>360.5f) { xRot=0.0f; } if(yRot>360.5f) { yRot=0.0f; } glBotatef(xROt,1.0f,0.0f,0.0f); glRotatef(yRot,0.0f,1.0f,0.0f); xRot+=0.5f; yRot+=0.5f; glBegin(GL_TRIANGLES); glColor3f(1.0f,0.0f,0.0f); glNormal3f(0.0f,-1.0f,0.0f); glTexCoord2f(0.0f,1.0f); glVertex3fv(vertices[1]); glTexCoord2f(1.0f,0.0f); glVertex3fv(vertices[2]); glTexCoord2f(0.0f,1.0f); glVertex3fv(vertices[4]); glTexCoord2f(1.0f,0.0f); glVertex3fv(vertices[4]); glTexCoord2f(0.0f,0.0f); glVertex3fv(vertices[3]); glTexCoord2f(0.0f,1.0f); glVertex3fv(vertices[1]); glColor3f(0.0f,0.0f,1.0f); wgGetNormal(vertices[1],vertices[3],vertices[0],normal); glNormal3f(normal); glTexCoord2f(0.0f,0.0f); glVertex3fv(vertices[1]); glTexCoord2f(1.0f,0.0f); glVertex3fv(vertices[3]); glTexCoord2f(0.5f,0.5f); glVertex3fv(vertices[0]); glColor3f(0.0f,1.0f,1.0f); wgGetNormal(vertices[0],vertices[4],vertices[2],normal); glNormal3f(normal); glTexCoord2f(0.5f,0.5f); glVertex3fv(vertices[0]); glTexCoord2f(0.0f,0.0f); glVertex3fv(vertices[4]); glTexCoord2f(1.0f,0.0f); glVertex3fv(vertices[2]); glColor3f(1.0f,0.0f,1.0f); wgGetNormal(vertices[0],vertices[2],vertices[1],normal); glNormal3f(normal); glTexCoord2f(0.5f,0.5f); glVertex3fv(vertices[0]); glTexCoord2f(0.0f,0.0f); glVertex3fv(vertices[2]); glTexCoord2f(1.0f,0.0f); glVertex3fv(vertices[1]); glEnd(); glPopMatrix(); glutSwapBuffers(); } voidReshape(GLsizei w,GLsizei h) { if(h==0) h=1; glViewport(0,0,w,h); float fAspect=(GLfloat)w/(GLfloat)h; glMatrixMade(GL_PROJECTION); glLoadIdentity(); glutPostRedisplay(); } void TimerFunc(int value) { glutPostRedisplay(); glutTimerFunc(60,TimerFunc,1); } int main(int args,char *argv[]) { glutInit(&args,argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(512,512); glutCreatWindow("example"); glutDisplayFunc(display); glutReshapeFunc(Reshape); Init(); glutTimerFunc(50,TimerFunc,1); //tTexture glutMainLoop(); return 0; } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: openGL
 输入关键字,在本站1000多万海量源码库中尽情搜索: