OPEN GL颜色映射

时间:2013-03-02 09:48:05

标签: opengl colors

我有以下工作代码(我从一个例子中得到了它)。

它生成一个立方体,其边的颜色不同。 有什么方法可以根据它们的位置或某些模拟为侧面的每个(一组)像素分配颜色。有些东西就像立方体表面上的标量场的颜色图......? 有人可以给我一个在任意表面上这样做的例子吗?

#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/freeglut_ext.h>

void init(void)
{
glClearColor(0,0,0,0);
glShadeModel(GL_FLAT);
}

void DrawCube(void)
{
glLoadIdentity();
gluLookAt(0, 10, 10, 0, 1, 0, 0, -2, -35.7);
glBegin(GL_QUADS);

//face in xy plane
glColor3f(0.12, 0.91, 0.02);//this the color with which complete cube is drawn. 
glVertex3f(0,0 ,0 );
glVertex3f(5, 0, 0);
glVertex3f(5, 5, 0);
glVertex3f(0, 5, 0);

//face in yz plane
glColor3f(1, 0.23, 0.56);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, 5);
glVertex3f(0, 5, 0);
glVertex3f(0, 5, 5);

//face in zx plance
glColor3f(0.45, .81, 1);
glVertex3f(0, 0, 0  );
glVertex3f(0, 0, 5);
glVertex3f(5, 0, 5);
glVertex3f(5, 0, 0);

//|| to xy plane.
glColor3f(0.23, 0.78,0.13);
glVertex3f(0, 0, 5);
glVertex3f(5, 0, 5);
glVertex3f(5, 5, 5);
glVertex3f(0, 5, 5);

//|| to yz plane
glColor3f(0.73, 0.58, 0.58);
glVertex3f(0,0 ,5 );
glVertex3f(5, 0, 5);
glVertex3f(5, 5, 5);
glVertex3f(0, 5, 5);

//|| to zx plane
glVertex3f(0.58, 0, 0.82);
glVertex3f(0, 5, 0  );
glVertex3f(0, 5, 5);
glVertex3f(5, 5, 5);
glVertex3f(5, 5, 0);
glEnd();
glFlush();
}


void reshape(int w,int h){

glViewport(0, 0, (GLsizei)w, (GLsizei)h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1, 1, -1, 1, 1.5, 20);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char** argv){

glutInit(&argc, argv);//we initizlilze the glut. functions
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(800, 800);
glutCreateWindow(argv[1]);
init();
glutDisplayFunc(DrawCube);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

1 个答案:

答案 0 :(得分:1)

观看此视频,您也可以下载该代码。 http://www.videotutorialsrock.com/opengl_tutorial/cube/home.php

在本视频中,您可以了解立方体表面上的纹理贴图,这是您需要的。

相关问题