-1

I know this has been asked before (I did search) but I promise you this one is different.

I am making an app for Mac OS X Mountain Lion, but I need to add a little bit of a bloom effect. I need to render the entire scene to a texture the size of the screen, reduce the size of the texture, pass it through a pixel buffer, then use it as a texture for a quad.

I ask this again because a few of the usual techniques do not seem to function. I cannot use the #version, layout, or out in my fragment shader, as they do not compile. If I just use gl_FragColor as normal, I get random pieces of the screen behind my app rather than the scene I am trying to render. The documentation doesn't say anything about such things.

So, basically, how can I render to a texture properly with the Mac implementation of OpenGL? Do you need to use extensions to do this?

I use the code from here

Justin
  • 2,122
  • 3
  • 27
  • 47
  • 5
    *"this one is different"* -> *"How can be done? I cannot use because they don't work. I don't provide any code of my exisiting approach."* - Hmm, not that different really. – Christian Rau Feb 12 '13 at 15:28
  • Unrelated keywords? If you have ever tried this, you would know that everyone says you must use `layout(location = 0) out vec3 color;` in the fragment shader. Both `layout` and `out` cause compilation errors. I am asking, and, I think, very clearly, how to replace them. – Justin Feb 12 '13 at 15:31
  • 2
    Those are totally unrelated to the bloom effect, though. Certainly **not** everybody says you *have* to use `layout`. This is a mere version incompatibility and a very basic OpenGL problem. If you don't have OpenGL 3, then use `gl_FragColor` as you always do. If that doesn't work, then that's because you're doing something else wrong (in the code not shown) and not because the bloom effect requires you to use `layout` and `out`, which would be rubbish. – Christian Rau Feb 12 '13 at 15:35
  • @ChristianRau I am not asking how to do the bloom effect. I am simply telling you what happens with the current rendering structure. What I need to know is how to render to a texture on the Mac platform with the Mac implementation of OpenGL. It is really quite a simple question. – Justin Feb 12 '13 at 15:37
  • *"I use the code from here"* - Don't have support for OpenGL 3 shader syntax? Well, don't use tutorials that use it, or at least don't require the examples to map one-to-one to the old GLSL syntax. *"But `gl_FragColor` doesn't work"* - Then well, *you* have ported the example insufficiently (though hard to say without code), or *the example* is wrong in the first place. – Christian Rau Feb 12 '13 at 15:38
  • Christian's right, you don't have to use the `layout` keyword if all you care about is generating a bloom effect. I've done this without any of these capabilities. Also, you don't specify, but are you using OpenGL 3.2? If not, you need to explicitly enable the use of OpenGL 3.2 Core Profile in 10.7 and up: http://developer.apple.com/library/mac/documentation/graphicsimaging/conceptual/opengl-macprogguide/opengl_pixelformats/opengl_pixelformats.html#//apple_ref/doc/uid/TP40001987-CH214-SW13 – Brad Larson Feb 12 '13 at 16:46

1 Answers1

1

Rendering to a texture is best done using FBOs, which let you render directly into the texture. If your hardware/driver doesn't support OpenGL 3+, you will have to use the FBO functionality through the ARB_framebuffer_object core extension or the EXT_framebuffer_object extension.

If FBOs are not supported at all, you will either have to resort to a simple glCopyTexSubImage2D (which involves a copy though, even if just GPU-GPU) or use the more flexible but rather intricate (and deprecated) PBuffers.

This tutorial on FBOs provides a simple example for rendering to a texture and using this texture for rendering afterwards. Since the question lacks specific information about the particular problems you encountered with your approach, those rather general googlable pointers to the usual render-to-texture resources need to suffice for now.

Christian Rau
  • 45,360
  • 10
  • 108
  • 185