Shader with Render-Target integration in OpenGL

E915a7b10f57abfa156e866fa92bfc86
0
Dr__Nick 101 Jun 14, 2009 at 21:04

Hi!

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?

Thanks
Nick

11 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 168 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.

E915a7b10f57abfa156e866fa92bfc86
0
Dr__Nick 101 Jun 14, 2009 at 21:23

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

6837d514b487de395be51432d9cdd078
0
TheNut 179 Jun 14, 2009 at 22:53

Just push the button and all will be ok :lol:
btnmakegame.png

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 168 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.

5ccedf5e0f538b594eb578f003ade3eb
0
Hyper 96 Jun 15, 2009 at 05:43

@TheNut

Just push the button and all will be ok :lol:
btnmakegame.png

The red button didn’t do anything… :(

E915a7b10f57abfa156e866fa92bfc86
0
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 http://wiki.delphigl.com/index.php/Tutorial_Framebufferobject. 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?

6673a7d3bfd3d1db5e05c5676cc040b6
0
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 …

E915a7b10f57abfa156e866fa92bfc86
0
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);
*

A0c9c0649c5deacc0ae3b7f7721c94d2
0
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:
fout.open(“myDebugFile.txt”);
fout<<&fb.fbobj;
fout.close()

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++”

6837d514b487de395be51432d9cdd078
0
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.