// INITIALIZATION
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
// Load Test Texture
glGenTextures(1, &textureTest);
glBindTexture(GL_TEXTURE_2D, textureTest); // Bind Our Texture
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtered
[self loadTexture: @"texture"]; // calls glTexImage2D with image data from png
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0, 320.0f,480.0f);
glOrthof(0,320.0f, 480.0f,0, -1.0f, 1.0f); // left, right, bottom, top
glMatrixMode(GL_MODELVIEW);
//FBO Setup
glGenTextures(1, &textureFBO); // texture handle
glBindTexture(GL_TEXTURE_2D, textureFBO); //bind it.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtered
glGenFramebuffersOES(1, &FBO); // frame buffer
glBindFramebufferOES(GL_FRAMEBUFFER_OES, FBO); //bind the frame buffer
// attach texture to framebuffer color buffer
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, textureFBO, 0);
if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) printf("CANNOT CREATE FRAMEBUFFER\n");
// MAIN DRAWING LOOP
static const Vertex3D vertices[] = {
{ 0.0, 100.0, 0.0},
{ 100.0, 100.0, 0.0},
{ 0.0, 200.0, 0.0},
{ 100.0, 200.0, 0.0}
};
static const GLfloat texCoords[] = {
0.0, 1.0,
1.0, 1.0,
0.0, 0.0,
1.0, 0.0
};
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
// Render to texture
glBindFramebufferOES(GL_FRAMEBUFFER_OES, FBO);
// Draw test texture
glBindTexture(GL_TEXTURE_2D, textureTest);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, 0); //disable any bound textures.
// End draw test texture
// Render to screen
glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
// Draw FBO texture
glBindTexture(GL_TEXTURE_2D, textureFBO);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, 0); //disable any bound textures.
// End draw FBO texture
cannot render texture to framebuffer (blank screen)
Started by lookitsash, Oct 30 2009 02:59 PM
1 reply to this topic
#1
Posted 30 October 2009 - 02:59 PM
I have read numerous articles/tutorials online regarding drawing a texture to a framebuffer in opengl, but I am having no luck getting it to work. I am creating a framebuffer, drawing a texture to the fbo, and then drawing the fbo texture to the screen but nothing displays. I am at a loss. If i comment out the fbo code and draw the embedded texture directly to the screen, that works. I am using OpenGL ES 1.1 Here is my code:
#2
Posted 08 November 2009 - 10:43 PM
Hi
I have a problem just like you in direct3d.
if you are be sure of fbo format you chose, at first checkup mipmap levels of fbo. because when you render in a fbo, just the first level will updated and other sublevels will left blanks. maybe when you want to render fbo in final step, the blanked sublevel of fbo is drawing !
I have a problem just like you in direct3d.
if you are be sure of fbo format you chose, at first checkup mipmap levels of fbo. because when you render in a fbo, just the first level will updated and other sublevels will left blanks. maybe when you want to render fbo in final step, the blanked sublevel of fbo is drawing !
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











