我一直在試圖弄清楚這一點,但是我失敗了。我需要繪製一個立方體,然後在它周圍添加一個邊框。立方體工作正常,我得到了邊框繪製,但總是有一條額外的線條插入。我使用GL_ARRAY_BUFFER存儲數據並從GL_TRIANGLES(繪製立方體本身)切換到GL_LINES(繪製輪廓邊框)。緩衝區中的每個偏移量都有自己的一組頂點。OpenGL - 當我在立方體上繪製邊框時出現額外的線條
我對顯示功能(GLUT)代碼:
// cubeLen = number of cube's vertices in buffer
// sidesLen = number of side vertices in buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, cubeLen);
glDrawArrays(GL_LINES, cubeLen, cubeLen + sidesLen);
glutSwapBuffers();
我的代碼來設置緩衝器:
GLuint buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(points) + sizeof(colors)
+ sizeof(points2) + sizeof(colors2),
NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(points), points);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(points), sizeof(colors), colors);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(points) + sizeof(colors),
sizeof(points2), points2);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(points) + sizeof(colors) + sizeof(points2),
sizeof(colors2), colors2);
我使用12個三角形(各3個頂點)爲的每一側立方體和12條線(24個頂點)以覆蓋所有邊緣。立方體和邊緣位於屏幕中央(座標爲0,0,0)。即使我禁用在顯示功能中繪製立方體,額外的不需要的線(似乎從中央左側3D位置延伸到中央前方3D位置)也會進入。但是,當我沒有爲立方體設置頂點時,它會消失。任何想法,爲什麼這可能會發生?感謝任何和所有的幫助。
那麼'points'和'points2'包含什麼,'cubeLen'和'sidesLen'的值是什麼? –