Re: Coordinate system in CAOpenGLLayer
Re: Coordinate system in CAOpenGLLayer
- Subject: Re: Coordinate system in CAOpenGLLayer
- From: Thomas Davie <email@hidden>
- Date: Mon, 08 Aug 2011 09:24:56 +0100
You're right – the vertices are here specified in OpenGL "clip space" – a coordinate system stretching from -1 to 1 on all 3 axes. If you want to specify points in a different coordinate space, it's your responsibility to make sure that they end up in clip space, by transforming them appropriately. In old world GL (as you have there) this is done through the fixed function transform:
vertex in model space -- * modelview matrix -> vertex in world space -- * projection matrix -> vertex in clip space -- divide x,y,z by w -> vertex in normalised device space -- viewport transform -> vertex in pixel space
I would however *highly* recommend not using old world GL. It will make your later transition to OpenGL 3.2 core much much harder, as most of the functions here (glMatrixMode, glPushMatrix, glRotate, glBegin, glColor, glVertex, glEnd, glPopMatrix, and many others) are no longer present.
To get an idea of how to get started with modern OpenGL, take a look at https://github.com/beelsebob/Cocoa-GL-Tutorial and https://github.com/beelsebob/Cocoa-GL-Tutorial-2. These are still written in OpenGL 2.1, but in a way that the port to 3.2 when you come to it is trivially easy.
Thanks
Tom Davie
if (*ra4 != 0xffc78948) { return false; }
On 8 Aug 2011, at 08:35, Graham Cox wrote:
> I'm looking at using CAOpenGLLayer to boost drawing performance. I'm a total novice at OpenGL.
>
> Looking at the 'CALayerEssentials' sample code as a starting point, it has the following code:
>
> -(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
> {
> // Set the current context to the one given to us.
> CGLSetCurrentContext(glContext);
>
> // We're just going to draw a single red quad spinning around based on the current time. Nothing particularly fancy.
> GLfloat rotate = timeInterval * 60.0; // 60 degrees per second!
> glClear(GL_COLOR_BUFFER_BIT);
> glMatrixMode(GL_MODELVIEW);
> glPushMatrix();
> glRotatef(rotate, 0.0, 0.0, 1.0);
> glBegin(GL_QUADS);
> glColor3f(1.0, 0.0, 0.0);
> glVertex2f(-0.5, -0.5);
> glVertex2f(-0.5, 0.5);
> glVertex2f( 0.5, 0.5);
> glVertex2f( 0.5, -0.5);
> glEnd();
> glPopMatrix();
>
> // Call super to finalize the drawing. By default all it does is call glFlush().
> [super drawInCGLContext:glContext pixelFormat:pixelFormat forLayerTime:timeInterval displayTime:timeStamp];
> }
>
>
> What I find a bit odd here is that the coordinate values for the glVertex calls are not related to the layer's actual bounds, but to some notional coordinate system stretching from -1 to +1 in each dimension. If the layer is resized, the 'square' resulting stretches in proportion.
>
> I didn't expect this, though perhaps it's normal for OpenGL, or at least CAOpenGLLayer. There's virtually nothing in the documentation about this layer or how it's set up, so I'm having a hard time understanding how I'm supposed to go about calculating the coordinates I need.
>
> Can someone point me in the direction of any documentation that could help here, or at least confirm my observations about coordinates being relative to a +/- 1 virtual space?
>
> --Graham
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden