這裏是代碼爲main.cpp和shaders的粘貼容器。它使用devil,glload和glfw。運行在Windows和Linux上。任何名爲pic.png的png都會加載。opengl中緩衝區數據的問題=只在我緩衝比需要更多字節時畫出
我以相當正常的方式緩衝我的數據。只是一個簡單的三角。
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
//vX vY vZ vW nX nY nZ U V
float bufferDataThree[9*3] = {
-1.0f, -1.0f, 0.0f,1.0f, 0.0f,1.0f,0.0f, 0.0f,0.0f,
1.0f, -1.0f, 0.0f,1.0f, 0.0f,1.0f,0.0f, 0.0f,1.0f,
1.0f, 1.0f, 0.0f,1.0f, 0.0f,1.0f,0.0f, 1.0f,1.0f};
//TOTAL 4 + 3 + 2 = 9;
glBufferData(GL_ARRAY_BUFFER, (9*3)*4, bufferDataThree, GL_STATIC_DRAW); //Doesnt Work
//glBufferData(GL_ARRAY_BUFFER, (10*3)*4, bufferDataThree, GL_STATIC_DRAW); //Works
有9 * 3 = 27個浮標。所以108字節。如果我緩衝108個字節,它會搞砸紋理座標。如果我緩衝116個字節,(2浮動更多)它渲染罰款。
我的顯示方法。
void display()
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,tbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, (4 + 3 + 2)*sizeof(float), 0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, (4 + 3 + 2)*sizeof(float),(void*) (4*sizeof(float)));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, (4 + 3 + 2)*sizeof(float),(void*) ((4+3)*sizeof(float)));
glDrawArrays(GL_TRIANGLES,0,3);
glDisableVertexAttribArray(0);
glUseProgram(0);
glfwSwapBuffers();
}
這是怎麼發生的?
爲什麼這是低票?我的問題缺乏解決所需的細節嗎?我不這麼認爲... – Andrew