Skip navigation.
 
mlDrawing to NSView with OpenGL questions
FROM : Konstantin Anoshkin
DATE : Sun Feb 10 17:11:01 2008

Hello.

Is it possible to somehow mix CoreGraphics and OpenGL drawing commands 
using a common NSView? What I'd like to do is render my own vertex/
fragment shaders into a CGContext.

1. Currently, I'm drawing to an NSOpenGLPixelBuffer with OpenGL, then 
copy the drawing with glReadPixels() to a scratch buffer, from which I 
copy byte rows to an NSBitmapImageRep, which I can draw to my 
CGContext or NSGraphicsContext. That's a lot of code moving pixels 
from VRAM to RAM to GPU, though I admit it works. Is there a more 
straight-forward way to draw with OpenGL to CGContext or, maybe, with 
CoreGraphics to an NSOpenGLView?

2. I've written and tested several shaders both in OpenGL Shader 
Builder and in a test app inside an NSOpenGLView. They work just fine. 
However, I don't have any NSOpenGLViews in my app, so I guess it's the 
absence of glutCreateWindow() that causes glCreateShader() to return 0 
without errors. If I call glutCreateWindow(), I get "GLUT Fatal Error: 
redisplay needed for window 1, but no display callback." in the 
console, so I have to add display callbacks, but then I'm moving away 
from my NSView. What confuses me is why simple OpenGL commands works 
while shaders don't.

What is the best practice of mixing CoreGraphics and OpenGL? Ideally, 
I'd want to avoid copying pixel data back to RAM because that slows 
down my animations a lot.

Thanks in advance.

Regards.
Konstantin.

Related mailsAuthorDate
mlDrawing to NSView with OpenGL questions Konstantin Anoshki… Feb 10, 17:11
mlRe: Drawing to NSView with OpenGL questions Erik Buck Feb 10, 18:18