Opengl es GL_三角形_条-为单个绘制调用生成网格(退化三角形)

Opengl es GL_三角形_条-为单个绘制调用生成网格(退化三角形),opengl-es,indexing,vertex,Opengl Es,Indexing,Vertex,我需要创建一个网格,为GL_三角形_条渲染做好准备 我的网格只是一个: 位置自解释 调整x、y尺寸 分辨率x,y中每个顶点之间的间距 以下是用于创建顶点/索引并返回它们的方法: int iCols = vSize.x / vResolution.x; int iRows = vSize.y / vResolution.y; // Create Vertices for(int y = 0; y < iRows; y ++) { for(int x = 0; x < iCo

我需要创建一个网格,为GL_三角形_条渲染做好准备

我的网格只是一个:

位置自解释 调整x、y尺寸 分辨率x,y中每个顶点之间的间距 以下是用于创建顶点/索引并返回它们的方法:

int iCols = vSize.x / vResolution.x;
int iRows = vSize.y / vResolution.y;


// Create Vertices
for(int y = 0; y < iRows; y ++)
{
    for(int x = 0; x < iCols; x ++)
    {
        float startu  = (float)x / (float)vSize.x;
        float startv  = (float)y / (float)vSize.y; 


        tControlVertex.Color    = vColor;
        tControlVertex.Position = CVector3(x * vResolution.x,y * vResolution.y,0);
        tControlVertex.TexCoord = CVector2(startu, startv - 1.0 );

        vMeshVertices.push_back(tControlVertex);   
    }
}


// Create Indices
rIndices.clear();

for (int r = 0; r < iRows - 1; r++)
{
    rIndices.push_back(r*iCols);

    for (int c = 0; c < iCols; c++)
    {
        rIndices.push_back(r*iCols+c);
        rIndices.push_back((r+1)*iCols+c);
    }
    rIndices.push_back((r + 1) * iCols + (iCols - 1));
} 
为了形象化这一点,先举几个例子

1个尺寸512x512分辨率64x64,所以它应该由8 x 8个四边形组成,但我只有7x7个

2个尺寸512x512分辨率128x128,所以它应该由4 x 4个四边形组成,但我只得到3x3

3个尺寸128x128分辨率8x8,因此它应该由16 x 16四边形组成,但我只得到15x15


如你所见,我遗漏了最后一行和最后一列。我哪里出错了?

简短回答:如果for循环测试这么简单,那么就做它,但事实并非如此。看看当我使用时会发生什么我很确定你正确地计算了顶点位置你可以通过使用GL_点进行渲染来测试这一点,但是你的索引计算似乎是可疑的。我相信我在编辑答案时添加的代码将生成正确的索引,假设您分别渲染每个tristrip,即在glDrawElements CallThank Radical7中通过2*iRows+1,但我需要通过粘贴三角形/使用退化三角形通过一次绘制调用来处理此网格。我已经解决了这个问题,请参阅:[GameDev StackExchange][1][1]:
for ( int r = 0; r <= iRows; ++r ) {
    for ( int c = 0; c <= iCols; ++c ) {
        rIndices.push_back( c + r + r*iCols );
        rIndices.push_back( c + r + (r+1)*iCols + 1 );
    }
}