Shader with Render-Target integration in OpenGL

Dr__Nick 101 Jun 14, 2009 at 21:04


I programmed Shaders that use some RenderTargets together in RenderMonkey, where they work well together. Now I am going to integrate them into an OpenGL project.

I think I understood the principles of integrating a Shader into an OpenGL project, except one thing: How are the RenderTargets handled? Do I have to declare them or something? Is there an example I can download?


11 Replies

Please log in or register to post a reply.

Reedbeta 167 Jun 14, 2009 at 21:14

One of the easiest ways to manage render targets in OpenGL is to use the EXT_framebuffer_object extension. This lets you create a texture and bind it as a render target, then later use the rendered image as a texture again.

Dr__Nick 101 Jun 14, 2009 at 21:23

Uff, thats a lot of stuff. Is there anywhere an example i can download?

TheNut 179 Jun 14, 2009 at 22:53

Just push the button and all will be ok :lol:

Reedbeta 167 Jun 15, 2009 at 01:02

The Filter demo on my website uses EXT_framebuffer_object, although it’s not the main purpose of that demo so it’s not commented as well as it might be.

Hyper 96 Jun 15, 2009 at 05:43


Just push the button and all will be ok :lol:

The red button didn’t do anything… :(

Dr__Nick 101 Jun 15, 2009 at 10:13

Many thanks so far!

I think I understood now, how to do this. As example I took the filter-demo and the tutorial on But there is still an error.

This is a piece of my global code:

struct framebuffer
GLuint fbobj, texobj;
const int NUM_FRAMEBUFFERS = 4;
GLuint fbo_depth_renderbuffer;
framebuffer fb[NUM_FRAMEBUFFERS];

and this is a piece of my initialization:

for (int i = 0; i < NUM_FRAMEBUFFERS; ++i)
glGenFramebuffersEXT(1, &fb.fbobj);
glGenTextures(1, &fb.texobj);
glGenRenderbuffersEXT(1, &fbo_depth_renderbuffer);

The compiling works very well, but while running the program, the error “Unbehandelte Ausnahme bei 0x00000000 in GLSL Example.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x00000000.”, which means an access violation while reading at position 0x00000000, shows up.

What is wrong here?

Goz 101 Jun 15, 2009 at 10:25

Where does it crash? knowing an access violation occurred is no help without knowing WHERE it occurred …

Dr__Nick 101 Jun 15, 2009 at 10:29

Oh, sorry, I forgot to write that.
It occurs at the line glGenFramebuffersEXT(1, &fb*.fbobj);

starstutter 101 Jun 15, 2009 at 16:27

0x00000000 almost always indicates a NULL pointer (in my experience anyway). I see you are using “i” as an index reference, so what is most likley happening is that you are somehow going out of bounds of the array, or you are accessing a texture member of the array that was not initialized. Personally (and I’m not sure if openGL has this) I would use whatever debugging tool you have to try and find which render target is not being initialized. One way you can do this is by outputting the address to the console by calling:

cout<<&fb.fbobj (or perhaps just fb.fbobj)

or to a file by using:“myDebugFile.txt”);

Using the console is the easier option, but I know that in C++ if you don’t already have it open, getting it to while running a windowed app is a pain in the ass.

Good luck and don’t hesitate to ask if you need more details. :)

EDIT: btw, just so you’re not confused, the console is not usually open by default in openGL or directX examples, so in that case cout won’t do anything. I would suggest looking around google for how to open the command console in C++. The code looks like a nightmare, but its suprisingly straight forward, and well worth the effort to be able to output any information you want to help you debug (or anything else you please).

EDIT AGAIN: oh wait… slightly misread your code. I’ll make corrections to my suggestions later. I this I may see the problem.

ANOTHER EDIT: oh! haha :D I’m not sure, but try replacing the “++i” with “i++”

TheNut 179 Jun 15, 2009 at 18:24

Does your video card support that extension? Are your video card drivers up-to-date? Check the function pointer returned from wglGetProcAddress() for the glGenFramebuffersEXT function and make sure it’s defined and not null.