关于openGL立方体,只有一个面有反射,其他面没有 20C

#include "stdafx.h"
#include
#include
#include
#include
#include
static GLfloat angle=0.0f;

void setNormal(GLfloat* Point1,GLfloat* Point2,GLfloat* Point3){
GLfloat normal[3];
int i;
for(i=0;i<3;++i){
normal[i]=(Point1[i]+Point2[i]+Point3[i])/3;
glNormal3fv(normal);}
}
void setNormal2(GLfloat* Point1,GLfloat* Point2){
GLfloat normal[3];
int i;
for(i=0;i<3;++i){
normal[i]=(Point2[i]-Point1[i]);
glNormal3fv(normal);}
}

void myDisplay(void)

{
static int list = 0;
if (list==0){
GLfloat
Point1[]={0.107991,0.060569,-0.108414},
Point2[]={0.107991,0.060569,0.108414},
Point3[]={-0.107991,0.060569,0.108414},
Point4[]={-0.107991,0.060569,-0.108414},
Point5[]={0.107992,0.277397,-0.108414},
Point6[]={0.107991,0.277397,0.108414},
Point7[]={-0.107992,0.277397,0.108414},
Point8[]={-0.107991,0.277397,-0.108414},
Pointa[]={0.000000,-1.000000,-0.000000},
Pointb[]={0.000000,1.000000,0.000000},
Pointc[]={1.000000,-0.000000,0.000000},
Pointd[]={-0.000000,-0.000000,1.000000},
Pointe[]={-1.000000,-0.000000,-0.000000},
Pointf[]={0.000000,0.000000,-1.000000};

glMatrixMode(GL_PROJECTION);//操作投影矩阵,投影变换就是定义一个可视空间,空间之外的物体不会绘制到屏幕上
glLoadIdentity();//变换前把当前矩阵设置为单位矩阵
gluPerspective(60.0f,1.0f,0.1f,20.0f);//可视空间视角,高宽比,最近可视距离,最远可视距离
glMatrixMode(GL_MODELVIEW);//变换前,设置当前操作的矩阵为模型视图矩阵
glLoadIdentity();//变换前把当前矩阵设置为单位矩阵
gluLookAt(0.8,-0.8,0.0,0.0,0.0,0.0,0.0,1.0,0.0);

    list=glGenLists(1);
    glNewList(list,GL_COMPILE);
    {
GLfloat sun_light_position[]={0.0f,0.0f,0.5f,1.0f};//光源的位置
GLfloat sun_light_ambient[]={0.0f,0.5f,0.0f,1.0f};//光源发出的光经过多次反射后,最终遗留在整个光照环境的强度
GLfloat sun_light_diffuse[]={0.0f,0.0f,0.2f,1.0f};//光源发出的光经过漫反射后,得到的光强
GLfloat sun_light_specular[]={0.0f,1.0f,0.5f,1.0f};//光源发出的光,照到光滑表面经过镜面反射,得到的光强
glLightfv(GL_LIGHT0,GL_POSITION,sun_light_position);
glLightfv(GL_LIGHT0,GL_AMBIENT,sun_light_ambient);
glLightfv(GL_LIGHT0,GL_DIFFUSE,sun_light_diffuse);
glLightfv(GL_LIGHT0,GL_SPECULAR,sun_light_specular);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
}



    {
 glPushMatrix();
 glBegin(GL_QUADS);
 //setNormal(Point1,Point2,Point3);
 //setNormal2(Point5,Point1);
 //glColor3f(1.0f,1.0f,1.0f);
 glNormal3fv(Pointa);
 glVertex3fv(Point1);
 glVertex3fv(Point2);
 glVertex3fv(Point3);
 glVertex3fv(Point4);
  glEnd();
  glPopMatrix();

//glTranslatef(50.0f,5.0f,0.0f);
glPushMatrix();
glBegin(GL_QUADS);
//setNormal(Point5,Point6,Point7);
//setNormal2(Point5,Point1);
//glColor3f(1.0f,0.5f,0.0f);
glNormal3fv(Pointb);
glVertex3fv(Point5);
glVertex3fv(Point8);
glVertex3fv(Point7);
glVertex3fv(Point6);
glEnd();
glPopMatrix();
glPushMatrix();
glBegin(GL_QUADS);
//setNormal(Point5,Point8,Point4);
//setNormal2(Point1,Point2);
//glColor3f(1.0f,0.0f,0.0f);
glNormal3fv(Pointc);
glVertex3fv(Point1);
glVertex3fv(Point5);
glVertex3fv(Point6);
glVertex3fv(Point2);
glEnd();
glPopMatrix();
glPushMatrix();
glBegin(GL_QUADS);
//setNormal(Point5,Point8,Point4);
//setNormal2(Point1,Point2);
//glColor3f(1.0f,0.0f,0.0f);
glNormal3fv(Pointd);
glVertex3fv(Point2);
glVertex3fv(Point6);
glVertex3fv(Point7);
glVertex3fv(Point3);
glEnd();
glPopMatrix();

 glPushMatrix();
 glBegin(GL_QUADS);
 //setNormal(Point7,Point6,Point2);
// setNormal2(Point2,Point1);
 //glColor3f(0.0f,0.0f,1.0f);
 glNormal3fv(Pointe);
 glVertex3fv(Point3);
 glVertex3fv(Point7);
 glVertex3fv(Point8);
 glVertex3fv(Point4);
  glEnd();
  glPopMatrix();
 glPushMatrix();
 glBegin(GL_QUADS);
 //setNormal(Point6,Point5,Point1);
 //setNormal2(Point1,Point4);
 //glColor3f(1.0f,0.0f,1.0f);
  glNormal3fv(Pointf);
 glVertex3fv(Point5);
 glVertex3fv(Point1);
 glVertex3fv(Point4);
 glVertex3fv(Point8);

glEnd();
glPopMatrix();
}
glEndList();
//glEnable(GL_DEPTH_TEST);

}
//glShadeModel(GL_SMOOTH);

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//清除颜色/深度缓冲
glPushMatrix();
glRotatef(angle,1,0.5,1);
glCallList(list);
glPopMatrix();

glPushMatrix();
    GLfloat moon_mat_ambient[]={0.0f,0.0f,0.5f,1.0f};
GLfloat moon_mat_diffuse[]={0.0f,0.0f,0.5f,1.0f};
GLfloat moon_mat_specular[]={0.0f,0.0f,1.0f,1.0f};
GLfloat moon_mat_emission[]={0.5f,0.0f,0.1f,0.0f};
GLfloat moon_mat_shininess=30.0f;
glMaterialfv(GL_FRONT,GL_AMBIENT,moon_mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,moon_mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,moon_mat_specular);
glMaterialfv(GL_FRONT,GL_EMISSION,moon_mat_emission);
glMaterialf(GL_FRONT,GL_SHININESS,moon_mat_shininess);
glPopMatrix();
 glutSwapBuffers();//使用双缓冲

}
void myIdle(void)
{
angle+=1.0f;
if(angle >=360.0f)
angle=0.0f;
myDisplay();
}
int main(int argc, _TCHAR* argv[])

