Jump to content


Shader with Render-Target integration in OpenGL


11 replies to this topic

#1 Dr. Nick

    New Member

  • Members
  • PipPip
  • 19 posts

Posted 14 June 2009 - 09:04 PM

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

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 14 June 2009 - 09:14 PM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Dr. Nick

    New Member

  • Members
  • PipPip
  • 19 posts

Posted 14 June 2009 - 09:23 PM

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

#4 TheNut

    Senior Member

  • Moderators
  • 1699 posts
  • LocationThornhill, ON

Posted 14 June 2009 - 10:53 PM

Just push the button and all will be ok :lol:
Posted Image
http://www.nutty.ca - Being a nut has its advantages.

#5 V-man

    New Member

  • Members
  • Pip
  • 4 posts

Posted 15 June 2009 - 12:40 AM

http://www.opengl.or...mebuffer_object
and also
http://www.opengl.or...More_about_FBOs

#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 15 June 2009 - 01:02 AM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#7 Hyper

    Valued Member

  • Members
  • PipPipPip
  • 195 posts

Posted 15 June 2009 - 05:43 AM

TheNut said:

Just push the button and all will be ok :lol:
Posted Image
The red button didn't do anything... :(
“You may be disappointed if you fail, but you are doomed if you don't try.”
Beverly Sills

#8 Dr. Nick

    New Member

  • Members
  • PipPip
  • 19 posts

Posted 15 June 2009 - 10:13 AM

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...amebufferobject. 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[i].fbobj);
glGenTextures(1, &fb[i].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?

#9 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 575 posts

Posted 15 June 2009 - 10:25 AM

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

#10 Dr. Nick

    New Member

  • Members
  • PipPip
  • 19 posts

Posted 15 June 2009 - 10:29 AM

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

#11 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 15 June 2009 - 04:27 PM

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[i].fbobj (or perhaps just fb[i].fbobj)

or to a file by using:
fout.open("myDebugFile.txt");
fout<<&fb[i].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++"
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#12 TheNut

    Senior Member

  • Moderators
  • 1699 posts
  • LocationThornhill, ON

Posted 15 June 2009 - 06:24 PM

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.
http://www.nutty.ca - Being a nut has its advantages.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users