为什么帧缓冲会在Derelict3中冻结?

时间:2012-05-05 10:51:59

标签: opengl d fbo

我正在使用Derelict3,它使用特定的openGL3标准,如果调用glEnable(GL_DEPTH_TEST),我遇到屏幕冻结(不更新)的问题,如果不调用深度缓冲区则不起作用。我注意到,如果在设置SDL_GL上下文并重新加载Derelict3之前进行调用,则会忽略设置清晰颜色和启用深度测试的调用。我必须按以下顺序制作它们:

win=SDL_CreateWindow("3Doodle", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h,     flags); 
if(!win){ 
       writefln("Error creating SDL window"); 
      SDL_Quit(); 
} 

context=SDL_GL_CreateContext(win); 
SDL_GL_SetSwapInterval(1); 

glVersion=DerelictGL3.reload(); 

glEnable(GL_DEPTH_TEST); 
glEnable(GL_CULL_FACE); 

glClearColor(0.0, 0.0, 0.0, 1.0); 
glClearDepth(1.0); 

glCullFace(GL_BACK); 
glFrontFace(GL_CCW);

虽然这在写入标准双缓冲区时整理了深度剔除,但当我使用renderBuffer作为新的深度缓冲区实现一个framebuffer对象时,我得到一个冻结......程序编译并运行时没有警告,但渲染的图像屏幕对齐的四边形保持固定。如果我注释掉glEnable(GL_DEPTH_TEST);相机可以自由移动,但渲染后的图像无需深入测试,只需按顺序绘制对象。

帧缓冲初始化代码是:

//fbo 
glEnable (GL_FRAMEBUFFER_SRGB); 
glGenFramebuffers(1, &fbo); 
assert(fbo > 0); 
glBindFramebuffer(GL_FRAMEBUFFER, fbo); 

glGenRenderbuffers(1, &rbo); 
assert(rbo > 0); 
glBindRenderbuffer(GL_RENDERBUFFER, rbo); 
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, projMat.w, projMat.h); 
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo); 
glBindRenderbuffer(GL_RENDERBUFFER, 0); 

glGenTextures(1, &fbon); 
assert(fbon > 0); 
glActiveTexture(GL_TEXTURE0); 
glBindTexture(GL_TEXTURE_2D, fbon); 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, projMat.w, projMat.h, 0, GL_RGBA,     GL_UNSIGNED_BYTE, null); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);    
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbon, 0); 
glBindTexture(GL_TEXTURE_2D, 0); 

 glGenTextures(1, &fboc); 
assert(fboc > 0); 
glActiveTexture(GL_TEXTURE1); 
glBindTexture(GL_TEXTURE_2D, fboc); 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, projMat.w, projMat.h, 0, GL_RGBA,     GL_UNSIGNED_BYTE, null); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);    
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, fboc, 0); 
glBindTexture(GL_TEXTURE_2D, 0); 

glGenTextures(1, &fbop); 
assert(fbop > 0); 
glActiveTexture(GL_TEXTURE2); 
glBindTexture(GL_TEXTURE_2D, fbop); 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, projMat.w, projMat.h, 0, GL_RGBA,     GL_UNSIGNED_BYTE, null); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);    
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, fbop, 0); 
glBindTexture(GL_TEXTURE_2D, 0); 

int status=glCheckFramebufferStatus(GL_FRAMEBUFFER); 
assert(status == GL_FRAMEBUFFER_COMPLETE); 

buffs=[GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2]; 
glDrawBuffers(3, buffs.ptr); 
glBindFramebuffer(GL_FRAMEBUFFER, 0);

在draw()中调用fbo的代码是:

glBindFramebuffer(GL_FRAMEBUFFER, fbo); 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

glUseProgram(shad); 
glUniformMatrix4fv(viewLoc, 1, GL_TRUE, player.mat.ptr); 

current.draw(); 

glUseProgram(0); 
glBindFramebuffer(GL_FRAMEBUFFER, 0); 

rend.draw();

我感到茫然,因为相同的代码在c#中应该正常工作。

1 个答案:

答案 0 :(得分:2)

我的愚蠢。忘了指定glDepthFunc