我正在尝试创建一个FBO来渲染到lwjgl中的纹理。该代码在Linux和Windows上运行良好,但在我的iMac上却没有。
相关的行如下
System.out.println(GLContext.getCapabilities().GL_EXT_framebuffer_object);
framebuffers[0] = glGenFramebuffersEXT();
功能返回false,并且调用生成帧缓冲器
Exception: java.lang.IllegalStateException: Function is not supported
您尝试调用未导出的函数时会出现这种情况。 Mac中的显卡是NVIDIA GeForce GTX 675MX 1024 MB,看到电脑只有一年的历史,我有点不知道为什么FBO不受支持。
这里的苹果文档https://developer.apple.com/library/mac/documentation/graphicsimaging/conceptual/opengl-macprogguide/OpenGLProg_MacOSX.pdf指出,如果FBO不可用,我应该使用PBO。好吧,我可以这样做,但是在PBO的相关章节中它说明了
"Important: Pixel buffers are deprecated starting with OS X v10.7 and are
not supported by the OpenGL 3.2 Core profile; use framebuffer objects instead."
所以我好像在追逐我的尾巴。我有OSX> 10.7但没有FBO:S
我的问题是,这是一个已知的问题,无论是在mac上的opengl,在mac上的fbo,还是在mac上的lwjgl,我该怎么做才能解决这个问题。
LWJGL Version: 2.9.0
OpenGL Verison: 3.2 NVIDIA-8.16.74 310.40.00.10f02
OpenGL Shader Version: 1.50
答案 0 :(得分:3)
不要使用EXT扩展来创建FrameBuffers,它们已添加到版本3.x的核心
你应该在扩展上使用核心功能的原因是因为。
你永远不知道某个扩展是否可用,它取决于各种各样的事情,例如。
通过使用核心功能,只要他们的显卡可以运行特定的GL版本,大多数人就有可能运行该程序。
的System.out.println(GLContext.getCapabilities()GL_EXT_framebuffer_object。);
功能返回false,并且调用生成帧缓冲器
这几乎证明了我对扩展和核心功能的看法。正如核心功能所说,您只需要一个支持所需OpenGL或以上版本的显卡。
我对OpenGL Extension vs OpenGL Core做了更深入的回答,您可以点击链接。
为了使LWJGL使用核心Framebuffer功能,您需要导入以下内容
import static org.lwjgl.opengl.GL30.*;
以下代码中使用了以下几个变量。
int fbo_handle = -1;
int texture_handle = -1;
int rbo_depth_buffer_handle = -1;
fbo_handle = glGenFramebuffers();
this.texture_handle = glGenTextures();
rbo_depth_buffer_handle = glGenRenderbuffers();
glBindFramebuffer(GL_FRAMEBUFFER, fbo_handle);
glBindTexture(GL_TEXTURE_2D, texture_handle);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_INT, (ByteBuffer) null);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_handle, 0);
glBindRenderbuffer(GL_RENDERBUFFER, rbo_depth_buffer_handle);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo_depth_buffer_handle);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
System.err.println("Framebuffer configuration error");
}
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, fbo_handle);
glActiveTexture(GL_TEXTURE0); // This is for Shader usage
glBindTexture(GL_TEXTURE_2D, texture_handle);
glDeleteFramebuffers(fbo_handle);
glDeleteRenderbuffers(rbo_depth_buffer_handle);
glDeleteTextures(texture_handle);
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.*;
import static org.lwjgl.opengl.GL13.*;
import static org.lwjgl.opengl.GL14.*;
import static org.lwjgl.opengl.GL30.*;