How to write Cocoa OpenGL application in C ++?

I am writing an application that should use OpenGL, on Mac, in C ++.

Anyway, can I get Cocoa to just give me OpenGL context and let me do my work in C ++? (I want my application to run on both Mac OS X and iPHone, but the whole GUI is in OpenGL, I just need the OpenGL context).

Thank!

+3
source share
2 answers

You cannot avoid the minimum amount of objective-C code. However, if you rename C object files to .mm files, C object code will be able to call C ++ class methods. This means that you can connect -drawRect (and other relevant NSOpenGLView posts) to the C ++ OpenGL implementation. NSOpenGLView has a -makeCurrent method, which you can call outside of drawRect to make sure that the correct OpenGL context is active.

Then your C ++ code can simply call the gl functions as needed.

+6
source

Take a look at NSOpenGLView . In drawRect:in your subclass, you can access the view context and invoke your OpenGL code.

+2
source

Source: https://habr.com/ru/post/1729242/


All Articles