텍스쳐를 렌더링하려고 애 쓰고 있지만 약간 문제가 있습니다. 모든 것이 제대로 작동하는지 확인하기 위해 화면에 간단한 쿼드를 렌더링하려고합니다.텍스쳐 문제로 렌더링
target->enable();
glBegin(GL_QUADS);
glColor4f(1.f, 0.f, 0.f, 1.f);
glVertex3f(0.f, 0.f, 0.f);
glColor4f(0.f, 1.f, 0.f, 1.f);
glVertex3f(16.f, 0.f, 0.f);
glColor4f(0.f, 0.f, 1.f, 1.f);
glVertex3f(0.f, 16.f, 0.f);
glColor4f(1.f, 1.f, 0.f, 1.f);
glVertex3f(16.f, 16.f, 0.f);
glEnd();
target->disable();
정상적으로 화면에 쿼드를 그릴 때 쿼드는 예상대로 렌더링됩니다. 그러나 렌더링 대상이 활성화 된 쿼드를 그릴 때 쿼드는 화면의 왼쪽 아래 모서리에서 렌더링되고 대상에 렌더링되지 않습니다.
RenderTarget::RenderTarget(GraphicsDevice *graphics, GLuint width, GLuint height) {
mWidth = width;
mHeight = height;
// First create the depth buffer
glGenRenderbuffers(1, &mDepth);
glBindRenderbuffer(GL_RENDERBUFFER_EXT, mDepth);
// Tell OpenGL that this renderbuffer is going to be a depth buffer
glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, mWidth, mHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mDepth);
glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);
// Create the frame buffer texture
glGenTextures(1, &mTexture);
glBindTexture(GL_TEXTURE_2D, mTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
// Create the frame buffer
glGenFramebuffers(1, &mFbo);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, mFbo);
// Attach the texture
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, mTexture, 0);
//Attach the depth buffer
glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mFbo);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
}
RenderTarget::~RenderTarget() {
glDeleteBuffers(1, &mFbo);
glDeleteBuffers(1, &mDepth);
glDeleteTextures(1, &mTexture);
mFbo = 0;
mDepth = 0;
mTexture = 0;
}
void RenderTarget::enable() {
// Bind the frame buffer
glBindFramebuffer(GL_FRAMEBUFFER_EXT, mFbo);
// store the glViewport and glEnable states
//glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT);
glClearColor(1.f, 0.f, 0.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.f, 0.f, 0.f, 0.f);
glLoadIdentity();
}
void RenderTarget::disable() {
// Restore glViewport and glEnable states
glPopAttrib();
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
}
FBO가 완전합니까 (http://www.opengl.org/wiki/Framebuffer_Object#Framebuffer_Completeness)? 당신은'glCheckFramebufferStatus()'를 호출하지 않는 것 같습니다. – genpfault
예, GL_FRAMEBUFFER_COMPLETE_EXT (으)로 되돌아 왔습니다. – rcapote