1

我一直在慢慢学习如何使用 3d 图形和 C++,并且我一直在使用来自 Ed angels 交互式计算机图形的示例使用 RGBA。当试图将其更改为每侧都有颜色时,我在我的理解中撞到了墙,或者我没有看到明显的东西。我使用的创建 RGBA 立方体的原始示例的片段是这样的:

const int NumVertices = 36;

point4 points[NumVertices];
color4 colors[NumVertices];

//Vertices of a unit cube centered at origin, sides aligned with axes
point4 vertices[8] = {
    point4( -1.0, -1.0, 1.0, 1.0),
    point4( -1.0, 1.0, 1.0, 1.0),
    point4( 1.0, 1.0, 1.0, 1.0),
    point4( 1.0, -1.0, 1.0, 1.0),
    point4( -1.0, -1.0, -1.0, 1.0),
    point4( -1.0, 1.0, -1.0, 1.0),
    point4( 1.0, 1.0, -1.0, 1.0),
    point4( 1.0, -1.0, -1.0, 1.0)
};

//RGBA colors
color4 vertex_colors[8] = {
    color4( 0.0, 0.0, 0.0, 1.0),  //black
    color4( 1.0, 0.0, 0.0, 1.0),  //red
    color4( 1.0, 1.0, 0.0, 1.0),  //yellow
    color4( 0.0, 1.0, 0.0, 1.0),  //blue
    color4( 0.0, 0.0, 1.0, 1.0),  //green
    color4( 1.0, 0.0, 1.0, 1.0),  //magenta
    color4( 1.0, 1.0, 1.0, 1.0),  //white
    color4( 0.0, 1.0, 1.0, 1.0)  //cyan
};

//Array of rotation angles (in degrees) for each coordinate axis
enum { Xaxis = 0, Yaxis = 1, Zaxis = 2, NumAxes = 3 };
int Axis = Xaxis;
GLfloat Theta[NumAxes] = { 0.0, 0.0, 0.0};

GLuint theta; //The location of the "theta" shader uniform variable
//----------------------------------------------------------------------------

//quad generates two triangles for each face and assigns colors to the vertices

int Index = 0;
void
quad( int a, int b, int c, int d)
{
    colors[Index] = vertex_colors[a]; points[Index] = vertices[a]; Index++;
    colors[Index] = vertex_colors[b]; points[Index] = vertices[b]; Index++;
    colors[Index] = vertex_colors[c]; points[Index] = vertices[c]; Index++;
    colors[Index] = vertex_colors[a]; points[Index] = vertices[a]; Index++;
    colors[Index] = vertex_colors[c]; points[Index] = vertices[c]; Index++;
    colors[Index] = vertex_colors[d]; points[Index] = vertices[d]; Index++;
}

//----------------------------------------------------------------------------

//generate 12 triangles: 36 vertices and 36 colors
void
colorcube( void )
{
    quad( 1, 0, 3, 2);
    quad( 2, 3, 7, 6);
    quad( 3, 0, 4, 7);
    quad( 6, 5, 1, 2);
    quad( 4, 5, 6, 7);
    quad( 5, 4, 0, 1);
}

现在,我认为我所要做的就是将quad中vertex_colors 的所有参数更改使它们都像这样:

int Index = 0;
void
quad( int a, int b, int c, int d)
{
    colors[Index] = vertex_colors[a]; points[Index] = vertices[a]; Index++;
    colors[Index] = vertex_colors[a]; points[Index] = vertices[b]; Index++;
    colors[Index] = vertex_colors[a]; points[Index] = vertices[c]; Index++;
    colors[Index] = vertex_colors[a]; points[Index] = vertices[a]; Index++;
    colors[Index] = vertex_colors[a]; points[Index] = vertices[c]; Index++;
    colors[Index] = vertex_colors[a]; points[Index] = vertices[d]; Index++;
}

但是当我这样做时,所有生成的都是一个空白的白色窗口。所以我感到困惑的是,不仅仅是更改参数,还是我需要使用其他东西才能使其正常工作?

4

0 回答 0