所以我組建了一個高度貼圖渲染,將完成大部分的工作詮釋他的頂點着色器,但首先我當然生成網格渲染,此刻我正在玩圍繞着openGL和C++的上限來看看我可以渲染多少密度的網格(所以我稍後在LoD網格劃分方面有了一些進展)C++ OpenGL的大網眼缺少三角形
ANYWAY!切入問題;
在我測試了一個32位,64位和128位的meshResolution之後,我注意到了這個問題我遇到了運行時崩潰,我使用自制類「indexFace」來阻止它們,它包含6個索引以降低數組長度,問題在於128分辨率只有網格的第三個實際上顯示,我在想,如果有OpenGL的能有多少指標呈現或持有使用1套BufferObjects,或者如果它的一個問題,我處理事情的C++方面的限制。
我通過以下生成網格:
void HeightMapMesh::GenerateMesh(GLfloat meshScale, GLushort meshResolution)
{
GLushort vertexCount = (meshResolution + 1) * (meshResolution + 1);
Vertex_Texture* vertexData = new Vertex_Texture[vertexCount];
GLushort indexCount = (meshResolution * meshResolution) * 6;
//indexFace holds 6 GLushort's in an attempt to overcome the array size limit
indexFace* indexData = new indexFace[meshResolution * meshResolution];
GLfloat scalar = meshScale/((GLfloat)meshResolution);
GLfloat posX = 0;
GLfloat posY = 0;
for (int x = 0; x <= meshResolution; x++)
{
posX = ((GLfloat)x) * scalar;
for (int y = 0; y <= meshResolution; y++)
{
posY = ((GLfloat)y) * scalar;
vertexData[y + (x * (meshResolution + 1))] = Vertex_Texture(posX, posY, 0.0f, x, y);
}
}
GLint indexPosition;
GLint TL, TR, BL, BR;
for (int x = 0; x < meshResolution; x++)
{
for (int y = 0; y < meshResolution; y++)
{
indexPosition = (y + (x * (meshResolution)));
BL = y + (x * (meshResolution + 1));
TL = y + 1 + (x * (meshResolution + 1));
BR = y + ((x + 1) * (meshResolution + 1));
TR = y + 1 + ((x + 1) * (meshResolution + 1));
indexData[indexPosition] = indexFace(
BL, TR, TL,
BL, BR, TR
);
}
}
mesh.Fill(vertexData, vertexCount, (void *)indexData, indexCount, GL_STATIC_DRAW, GL_STATIC_DRAW);
delete [] vertexData;
delete [] indexData;
}
//This is for mesh.Fill()
void Fill(T* vertData, GLushort vertCount, void* indData, GLushort indCount, GLenum vertUsage, GLenum indUsage)
{
indexCount = indCount;
vertexCount = vertCount;
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjectID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObjectID);
glBufferData(GL_ARRAY_BUFFER, sizeof(T) * vertexCount, vertData, vertUsage);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indexCount, indData, indUsage);
}
小幅回調,而USHORT和uint是我的問題,那是因爲我使用USHORT來繞過索引計數,頂點還是很好的USHORT範圍內,因此是安全的,以保持指數爲ushorts,感謝雖然由於某種原因,我很困惑短褲的限制與整數和長整數。 GL_TRIANGLE_STRIP我會仰視它的順序總是讓我感到困惑,當你有多個行,但研究熟能生巧我猜想,再次感謝。 – 2014-10-17 13:41:36