在我的 OpenGL 程序中,我想渲染内存中的所有内容。我不想将数据呈现到窗口/屏幕。所以我创建了一个帧缓冲区。接下来我要做的是将 3d 模型渲染到该帧缓冲区。
我已经下载了 Assimp 库来处理模型的加载。我只是不确定如何使用它。看起来它希望您将所有内容直接绘制到窗口?
我现在要做的就是将该模型加载并绘制到我的帧缓冲区中。基本上就这些了。</p>
关于如何轻松做到这一点的任何提示/建议?也欢迎为另一个库(可能更适合我的需要)提供提示。
我的代码,我想在其中绘制到我的帧缓冲区:
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); // Bind our frame buffer for rendering
glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); // Push our glEnable and glViewport states
glViewport(0, 0, window_width, window_height); // Set the size of the frame buffer view port
glClearColor (0.0f, 1.0f, 0.0f, 1.0f); // Set the clear colour
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the depth and colour buffers
glLoadIdentity(); // Reset the modelview matrix
// RENDER 3D MODEL HERE....
// TEAPOT AS EXAMPLE
glTranslatef(0.0f, 0.0f, -5.0f); // Translate back 5 units
glRotatef(rotation_degree, 1.0f, 1.0f, 0.0f); // Rotate according to our rotation_degree value
//glFrontFace(GL_CW);
glutSolidTeapot(1.0f); // Render a teapot
//glFrontFace(GL_CCW);
int r = glGetError();
int s = glCheckFramebufferStatus(GL_FRAMEBUFFER);
glPopAttrib(); // Restore our glEnable and glViewport states
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // Unbind our texture
最佳答案
assimp 库只是一个加载器;它不关心你是绘制到屏幕外的帧缓冲区还是窗口的后备缓冲区。
尝试检查 glGetError 和 glCheckFramebufferStatus 的返回码。
关于c++ - 将模型渲染到帧缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8956236/