디스플레이에 렌더링 할 수있는 3D 장면이 있습니다. 그러나, 그것을 표시하는 것 외에도 렌더링 된 장면을 100 프레임마다 한 번씩 이미지 (JPG 또는 PNG 이미지)로 내보낼 수 있습니다. 아마 어딘가에 파일로 저장할 수 있습니다. 기계. OpenGL : 렌더링뿐만 아니라 프레임 버퍼로 렌더링
나는 다음과 같은 시도 :do{
glBindFramebuffer(GL_FRAMEBUFFER, framebuffername);
drawScene();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
drawScene();
}while(glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS
나는 프레임 버퍼가 제대로 개체 사용하고있는 경우 잘 모르겠어요,하지만 내 목표를 부여 진행 방법에 관한 제안을 찾고 있었다. 위의 코드에서 필자는 정의한 FBO에 프레임 버퍼를 바인딩하고 장면을 그립니다 (올바른 경우 FBO로 그려야합니까?). 그런 다음 일반 디스플레이로 다시 그립니다. 그러나이 코드는 디스플레이가 항상 내 장면과 내가 원하지 않는 빈 (검정색) 장면간에 전환되도록합니다. 항상 모든 검정색을 사용하지 않고 멋진 장면 3D 장면을 표시 장치에 표시하려고합니다.
// Swap buffers
glfwSwapBuffers(window);
glfwPollEvents();
당신이 없을 때 당신이 전화를하면 어떻게 어떻게 생각하십니까 :
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glBindTexture(GL_TEXTURE_2D, 0);
//glBindFramebuffer(GL_FRAMEBUFFER, framebuffername);
// Use our shader
glUseProgram(programID);
// Compute the MVP matrix from keyboard and mouse input
computeMatricesFromInputs();
glm::mat4 ProjectionMatrix = getProjectionMatrix();
glm::mat4 ViewMatrix = getViewMatrix();
glm::mat4 ModelMatrix = glm::mat4(1.0); //DEFINE MODEL TO WORLD TRANSFORMATION
//glm::mat4 ModelMatrix = glm::scale(2.0,2.0,2.0);
glm::mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
// Send our transformation to the currently bound shader,
// in the "MVP" uniform
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
glUniform1f(FARPLANE, farplane_control);
glUniform1f(NEARPLANE, nearplane_control);
glUniformMatrix4fv(ModelMatrixID, 1, GL_FALSE, &ModelMatrix[0][0]);
glUniformMatrix4fv(ViewMatrixID, 1, GL_FALSE, &ViewMatrix[0][0]);
glm::vec3 lightPos = glm::vec3(0, 0, 4);
glUniform3f(LightID, lightPos.x, lightPos.y, lightPos.z);
// 1st attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// 2nd attribute buffer : normals
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
glVertexAttribPointer(
1, // attribute
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// Draw the triangle !
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices.size());
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glReadBuffer(GL_FRONT);
// Swap buffers
glfwSwapBuffers(window);
glfwPollEvents();
}
[mcve]에서 편집하십시오. – genpfault