我正在尝试在 NVIDIA Quadro 5000 上使用立体 3D 渲染绘制从 .obj 文件加载的基本网格。据我所知,我认为我的左眼和右眼截锥体和偏移量已相应设置,但我的主要问题是写入和清除 BACK_LEFT 和 BACK_RIGHT 缓冲区。似乎它完全错过了第一部分,只绘制了 BACK_RIGHT 缓冲区(渲染循环的第二部分)。如果我能得到一些关于如何在同一帧中写入/读取和清除这些缓冲区的指示,那就太好了。它是一个 Linux 应用程序,因此是 glXSwap(),不使用 glut 或 glew 并使用 glm 进行数学运算。这是我的绘图循环:
void GLDraw::Draw()
{
//initialise shader in frame
shader->UseShaderProgram();
//select back_left buffer
glDrawBuffer(GL_BACK_LEFT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//set projection and view for back_left
projectionMatrix = glm::frustum(-xCoord - frustumAssymmetry, xCoord - frustumAssymmetry, -yCoord, yCoord, 0.1f, 200.0f);
projectionMatrix *= glm::translate(glm::mat4(1.0f), glm::vec3(eyeOffset, 0.0f, 0.0f));
glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, value_ptr(projectionMatrix));
glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix[0][0]);
//set model matrix for rendering calls
modelMatrix = scale(mat4(1.0f), vec3(0.7, 0.7, 0.5f));
modelMatrix *= translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.0f));
modelMatrix *= rotate(mat4(1.0f), i+=0.04, vec3(0.0f, 1.0f, 0.0f));
glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]);
//draw VAO
glBindVertexArray(vikingVAO);
glDrawElements(GL_TRIANGLES, viking_elements.size() * sizeof(viking_elements[0]), GL_UNSIGNED_SHORT, 0);
glBindVertexArray(0);
//select back_right buffer <-- SEEMS TO ONLY RENDER FROM HERE, MISSING THE FIRST PART
glDrawBuffer(GL_BACK_RIGHT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//set projection and view for back_right
projectionMatrix = glm::frustum(-xCoord + frustumAssymmetry, xCoord + frustumAssymmetry, -yCoord, yCoord, 0.1f, 200.0f);
projectionMatrix *= glm::translate(glm::mat4(1.0f), glm::vec3(-eyeOffset, 0.0f, 0.0f));
glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, value_ptr(projectionMatrix));
glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix[0][0]);
//set model matrix for rendering calls
modelMatrix = scale(mat4(1.0f), vec3(0.7, 0.7, 0.5f));
modelMatrix *= translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.0f));
modelMatrix *= rotate(mat4(1.0f), i+=0.04, vec3(0.0f, 1.0f, 0.0f));
glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]);
//draw VAO
glBindVertexArray(vikingVAO);
glDrawElements(GL_TRIANGLES, viking_elements.size() * sizeof(viking_elements[0]), GL_UNSIGNED_SHORT, 0);
glBindVertexArray(0);
//clear shader
shader->ClearShaderProgram();
//swap buffers
glXSwapBuffers(display, win);
}
编辑:意识到如果我在正确的屏幕上运行我的应用程序,它会呈现 GL_BACK_RIGHT 缓冲区。在左侧屏幕上运行它会绘制 GL_BACK_LEFT。
有任何想法吗?可能是显示器设置?