opengl — c ++ меняет куб rgba так, чтобы по одному цвету с каждой стороны

Я медленно изучал, как работать с 3D-графикой и C ++, и я работал с RGBA, используя пример интерактивной компьютерной графики Ed angels. Когда я пытаюсь изменить его, чтобы он имел цвет с каждой стороны, я ударился о стену в моем понимании, или я не вижу ничего очевидного. Фрагмент исходного примера, который я использовал для создания куба 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);
}

Теперь все, что я думал, что должен был сделать из того, что я прочитал, это просто изменить все параметры 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++;
}

Но когда я сделал это, все, что было сгенерировано, было пустым белым окном. Итак, что меня смущает, так это нечто большее, чем просто изменение параметров, или мне нужно работать с чем-то другим, чтобы это работало?

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …