프로그래밍 방식으로 텍스처를 렌더링 한 다음 이전에 그려진 텍스처로 스킨 된 간단한 쿼드를 렌더링하는 테스트 프로그램이 있습니다. 이 프로그램은 매우 간단하며 모든 것이 2D로 이루어집니다. 이 프로그램은 리눅스에서 잘 작동하고해야 맘에 드는 모든 것을 보인다 : 나는 10.7 아무것도 실행되지 내 맥에서 프로그램을 실행할 때 OSX 10.7에서 FBO를 사용하여 텍스처를 렌더링 할 때 문제가 발생하지만 리눅스가 아닌 경우
그러나 나타난다 : 나는 이유에 관해서는 완전한 손실에있어
프로그램이 내 Mac에서 작동하지 않습니다.
다음은 프로그램의 관련 비트입니다.
void createFBObject(){
cout<<"Creating a new frame buffer object"<<endl;
glDeleteFramebuffers(1, &fboId);
glGenFramebuffersEXT(1, &fboId);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
glGenRenderbuffersEXT(1, &rboId);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboId);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, textureSize, textureSize);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboId);
bool status = checkFramebufferStatus();
if(!status){
cout<<"FrameBufferObject not created! Quitting!"<<endl;
exit(1);
fboUsed = false;
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
텍스처로 렌더링 :
void drawToTexture(){
if (!isTextureValid)
createTextureObject();
glViewport(0, 0, textureSize, textureSize);
glLoadIdentity();
// set the rendering destination to FBO
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
// clear buffer
glClearColor(0, 0, 0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw to the texture
glColor3f(0.0, 1.0, 0.0);
for (int i=1; i<=5; i++){
glBegin(GL_LINE_LOOP);
glVertex2f(-1 * i/5.0f, -1 * i/5.0f);
glVertex2f(1 * i/5.0f, -1 * i/5.0f);
glVertex2f(1 * i/5.0f, 1 * i/5.0f);
glVertex2f(-1 * i/5.0f, 1 * i/5.0f);
glEnd();
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
텍스쳐 쿼드 렌더링 :
void drawTexturedQuad(){
glViewport(50, 50, textureSize, textureSize);
glLoadIdentity();
glClearColor(0.2, 0.2, 0.2, 0.2);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, textureId);
int size = 1;
int texS = 1;
glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1);
glTexCoord2f(texS, texS); glVertex3f(size, size,0);
glTexCoord2f(0, texS); glVertex3f(-1 * size , size,0);
glTexCoord2f(0, 0); glVertex3f(-1 * size, -1 * size,0);
glTexCoord2f(texS, 0); glVertex3f(size, -1 * size,0);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
}
를 프레임 버퍼 오브젝트를 작성
void createTextureObject(){
cout<<"Creating a new texture of size:"<<textureSize<<endl;
//glDeleteTextures(1, &textureId);
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); // automatic mipmap generation included in OpenGL v1.4
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, textureSize, textureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
isTextureValid = true;
createFBObject();
}
:
텍스처 만들기
void displayCB(){
drawToTexture();
drawTexturedQuad();
glutSwapBuffers();
}
또한 내가 가지고있는 다른 방법 FrameBufferObjects는 OpenGL을 지원하는 있는지 확인하고 그렇지 않은 경우 프로그램이 종료 : 나는 GLUT 다시 내 디스플레이 전화를 사용하고
는 간단하다. 또한 창 크기를 조정할 때마다 textureSize
을 설정하는 다른 논리가 있습니다.
내 버퍼 ID가 무엇인지 실마리가 없습니다. bufferId를 0으로 바인딩 할 때 내 버퍼의 바인딩을 해제하고 있습니다. 또한 나는 2 추천의 힘을 알고 있지만 내 경우에는 정확한 크기의 텍스처를 사용해야한다. – slayton