mk12
mk12

Reputation: 26434

CGFloat vs GLfloat

I understand CGFloat should be used in Cocoa applications to make them 64-bit clean. But what about in a simple OpenGL game that uses Cocoa/Objective-C for everything but the rendering (to an NSOpenGLView)? CGFloat is a part of Core Graphics, so if I would it also be alright to use CGPoint, CGRect etc.? or should I just write rects and vectors and that kind of stuff myself?

Basically is it fine to mix OpenGL with CoreGraphics types?

Upvotes: 0

Views: 1334

Answers (2)

wbyoung
wbyoung

Reputation: 22493

I would recommend using GLfloat everywhere you plan on passing floats to OpenGL and CGFloat for anything in Cocoa. While they may be the same width now (I assume they are, but I didn't look), there's no guarantee that they'll be the same forever. You'll probably be safer writing your own rect and size structs. Shouldn't be too much work.

Upvotes: 5

Dan Waylonis
Dan Waylonis

Reputation: 812

In 64-bit Intel binaries, sizeof(CGFloat) is 8, and sizeof(GLfloat) is 4.

Upvotes: 4

Related Questions