{

glutInit(&argc,(char**)argv); //初始化glut,必须调用,复制黏贴这句话即可

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); //设置显示方式,RGB、单缓冲。当然还有GLUT_INDEX索引颜色 GLUT_DOUBLE双缓冲(Qt中看到过双缓冲)

glutInitWindowPosition(200,200); //位置

glutInitWindowSize(400,400);//窗口大小
//glutInitWindowSize(WIDTH,HEIGHT);

glutCreateWindow("第一个OpenGL程序"); //创建窗口,设置标题

glutDisplayFunc(&myDisplay); // 当绘制窗口时调用myDisplay,像Cocos2d-x刷帧Draw中的操作

glutIdleFunc(&myIdle);

glutMainLoop(); //消息循环

return 0;

}

这是代码,六个面只有一个能反射光线,求解惑

2个回答

法向量的方向是否设置正确?如果法向量方向与光源方向夹角小于90度,就会反射光照,如果大于90度,就不会反射光线。对于六面体,六个面的法向量都朝外,通过调整光源位置,才能看到反射光。

http://wenku.baidu.com/link?url=Ts-d_ZtY1i-MIdOdUamW8cKe5JzL7MTiTnfgFZY0H9c2G95J8A5cOmamrtJt1NRjUV3_Qn_vIPCvMsPZ8luDS35GbMCjaFIpCyWhkKRdgsG 这个教程里面有你想要的,关于天体运动那一块的。再看看光源的方向和平面的法向量的位置是否设置正确

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
opengl画一个立方体,里面有一个茶壶模型
opengl画一个立方体,里面有一个茶壶模型,可实现旋转效果
OpenGL画一个立方体
最直接的方法 将所有的36个先列出来,然后用glDrawArrays画出来 1、把所有的36个坐标点都列出来: float vertices[] = { //position //TexCoord -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0...
OpenGL立方体
直接画 #include &lt;windows.h&gt; #include &lt;GL/glut.h&gt; #include &lt;stdio.h&gt; #include &lt;string&gt; #include &lt;iostream&gt; // 绘制立方体 // 将立方体的八个顶点保存到一个数组里面 s...
【OpenGL】OpenGL颜色立方体
使用OpenGL绘制RGB颜色立方体 方向键旋转 鼠标点击/拖拽 C++代码#include <iostream> #include <GL/glut.h> using namespace std;#define M_PI 3.1415926535898GLfloat AngleX; GLfloat AngleY;static float c = M_PI / 180.0f;
OpenGL选择模式,选择一个立方体的面生成新的立方体
最近在学习OpenGL,想做一个程序来实现动态添加和立方体的功能,类似积木,当鼠标左键选择一个面时候,就在这个面上生成一个立方体,如果是右键则清除该立方体,但遇到了种种问题,第一个问题是,我所画的立方体的棱角不清除,多个立方体堆一块是总是一坨一坨的,后来我在每个边上画了一条黑线,虽然看起来比以前好了,但是那黑线时不时的就变成虚线或消失了(我进行了深度测试来消除隐藏面,不知道是不是这个引起的)。希望大神帮忙解答一下
一个OPENGL实例 旋转立方体
一个完整的OPENGL实例,附有源代码,一个旋转立方体.
用OpenGL绘制一个立方体
.cpp文件格式 用OpenGL绘制一个立方体
openGL编码实现一个立方体
代码清单:#include "GL/glut.h" void init(void) { glClearColor(0.0,0.0,0.0,0.0); glShadeModel(GL_FLAT); }void Reshape(int w, int h)//移动窗口或改变窗口尺寸 { glViewport(0, 0, w, h); glMatrixMode(GL_PROJ
OpenGL画的立方体为什么没有颜色呢?
rnimport java.nio.ByteBuffer;rnimport java.nio.FloatBuffer;rnimport java.nio.IntBuffer;rnrnimport javax.microedition.khronos.egl.EGLConfig;rnimport javax.microedition.khronos.opengles.GL10;rnrnimport android.opengl.GLUtils;rnimport android.opengl.GLSurfaceView.Renderer;rnimport android.util.Log;rnimport android.view.KeyEvent;rnrnpublic class GLRender implements Rendererrnrn int one = 0x10000;rn rn float step = 0.4f;rn boolean key;rn boolean light = true;rn rn float xrot = 0, yrot = 0; rn float xspeed, yspeed;rn float z = -2.0f;rn float radio = (float)320 / 480;rn rnrn FloatBuffer lightAmbient = FloatBuffer.wrap(new float[]0.5f,0.5f,0.5f,1.0f); rnrn FloatBuffer lightDiffuse = FloatBuffer.wrap(new float[]1.0f,1.0f,1.0f,1.0f);rn FloatBuffer lightPosition = FloatBuffer.wrap(new float[]0.0f,0.0f,6.0f,1.0f); rnrn int filter = 1;rnrn int [] texture;rn rn FloatBuffer vertices = FloatBuffer.wrap(new float[]rn -radio,-1,radio,rn radio,-1,radio,rn radio,1,radio,rn -radio,1,radio,rn rn -radio,-1,-radio,rn -radio,1,-radio,rn radio,1,-radio,rn radio,-1,-radio,rn rn -radio,1,-radio,rn -radio,1,radio,rn radio,1,radio,rn radio,1,-radio,rn rn -radio,-1,-radio,rn radio,-1,-radio,rn radio,-1,radio,rn -radio,-1,radio,rn rn radio,-1,-radio,rn radio,1,-radio,rn radio,1,radio,rn radio,-1,radio,rn rn -radio,-1,-radio,rn -radio,-1,radio,rn -radio,1,radio,rn -radio,1,-radio,rn rn );rn rn IntBuffer normals = IntBuffer.wrap(new int[]rn 0,0,one,rn 0,0,one,rn 0,0,one,rn 0,0,one,rn rn 0,0,-one,rn 0,0,-one,rn 0,0,-one,rn 0,0,-one,rn rn 0,one,0,rn 0,one,0,rn 0,one,0,rn 0,one,0,rn rn 0,-one,0,rn 0,-one,0,rn 0,-one,0,rn 0,-one,0,rn rn one,0,0,rn one,0,0,rn one,0,0,rn one,0,0,rn rn -one,0,0,rn -one,0,0,rn -one,0,0,rn -one,0,0,rn );rn rn IntBuffer texCoords = IntBuffer.wrap(new int[]rn one,0,0,0,0,one,one,one, rn 0,0,0,one,one,one,one,0,rn one,one,one,0,0,0,0,one,rn 0,one,one,one,one,0,0,0,rn 0,0,0,one,one,one,one,0,rn one,0,0,0,0,one,one,one,rn );rn rn ByteBuffer indices1 = ByteBuffer.wrap(new byte[]rn 0,1,3,2, rn );rn rn ByteBuffer indices2 = ByteBuffer.wrap(new byte[] rn 4,5,7,6, rn );rn rn ByteBuffer indices3 = ByteBuffer.wrap(new byte[] rn 8,9,11,10, rn );rn rn ByteBuffer indices4 = ByteBuffer.wrap(new byte[] rn 12,13,15,14,rn );rn ByteBuffer indices5 = ByteBuffer.wrap(new byte[] rn 16,17,19,18, rn );rn ByteBuffer indices6 = ByteBuffer.wrap(new byte[] rn 20,21,23,22,rn );rn rnrn public void onDrawFrame(GL10 gl)rn rn gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);rn gl.glLoadIdentity();rn rn gl.glEnable(GL10.GL_LIGHTING);rn rn rn gl.glTranslatef(0.0f, 0.0f, z);rn //gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f);rn gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f);rnrnrn //gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[filter]);rn rn gl.glNormalPointer(GL10.GL_FIXED, 0, normals);rn gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);rn gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, texCoords);rnrn gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);rn gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);rn gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);rn rnrn gl.glColor4f(0.5f, 0, 0, 1.0f);rn gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices1);rn gl.glColor4f(0.5f, 0.5f, 0, 1.0f);rn gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices2);rn gl.glColor4f(0.5f, 0.5f, 0.5f, 1.0f);rn gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices3);rn gl.glColor4f(0, 0.5f, 0, 1.0f);rn gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices4);rn gl.glColor4f(0, 0, 0.5f, 1.0f);rn gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices5);rn gl.glColor4f(0, 0.5f, 0.5f, 1.0f);rn gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 4, GL10.GL_UNSIGNED_BYTE, indices6);rnrn gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);rn gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);rn gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);rn rn if ( key )rn rn xrot+=xspeed; rn yrot+=yspeed; rn rn rn rnrn public void onSurfaceChanged(GL10 gl, int width, int height)rn rn Log.d("GLRender","onSurfaceChanged");rn rn Log.d("GLRENDER","width:"+String.valueOf(width));rn Log.d("GLRENDER","height:"+String.valueOf(height));rn float ratio = (float) width / height;rnrn gl.glViewport(0, 0, width, height);rnrn gl.glMatrixMode(GL10.GL_PROJECTION);rnrn gl.glLoadIdentity();rn rn //gl.glOrthof(-ratio * 1.5f,ratio * 1.5f,-1.5f,1.5f,1,10);rn rn gl.glFrustumf(-ratio, ratio, -1, 1, 1, 5);rnrn gl.glMatrixMode(GL10.GL_MODELVIEW); rnrn gl.glLoadIdentity(); rn rnrn public void onSurfaceCreated(GL10 gl, EGLConfig config)rn rn Log.d("GLRender","onSurfaceCreated");rn rn gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);rnrn gl.glClearColor(0, 0, 0, 0);rn rn gl.glEnable(GL10.GL_CULL_FACE);rnrn gl.glShadeModel(GL10.GL_SMOOTH);rnrn gl.glEnable(GL10.GL_DEPTH_TEST);rn rn rn IntBuffer textureBuffer = IntBuffer.allocate(3);rnrn gl.glGenTextures(3, textureBuffer);rn texture = textureBuffer.array();rn rnrn gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);rn gl.glTexParameterx(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_NEAREST); // ( NEW )rn gl.glTexParameterx(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_NEAREST); // ( NEW )rn GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, GLImage.mBitmap, 0);rn rnrn gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[1]);rn gl.glTexParameterx(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_LINEAR); // ( NEW )rn gl.glTexParameterx(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_LINEAR); // ( NEW )rn GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, GLImage.mBitmap, 0);rn rn gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[2]);rn gl.glTexParameterx(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MAG_FILTER,GL10.GL_NEAREST); // ( NEW )rn gl.glTexParameterx(GL10.GL_TEXTURE_2D,GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_LINEAR); // ( NEW )rn GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, GLImage.mBitmap, 0);rn rn gl.glClearDepthf(1.0f);rn gl.glDepthFunc(GL10.GL_LEQUAL);rn gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);rn //gl.glEnable(GL10.GL_TEXTURE_2D);rnrn gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_AMBIENT, lightAmbient);rnrn rn gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_DIFFUSE, lightDiffuse);rnrnrn gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_POSITION, lightPosition);rn rn gl.glEnable(GL10.GL_LIGHT1);rn rn rn rn rnrn
shader反射——立方体贴图
创建立方体贴图的工具代码: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; public class CubeMapTool : EditorWindow { private Cubemap cubeMap = null; [M...
opengl绘制立方体(二)
使用opengl绘制两个颜色不一样的立方体 #include &quot;stdio.h&quot; #include &amp;lt;GL/glew.h&amp;gt; #include &amp;lt;GLFW/glfw3.h&amp;gt; #include &amp;lt;soil/SOIL.h&amp;gt; #include &amp;lt;glm/glm.hpp&amp;gt; #include &amp;lt;glm/gtc/matrix_transform.hpp...
立方体 opengl bmp纹理
vc++ OpenGL 立方体贴图,讲bmp图像贴到立方体上。
OPENGL 立方体 平滑着色
OPENGL 绘制一个正方体,并进行光滑着色
OpenGL 作图例子 - 立方体
OpenGL 作图例子 - 立方体
Opengl做立方体
Opengl用面做立方体,在坐标系里面选择八个点作为立方体的八个顶点,一个面一个面的画
opengl 旋转的立方体
才刚学opengl不久,还有很多地方不清楚,所以正一边练习一边自学,还请各位高手讲解时能详细一点。rn我想写一个[color=#FF0000]基于MFC[/color]的旋转的立方体程序,加入了如下代码:rn[code=C/C++]rn glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Bufferrn glLoadIdentity(); // Reset The Current Modelview Matrixrn rn rn//NEW//////////////////NEW//////////////////NEW//////////////////NEW////////////////rnrn// glTranslatef(0.0f, 0.0f,0.0f); // Translate Into The Screen 7.0 Unitsrn glRotatef(m_rotate,0.0f,1.0f,0.0f); // Rotate The cube around the Y axisrn glRotatef(m_rotate,1.0f,1.0f,1.0f); rn glScalef(0.5,0.5,0.5); rn glBegin(GL_QUADS); // Draw a cube with quadsrn glColor3f(0.0f,1.0f,0.0f); // Color Bluern glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)rn glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)rn glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)rn glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)rn glColor3f(1.0f,0.5f,0.0f); // Color Orangern glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)rn glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)rn glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)rn glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)rn glColor3f(1.0f,0.0f,0.0f); // Color Redrn glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)rn glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)rn glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)rn glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)rn glColor3f(1.0f,1.0f,0.0f); // Color Yellowrn glVertex3f( 1.0f,-1.0f,-1.0f); // Top Right Of The Quad (Back)rn glVertex3f(-1.0f,-1.0f,-1.0f); // Top Left Of The Quad (Back)rn glVertex3f(-1.0f, 1.0f,-1.0f); // Bottom Left Of The Quad (Back)rn glVertex3f( 1.0f, 1.0f,-1.0f); // Bottom Right Of The Quad (Back)rn glColor3f(0.0f,0.0f,1.0f); // Color Bluern glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)rn glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)rn glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)rn glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)rn glColor3f(1.0f,0.0f,1.0f); // Color Violetrn glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)rn glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)rn glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)rn glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)rn glEnd(); // End drawing cube with quadsrn glFlush();rn m_rotate +=(float)0.9f;[/code]rn这代码应该是没问题的,但出现的结果好像是六个面独自旋转,而不是以一个整体旋转,所以问一下,还要在什么地方再加上什么代码或进行什么修改才能得到想要的结果。rn由于代码太多,所以其它代码就不粘上来了,解决后立即结帖。
OpenGL立方体六面贴图
在控件上显示一个OpenGL的正方体,六个面都有不同的贴图,并有三个滑块控制x,y,z三轴的旋转速度。
android OpenGL 立方体
android 立方体 六面贴图 壁纸 源代码
OpenGL手势转动立方体
一个手势控制立方体转动的工程,代码中有非常非常详细的解释以及相关知识点的讲解~
OpenGL旋转立方体课程设计
非常好的计算机图形论文,旋转立方体的动态实现。有完整源代码(c语言版)
opengl的立方体消隐算法
opengl的立方体消隐算法 可以实现选择 放大缩小
旋转立方体 opengl编写
很好看 自己可以修改参数 实现正立方体的效果 花费很长时间才编出来 呵呵 给大家分享
立方体旋转——OpenGL源代码
键盘控制的立方体旋转OpenGL源代码,欢迎大家参考
opengl旋转立方体
游戏设计基础,用opengl创建立方体旋转的源代码
openGL绘制立方体
用openGL绘制三维坐标系并绘制一个立方体。通过点、solid 、wire三种格式绘制!
OpenGL给立方体纹理贴图
下面是我的代码,实现的功能是绘制一个立方体,并给六个面贴上不同的纹理,(导入的六张bmp图片都是256*256大小的)。但是看到的效果是乱的,谁能帮我看看嘛?感激不尽~~rnrn在这里我用到了SOIL(Simple OpenGL Image Library)库:[url=http://nehe.gamedev.net/tutorial/lesson_06_texturing_update/47002/][/url]rnrn我的代码:rn[code=C/C++]#include rn#include rn#include rnrn#include "SOIL.h"rnrnGLuint texture[6];//6 textures for 6 faces of the cubernrnGLfloat xRot,yRot,zRot;//control cube's rotationrnrn//load the bitmap and convert it into a texturernint LoadGLTextures()rnrn int Status = 0;rn char *bmpFile[6] = "BmpFile/Ferrary.bmp","BmpFile/Honda.bmp","BmpFile/Hust.bmp",rn "BmpFile/Lamborghini.bmp","BmpFile/NeHe.bmp","BmpFile/Porsche.bmp";rn for (int i = 0;i < 6;++i)rn rn texture[i] = SOIL_load_OGL_texture(rn bmpFile[i],rn SOIL_LOAD_AUTO,rn SOIL_CREATE_NEW_ID,rn SOIL_FLAG_INVERT_Y);rn printf("texture[%d]: %d\n",i,texture[i]);rn if(texture[i] == 0)rn Status = 0;rn glBindTexture(GL_TEXTURE_2D,texture[i]);rn glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);rn glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);rn rnrn return Status;rnrnrnint init()rnrn glEnable(GL_TEXTURE_2D);rn if(!LoadGLTextures())rn return 0;rn glShadeModel(GL_SMOOTH);rn glClearColor(0.0f,0.0f,0.0f,0.5f);rn glClearDepth(1.0f);rn glEnable(GL_DEPTH_TEST);rn glDepthFunc(GL_LEQUAL);rn glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);rn return 1;rnrnrnvoid display()rnrn glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);rn glLoadIdentity();rn glTranslatef(0.0f,0.0f,-5.0f);rn glRotatef(xRot,1.0f,0.0f,0.0f);rn glRotatef(yRot,0.0f,1.0f,0.0f);rn glRotatef(zRot,0.0f,0.0f,1.0f);rnrn //glRotatef(45,1.0f,0.0f,0.0f);rn //glRotatef(45,0.0f,1.0f,0.0f);rnrn glBindTexture(GL_TEXTURE_2D,texture[0]);rnrn glBegin(GL_QUADS); rn // Front Face rn // Bottom Left Of The Texture and Quad rn glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); rn // Bottom Right Of The Texture and Quad rn glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); rn // Top Right Of The Texture and Quad rn glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); rn // Top Left Of The Texture and Quad rn glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); rn glEnd(); rnrn glBindTexture(GL_TEXTURE_2D,texture[1]);rn glBegin(GL_QUADS); rn // Back Face rn // Bottom Right Of The Texture and Quad rn glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); rn // Top Right Of The Texture and Quad rn glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); rn // Top Left Of The Texture and Quad rn glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); rn // Bottom Left Of The Texture and Quad rn glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); rn glEnd(); rnrn glBindTexture(GL_TEXTURE_2D,texture[2]);rn glBegin(GL_QUADS); rn // Top Face rn // Top Left Of The Texture and Quad rn glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); rn // Bottom Left Of The Texture and Quad rn glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); rn // Bottom Right Of The Texture and Quad rn glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); rn // Top Right Of The Texture and Quad rn glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); rn glEnd(); rnrn glBindTexture(GL_TEXTURE_2D,texture[3]);rn glBegin(GL_QUADS); rn // Bottom Face rn // Top Right Of The Texture and Quad rn glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); rn // Top Left Of The Texture and Quad rn glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); rn // Bottom Left Of The Texture and Quad rn glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); rn // Bottom Right Of The Texture and Quad rn glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); rn glEnd(); rnrn glBindTexture(GL_TEXTURE_2D,texture[4]);rn glBegin(GL_QUADS); rn // Right face rn // Bottom Right Of The Texture and Quad rn glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); rn // Top Right Of The Texture and Quad rn glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); rn // Top Left Of The Texture and Quad rn glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); rn // Bottom Left Of The Texture and Quad rn glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); rn glEnd(); rnrn glBindTexture(GL_TEXTURE_2D,texture[5]);rn glBegin(GL_QUADS); rn // Left Face rn // Bottom Left Of The Texture and Quad rn glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); rn // Bottom Right Of The Texture and Quad rn glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); rn // Top Right Of The Texture and Quad rn glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); rn // Top Left Of The Texture and Quad rn glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); rn glEnd(); rnrn /*xRot += 0.3f;rn yRot += 0.4f;rn zRot += 0.5f;*/rnrn glutSwapBuffers();rnrnrnvoid reshape(int w,int h)rnrn if (0 == h)rn h = 1;rn rn glViewport(0,0,(GLsizei)w,(GLsizei)h);rn glMatrixMode(GL_PROJECTION);rn glLoadIdentity();rn gluPerspective(60.0f,(GLfloat)w / (GLfloat)h,1,100);rn glMatrixMode(GL_MODELVIEW);rn glLoadIdentity();rnrnrnvoid keyboard(unsigned char key,int x,int y)rnrn switch(key)rn case 'x':rn xRot += 1.0f;rn glutPostRedisplay();rn break;rn case 'y':rn yRot += 1.0f;rn glutPostRedisplay();rn break;rn case 'z':rn zRot += 1.0f;rn glutPostRedisplay();rn break;rn default:rn break;rn rnrnrnint main(int argc,char** argv)rnrn glutInit(&argc,argv);rn glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);rn glutInitWindowSize(400,400);rn glutInitWindowPosition(100,100);rn glutCreateWindow("Texture Map");rn init();rn glutDisplayFunc(display);rn glutReshapeFunc(reshape);rn glutKeyboardFunc(keyboard);rn glutMainLoop();rn return 0;rn[/code]rnrn运行效果:rn[img=http://hi.csdn.net/attachment/201203/11/2712336_1331434203vVwA.jpg][/img]rnrn[img=http://hi.csdn.net/attachment/201203/11/2712336_1331434358OPyZ.jpg][/img]rnrn正常效果应该是这样子的:rn[img=http://hi.csdn.net/attachment/201203/11/2712336_1331434425901v.jpg][/img]rn可以看出,有的面上纹理可以看见,但是有的不能看见。所以就乱了~~rnrn这是为什么啊?rn求指导~~~~~
opengl绘制立方体
#include &quot;stdio.h&quot; #include &amp;lt;GL/glew.h&amp;gt; #include &amp;lt;GLFW/glfw3.h&amp;gt; #include &amp;lt;soil/SOIL.h&amp;gt; #include &amp;lt;glm/glm.hpp&amp;gt; #include &amp;lt;glm/gtc/matrix_transform.hpp&amp;gt; #include &amp;lt;glm/g..
openGl立方体纹理贴图
实现立方体各个面的贴图,对openGl的学习认识,openGl
OpenGL立方体旋转程序
自己编的立方体旋转的程序 VC6.0环境下 初学OpenGL VC图像编程的可能会有点点用吧
OpenGL 画彩色立方体
#include &amp;lt;windows.h&amp;gt;#include &amp;lt;gl/glut.h&amp;gt;#include &amp;lt;math.h&amp;gt;#define GL_PI 3.1415fstatic GLfloat xRot = 0.0f;static GLfloat yRot = 0.0f;void RenderScene(void){   float fz,bz;   glClear(G...
Opengl旋转立方体
关于利用Opengl制作旋转立方体的简单例子,分享学习一下
OpenGL 旋转的立方体
使用OpenGL编写的一个简单的立方体三维模型,可以实现立方体的选择操作
OpenGL 颜色立方体
OpenGL 颜色立方体
给立方体各个面贴上不同图片opengl
如题 本人是新手 求比较完整的代码rn不胜感激
openGL 旋转立方体
使用openGL 绘制的旋转立方体,很不错,学习好用啊
opengl分形海绵立方体
把原来的fractal sponge光照进行了重新设置,嗯,现在看起来酷多了
OpenGL绘制立方体
OpenGL绘制立方体,利用了简单的原理绘制了一个彩色的立方体。
彩色立方体OpenGL
#include "StdAfx.h" #include <GL/glut.h> GLfloat step = 0.0;//定义旋转角度 static GLfloat c1[] = { 0.0,0.0,1.0 }, c2[] = { 0.0,1.0,1.0 }, c3[] = { 1.0,1.0,1.0 }, c4[] = { 1.0,0.0,1.0 }, c5[] = { 1.0,0.0,0.0 }, c6[] = { 1.0,1.0,0.0 }, c7[] = { 0.0,1.0,0.0 }, c8[] = { 1.0,1.0,1.0 };//颜色立方体的颜色 void myinit(void); //初始化设置 void myReshape(GLsizei w, GLsizei h); //屏幕大小改变时响应函数 void display(void); //屏幕绘制响应函数 void controlIdleFunc(int button, int state, int x, int y); //鼠标点击响应函数 void DrawColorBox(void); //绘制立方体函数 void myinit(void)
OPENGL带纹理立方体
带纹理立方体 非常详细 有代码 可运行
OpenGL立方体示例
包含显示立方体框架,颜色立方体,旋转立方体等示例程序
相关热词 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池 c#5.0 安装程序 c# 分页算法 c# gmail 发邮件 c# 多层文件