• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Coordinate system in CAOpenGLLayer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Coordinate system in CAOpenGLLayer


  • Subject: Coordinate system in CAOpenGLLayer
  • From: Graham Cox <email@hidden>
  • Date: Mon, 08 Aug 2011 17:35:59 +1000

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

  • Follow-Ups:
    • Re: Coordinate system in CAOpenGLLayer
      • From: Thomas Davie <email@hidden>
  • Prev by Date: Re: Notification of autocomplete (in any app)
  • Next by Date: Core Data : User missing inverse relationship despite model settings
  • Previous by thread: Re: Notification of autocomplete (in any app)
  • Next by thread: Re: Coordinate system in CAOpenGLLayer
  • Index(es):
    • Date
    • Thread