Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa OpenGL window in pure C?

Tags:

c

cocoa

opengl

I want to open an OpenGL window ( to display and grab keystrokes / mouse events ) in MacOSX.

I don't want to use Glut (since it demandds it be the root thread).

I don't want to learn Objective C.

Is there anyway to access the OpenGL api in pure C?

Thanks!

like image 747
anon Avatar asked Jan 30 '10 22:01

anon


2 Answers

If you want to grab events on OS X, there are a couple options:

  • SDL. Highly recommended, C, not very flexible. You will need to either install it on systems where you use it, or include the framework in your app bundle.
  • Cocoa. Use this if you need more flexibility.
  • Carbon. I don't recommend using this API, but it is pure C.

Objective C is a very small set of additions to pure C code. You don't have to learn much of it to get by using the Cocoa API. It's not at all the beast that is C++. If you know C, you can learn all you need in a couple hours. All of the best sample code and documentation on the web is for Cocoa, not Carbon. There's OpenGL sample code galore that uses Cocoa, all over the web and on Apple's dev website.

However, all the event handling has to go in the main thread regardless of the API you use. That's the purpose of the main thread, no? You can do OpenGL calls in any thread you like, of course.

like image 54
Dietrich Epp Avatar answered Nov 08 '22 07:11

Dietrich Epp


I ended up using GLFW.

At first, keyboard events do not work; but they have a sample script for building a bundle. After that, flawless.

like image 4
anon Avatar answered Nov 08 '22 08:11

anon