• 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
Problem applying texture to rectangle.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem applying texture to rectangle.


  • Subject: Problem applying texture to rectangle.
  • From: Ian was here <email@hidden>
  • Date: Sat, 2 Jun 2007 21:05:15 -0700 (PDT)

I am trying to attach a texture to a rectangle. I've
Googled the heck out of this and have tried various
configurations, but cannot get the texture to apply.
All I get is a white rectangle. Can anyone tell me
what's NOT going on here?



- (void)awakeFromNib
{
	// Make OpenGL commands render into our GL context.

	NSOpenGLContext		*glContext = [self openGLContext];

	[glContext makeCurrentContext];


	cameraEyeX = 1.0;
	cameraEyeY = 0.0;
	cameraEyeZ = 4.0;
	cameraCenterX = 0.0;
	cameraCenterY = 0.0;
	cameraCenterZ = 0.0;
	cameraUpX = 0.0;
	cameraUpY = 1.0;
	cameraUpZ = 0.0;


	// Setup texture image.

	glEnable( GL_TEXTURE_2D );


	NSImage		*image = [NSImage imageNamed:@"myImage"];
	NSBitmapImageRep	*bitmapImageRep = [[NSBitmapImageRep
alloc] initWithData:[image TIFFRepresentation]];


	glGenTextures( 1, &testTexture );
	glBindTexture( GL_TEXTURE_2D, testTexture );

	glPixelStorei( GL_UNPACK_ROW_LENGTH, [bitmapImageRep
pixelsWide] );
	glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8,
(GLsizei)[bitmapImageRep pixelsWide],
(GLsizei)[bitmapImageRep pixelsHigh], 0, GL_RGB,
GL_UNSIGNED_BYTE, [bitmapImageRep bitmapData] );


	[bitmapImageRep release];
}



- (void)drawRect:(NSRect)rect
{
	// Clear the buffers.

	glClearColor( 0.0, 0.0, 0.0, 1.0 );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );


	// Set the camera position.

	glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();

	gluLookAt( cameraEyeY * sin( cameraEyeZ ), cameraEyeY
* cos( cameraEyeX ), cameraEyeZ, cameraCenterX,
cameraCenterY, cameraCenterZ, cameraUpX, cameraUpY,
cameraUpZ );


  // Draw a rectangle with the texture image applied
to it.

	glBegin( GL_QUADS );
		glTexCoord2f( 0.0, 0.0 );
		glVertex3f( -2.0, -2.0, 0.0 );
		glTexCoord2f( 0.0, 1.0 );
		glVertex3f( -2.0, 2.0, 0.0 );
		glTexCoord2f( 1.0, 1.0 );
		glVertex3f( 2.0, 2.0, 0.0 );
		glTexCoord2f( 1.0, 0.0 );
		glVertex3f( 2.0, -2.0, 0.0 );
	glEnd();

	glFlush();
}



Thanks!


      ____________________________________________________________________________________
Shape Yahoo! in your own image.  Join our Network Research Panel today!   http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: Problem applying texture to rectangle.
      • From: Jon Trainer <email@hidden>
  • Prev by Date: Re: RS: appendFormat allocation implications
  • Next by Date: Creating dynamic views
  • Previous by thread: Re: RS: appendFormat allocation implications
  • Next by thread: Re: Problem applying texture to rectangle.
  • Index(es):
    • Date
    • Thread