我尝试让我的渲染函数工作。我正在使用顶点数组。这是我的顶点结构:
struct Vertex
{
float x, y, z; // The x, y and z floating point values
float u, v; // The u - v texture coordinates
float padding[3]; // needs to be multiple of 32
};
这是我的渲染代码:
// Render the mesh
void WLD::render(GLuint* textures, long curRegion, CFrustum cfrustum)
{
int num = 0;
// Set up my indices
GLuint indicies[3];
// Cycle through the PVS
while(num < regions[curRegion].visibility.size())
{
int i = regions[curRegion].visibility[num];
if(!regions[i].dead && regions[i].meshptr != NULL)
{
if(cfrustum.BoxInFrustum(regions[i].meshptr->min[0], regions[i].meshptr->min[2], regions[i].meshptr->min[1], regions[i].meshptr->max[0], regions[i].meshptr->max[2], regions[i].meshptr->max[1]))
{
// Cycle through every polygon in the mesh and render it
for(int j = 0; j < regions[i].meshptr->polygonCount; j++)
{
// Assign the index for the polygon to the index in the huge vertex array
indicies[0] = regions[i].meshptr->poly[j].vertIndex[0];
indicies[1] = regions[i].meshptr->poly[j].vertIndex[1];
indicies[2] = regions[i].meshptr->poly[j].vertIndex[2];
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &verticies[0].x);
// Texture index
int tex = regions[i].meshptr->poly[j].tex;
// Need to bind this to the polygon I render.
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &verticies[0].u);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, indicies);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
}
num++;
}
}
其中一个参数GLuint * textures包含所有加载的纹理。因此,行int tex = regions [i] .meshptr->poly [j] .tex返回的值是此特定多边形的纹理在纹理中的索引。当我渲染它时,如何将其绑定到每个多边形?如果您有任何问题,请告诉我。
我知道我需要使用glClientActiveTexture(),但是一方面,它说未定义,我找不到正确的头文件;另一方面,我不知道如何使用它。我找不到任何好的例子。那么,如果多边形引用纹理索引4,我该如何使用glClientActiveTexture将其绑定到多边形并进行渲染。