problem rendering on framebufferobject

Started by
6 comments, last by Kalidor 17 years ago
Hello All, I was rendering to a frame buffer object, which has a texture attached to it. The rendering was done with lighting disabled, and glColor4f(1,1,1,1). For some reason, when I try to draw that texture (which should now have an image in it), it draws darker than it should. Here is the code.. rendering to the buffer:

   bloomBuffer->activateBuffer(); // this activates the framebuffer (binding etc)

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   glDisable(GL_DEPTH_TEST);
   glDisable(GL_LIGHTING);
   glDisable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA,GL_ONE);

   skyrail->setupBaseOrtho(); // this just sets orthogonal view, nothing more

   glDisable(GL_TEXTURE_2D);

   glBegin(GL_QUADS);
      glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
      glVertex2f(0,0);
      glVertex2f(0,100);
      glVertex2f(100,100);
      glVertex2f(100,0);
   glEnd();

   glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
   glEnable(GL_LIGHTING);
   glEnable(GL_DEPTH_TEST);
And later, the fbo's attached texture gets drawn. But, the rectangle above doesn't appear white, it appears grey (i checked the actual color, its 175,175,175).. Does anyone know what could possibly be wrong? I've been trying to find out what's happened for hours, and this is driving me insane. thanks in advance
Advertisement
Quote:Original post by underthesun
   ...   glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);   glEnable(GL_LIGHTING);   glEnable(GL_DEPTH_TEST);


And later, the fbo's attached texture gets drawn. But, the rectangle above doesn't appear white, it appears grey (i checked the actual color, its 175,175,175)..
Is lighting still enabled when you're rendering the FBO texture to the backbuffer? Can you post that part of your code?
thanks for the quick reply.

   glDisable(GL_DEPTH_TEST);   glDisable(GL_LIGHTING);   glDisable(GL_BLEND);   skyrail->setupBaseOrtho();   activateGL();   glBegin(GL_QUADS);      glColor4f(1.0f, 1.0f, 1.0f, 1.0f);      realCoord2f(0,0);      glVertex2f(0,0);      realCoord2f(0,1);      glVertex2f(0,realheight);      realCoord2f(1,1);      glVertex2f(realwidth,realheight);      realCoord2f(1,0);      glVertex2f(realwidth,0);   glEnd();   glEnable(GL_BLEND);   glEnable(GL_LIGHTING);   glEnable(GL_DEPTH_TEST);


I just hope it's not my graphics card or anything, i mean it's a radeon 9550. Or opengl or anything out of my control to fix..
What do activateGL and realCoord2f do? Does this quad appear pure white when texturing is disabled? Are you getting any OpenGL errors? Anything else you can think of where your code might be going wrong, because so far it looks okay to me.
void Texture::realCoord2f(float x, float y){   glTexCoord2f(x * realwidth) / powerwidth, (((1.0f - y) * realheight) / powerheight);}


The function above just sets the coordinates based on the original texture's actual coordinates, as opposed to the texture with the width and height of powers of 2 (just for convenience).

activateGL for the texture does the following:

void Texture::activateGL(){   activateGL(0);}void Texture::activateGL(int multitextureindex){   if(success){      glActiveTexture(GL_TEXTURE0 + multitextureindex);      glEnable(GL_TEXTURE_2D);      glBindTexture(GL_TEXTURE_2D, textureid);   }}


so yeah.. I also did check the opengl errors, and something showed up but I fixed that, and did not affect anything..

this is really weird. I might check it at university computers sometimes..
Ah, it seems like this is some decent sized project, or at least large enough that just posting the code for it would be tedious. Is it possible for you to upload the entire project somewhere so that we can run it and take a closer look? I won't be able to check it out for a while now but I'll try whenever I can if it's still not fixed by then.
I actually just fixed the problem by not using framebuffers, that is, just not enabling the frame buffer, and using copyteximage2d into the texture. It's much simpler I guess.

Thanks for the help kalidor :D just a question, what kind of performance difference does using a fbo offer as opposed to just using copyteximage2d?
Quote:Original post by underthesun
I actually just fixed the problem by not using framebuffers, that is, just not enabling the frame buffer, and using copyteximage2d into the texture. It's much simpler I guess.

Thanks for the help kalidor :D just a question, what kind of performance difference does using a fbo offer as opposed to just using copyteximage2d?
Sorry for the late reply.

If you're sticking with the copy-to-texture approach, I would recommend creating the texture before hand and then using glCopyTexSubImage2D instead of glCopyTexImage2D. The difference is that glCopyTexSubImage2D merely updates the texture's image data whereas glCopyTexImage2D recreates the whole texture. The former will be slightly more efficient (it may not be noticeable however, depending on your application).

Several posts here (I've never actually tested the performance differences) seem to indicate that there isn't too large a difference in performance between rendering to a texture using FBOs and rendering to the framebuffer and then copying to the texture (again, it may not be noticeable depending on the application). There are several advantages to using FBOs however, including getting around the annoyance of the pixel ownership test.

The pixel ownership test is the first per-fragment test to take place and it tests if the GL context "owns" the current fragment. If it doesn't, it's up to the window system what happens to the fragment. The biggest affect this has on copy-to-texture is that if another window is obscuring your OpenGL window, it's undefined what is rendered in the GL context under that obscuring window, because the GL doesn't "own" those fragments. So when you render to the framebuffer and copy it to a texture, you usually get garbage in those areas of the texture that correspond to the obscured areas of the framebuffer.

This topic is closed to new replies.

Advertisement