У меня есть базовая программа, которая рисует куб из 48 тетраэдров.Точнее, он использует 27 вершин и индексный буфер для рисования этих тетраэдров.Я хотел бы применить текстуру ко всем тетраэдрам, но все учебники, которые я нашел о текстурах, не рендерится с использованием индексов, и каждая вершина в моей программе используется в 16 других тетраэдрах, поэтому я даже не могу понять, как ориентироватьсятекстуры.Сама программа слишком длинная и слишком грязная, чтобы я мог ее опубликовать, но если кто-то может сказать мне, возможно ли поместить текстуры на индексированные примитивы или нет, а также дать мне ссылку на учебник, я был бы признателен.
РЕДАКТИРОВАТЬ: Код ici:
void setVertices(FLOAT cubeYOffset, FLOAT cubeXOffset, FLOAT cubeZOffset, int tetraRender[]){
CUSTOMVERTEX vertices[] = {
{ cubeXOffset+1.0f, cubeYOffset+0.0f, cubeZOffset-1.0f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, },//Center top = 0
{ cubeXOffset+0.0f, cubeYOffset+0.0f, cubeZOffset-1.0f, -0.5f, 0.5f, 0.0f, -1.0f, 1.0f, },
{ cubeXOffset+0.0f, cubeYOffset+0.0f, cubeZOffset+0.0f, -0.5f, 0.5f, 0.5f, -1.0f, 1.0f, },
{ cubeXOffset+1.0f, cubeYOffset+0.0f, cubeZOffset+0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 1.0f, },
{ cubeXOffset+2.0f, cubeYOffset+0.0f, cubeZOffset+0.0f, 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, },
{ cubeXOffset+2.0f, cubeYOffset+0.0f, cubeZOffset-1.0f, 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, },
{ cubeXOffset+2.0f, cubeYOffset+0.0f, cubeZOffset-2.0f, 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, },
{ cubeXOffset+1.0f, cubeYOffset+0.0f, cubeZOffset-2.0f, 0.0f, 0.5f, -0.5f, 0.0f, 1.0f, },
{ cubeXOffset+0.0f, cubeYOffset+0.0f, cubeZOffset-2.0f, -0.5f, 0.5f, -0.5f, -1.0f, 0.0f, },
{ cubeXOffset+1.0f, cubeYOffset-1.0f, cubeZOffset-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, },//Center middle = 9
{ cubeXOffset+0.0f, cubeYOffset-1.0f, cubeZOffset-1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, },
{ cubeXOffset+0.0f, cubeYOffset-1.0f, cubeZOffset+0.0f, -0.5f, 0.0f, 0.5f, -1.0f, 0.0f, },
{ cubeXOffset+1.0f, cubeYOffset-1.0f, cubeZOffset+0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, },
{ cubeXOffset+2.0f, cubeYOffset-1.0f, cubeZOffset+0.0f, 0.5f, 0.0f, 0.5f, 1.0f, 0.0f, },
{ cubeXOffset+2.0f, cubeYOffset-1.0f, cubeZOffset-1.0f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, },
{ cubeXOffset+2.0f, cubeYOffset-1.0f, cubeZOffset-2.0f, 0.5f, 0.0f, -0.5f, 1.0f, 0.0f, },
{ cubeXOffset+1.0f, cubeYOffset-1.0f, cubeZOffset-2.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, },
{ cubeXOffset+0.0f, cubeYOffset-1.0f, cubeZOffset-2.0f, -0.5f, 0.0f, -0.5f, -1.0f, 0.0f, },
{ cubeXOffset+1.0f, cubeYOffset-2.0f, cubeZOffset-1.0f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, },//Center bottom = 18
{ cubeXOffset+0.0f, cubeYOffset-2.0f, cubeZOffset-1.0f, -0.5f, -0.5f, 0.0f, -1.0f, -1.0f, },
{ cubeXOffset+0.0f, cubeYOffset-2.0f, cubeZOffset+0.0f, -0.5f, -0.5f, 0.5f, -1.0f, -1.0f, },
{ cubeXOffset+1.0f, cubeYOffset-2.0f, cubeZOffset+0.0f, 0.0f, -0.5f, 0.5f, 0.0f, -1.0f, },
{ cubeXOffset+2.0f, cubeYOffset-2.0f, cubeZOffset+0.0f, 0.5f, -0.5f, 0.5f, 1.0f, -1.0f, },
{ cubeXOffset+2.0f, cubeYOffset-2.0f, cubeZOffset-1.0f, 0.5f, -0.5f, 0.0f, 1.0f, -1.0f, },
{ cubeXOffset+2.0f, cubeYOffset-2.0f, cubeZOffset-2.0f, 0.5f, -0.5f, -0.5f, 1.0f, -1.0f, },
{ cubeXOffset+1.0f, cubeYOffset-2.0f, cubeZOffset-2.0f, 0.0f, -0.5f, -0.5f, 0.0f, -1.0f, },
{ cubeXOffset+0.0f, cubeYOffset-2.0f, cubeZOffset-2.0f, -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, },//26(actually 27th)
};
d3ddev->CreateVertexBuffer(27*sizeof(CUSTOMVERTEX),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&v_buffer,
NULL);
VOID* pVoid;
v_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));
v_buffer->Unlock();
short tetra[48][12] = {
//tetra 1
0, 1, 2,
0, 1, 11,
0, 2, 11,
1, 2, 11,
//tetro 2
0, 2, 3,
0, 2, 11,
0 , 3, 11,
2, 3, 11,
//tetro 3
0, 3, 4,
0, 3, 13,
0, 4, 13,
3, 4, 13,
//tetro 4
0, 4, 5,
0, 4, 13,
0, 5, 13,
4, 5, 13,
//tetro 5
0, 5, 6,
0, 5, 15,
0, 6, 15,
5, 6, 15,
//tetro 6
0, 6, 7,
0, 6, 15,
0, 7, 15,
6, 7, 15,
//tetro 7
0, 7, 8,
0, 7, 17,
0, 8, 17,
7, 8, 17,
//tetro 8
0, 8, 1,
0, 8, 17,
0, 1, 17,
8, 1, 17,
//tetro 9
0, 1, 11,
0, 1, 10,
0, 10, 11,
1, 10, 11,
//tetro 10
0, 3, 11,
0, 3, 12,
0, 11, 12,
3, 11, 12,
//tetro 11
0, 3, 13,
0, 3, 12,
0, 12, 13,
3, 12, 13,
//tetro 12
0, 5, 13,
0, 5, 14,
0, 13, 14,
5, 13, 14,
//tetro 13
0, 5, 15,
0, 5, 14,
0, 14, 15,
5, 14, 15,
//tetro 14
0, 7, 15,
0, 7, 16,
0, 15, 16,
7, 15, 16,
//tetro 15
0, 7, 17,
0, 7, 16,
0, 16, 17,
7, 16, 17,
//tetro 16
0, 1, 17,
0, 1, 10,
0, 17, 10,
1, 17, 10,
//tetro 17
0, 10, 11,
0, 9, 10,
0, 9, 11,
9, 10, 11,
//tetro 18
0, 11, 12,
0, 9, 11,
0, 9, 12,
9, 11, 12,
//tetro 19
0, 12, 13,
0, 9, 12,
0, 9, 13,
9, 12, 13,
//tetro 20
0, 13, 14,
0, 9, 13,
0, 9, 14,
9, 13, 14,
//tetro 21
0, 14, 15,
0, 9, 14,
0, 9, 15,
9, 14, 15,
//tetro 22
0, 15, 16,
0, 9, 15,
0, 9, 16,
9, 15, 16,
//tetro 23
0, 16, 17,
0, 9, 16,
0, 9, 17,
9, 16, 17,
//tetro 24
0, 17, 10,
0, 9, 17,
0, 9, 10,
9, 17, 10,
//tetro 17
9, 10, 11,
9, 18, 10,
9, 18, 11,
18, 10, 11,
//tetro 18
9, 11, 12,
9, 18, 11,
9, 18, 12,
18, 11, 12,
//tetro 19
9, 12, 13,
9, 18, 12,
9, 18, 13,
18, 12, 13,
//tetro 20
9, 13, 14,
9, 18, 13,
9, 18, 14,
18, 13, 14,
//tetro 21
9, 14, 15,
9, 18, 14,
9, 18, 15,
18, 14, 15,
//tetro 22
9, 15, 16,
9, 18, 15,
9, 18, 16,
18, 15, 16,
//tetro 23
9, 16, 17,
9, 18, 16,
9, 18, 17,
18, 16, 17,
//tetro 24
9, 17, 10,
9, 18, 17,
9, 18, 10,
18, 17, 10,
//tetro 9
18, 19, 11,
18, 19, 10,
18, 10, 11,
19, 10, 11,
//tetro 10
18, 21, 11,
18, 21, 12,
18, 11, 12,
21, 11, 12,
//tetro 11
18, 21, 13,
18, 21, 12,
18, 12, 13,
21, 12, 13,
//tetro 12
18, 23, 13,
18, 23, 14,
18, 13, 14,
23, 13, 14,
//tetro 13
18, 23, 15,
18, 23, 14,
18, 14, 15,
23, 14, 15,
//tetro 14
18, 25, 15,
18, 25, 16,
18, 15, 16,
25, 15, 16,
//tetro 15
18, 25, 17,
18, 25, 16,
18, 16, 17,
25, 16, 17,
//tetro 16
18, 19, 17,
18, 19, 10,
18, 17, 10,
19, 17, 10,
//tetro 19
18, 19, 20,
18, 19, 11,
18, 20, 11,
19, 20, 11,
//tetro 20
18, 20, 21,
18, 20, 11,
18 , 21, 11,
20, 21, 11,
//tetro 21
18, 21, 22,
18, 21, 13,
18, 22, 13,
21, 22, 13,
//tetro 22
18, 22, 23,
18, 22, 13,
18, 23, 13,
22, 23, 13,
//tetro 23
18, 23, 24,
18, 23, 15,
18, 24, 15,
23, 24, 15,
//tetro 24
18, 24, 25,
18, 24, 15,
18, 25, 15,
24, 25, 15,
//tetro 25
18, 25, 26,
18, 25, 17,
18, 26, 17,
25, 26, 17,
//tetro 26
18, 26, 19,
18, 26, 17,
18, 19, 17,
26, 19, 17,
};
short indices [576];
int i = 0;
int i2 = 0;
ind = 0;
int ic;
for(i; i < 48; i++){
if (tetraRender[i] == 1){
for(i2; i2 < 12; i2++){
if((ind == 0)&&(i2 == 0)){
ic = 0;
}else{
ic = ind*12+i2;
}
indices[ic] = tetra[i][i2];
}
i2 = 0;
ind++;
}
}
if (ind > 0) {
d3ddev->CreateIndexBuffer(12*ind*sizeof(short),
0,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&i_buffer,
NULL);
i_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, indices, 12*ind*2);
i_buffer->Unlock();
}
}
Хорошо, так что это объявление вершин и индексов, просто чтобы дать вам представление.Это очень грязно, поэтому я извиняюсь, и если вы не видите, что он делает, это объявляет спиралевидный набор вершин, за которым следует объявление всех индексов тетраэдров.затем он использует массив int в функции from для рисования только указанных тетраэдров.
И да, я использую 3D-освещение, хотя у меня нет ни малейшего почему.