PDA

View Full Version : Use of NSView subclass with OpenGL 3.2 gives undefined framebuffer errors



Balance73
12-24-2012, 05:03 PM
Hi All,

I've a 2008 Unibody Apple MacBook with a 2.4Ghz Core 2 Duo CPU, an 8GB RAM upgrade and an nVidia GeForce 9400M graphics chipset. It's running OS X 10.8.2.

I'm working on a pair of variants of Apple's OpenGL 3.2-based GLEssentials project (the reflected, spinning monster), which at this stage should display a simple 'ground' made up of flat-shaded triangles. The first variant sub-classes the NSOpenGLView class, and displays the triangles in a window without any issues. The second variant sub-classes the NSView class, as opposed to the NSOpenGLView class. When I compile and run it, the output of the command "glCheckFramebufferStatus(GL_FRAMEBUFFER)", situated immediately after creating a rendering context and making it current, is GL_FRAMEBUFFER_UNDEFINED. Further to that, the shader validation returns "Validation Failed: Current draw framebuffer is invalid." Needless to say, nothing gets rendered. I get the impression these errors pertain to the default framebuffer (object number of 0). I'm told that this should be set up automatically when the rendering context is created.

According to this page (http://www.opengl.org/wiki/Framebuffer_Object#Framebuffer_Completeness) this can be resolved. If someone can enlighten me on how it would be greatly appreciated. It wouldn't surprise me if it was absurdly simple. :-| Happy to provide source code if need be.

Thanks in advance.

arekkusu
12-24-2012, 06:16 PM
See the documentation:

Working With Rendering Contexts
http://developer.apple.com/library/mac/#documentation/graphicsimaging/Conceptual/OpenGL-MacProgGuide/opengl_contexts/opengl_contexts.html
which notes that NSOpenGLView handles on your behalf (via the -update method) associating the view with the context.

and Drawing to a Cocoa View
http://developer.apple.com/library/mac/#documentation/graphicsimaging/conceptual/OpenGL-MacProgGuide/opengl_drawing/opengl_drawing.html
which shows an example of a custom NSView implementation (note -update etc, you are responsible for re-implementing the NSOpenGLView machinery.)

Balance73
12-29-2012, 12:57 AM
Thanks for the links, arekkusu. I'd read them before, but hadn't paid the same sort of attention as I've done now. Having followed the instructions more closely (particularly with the implementation of the prepareOpenGL method), I'm pleased to say that I've got OpenGL 3.2 and NSView sub-classes playing together just nicely, and rendering what I want. :D