Re: Problem applying texture to rectangle.
Re: Problem applying texture to rectangle.
- Subject: Re: Problem applying texture to rectangle.
- From: Ian was here <email@hidden>
- Date: Sun, 3 Jun 2007 15:11:30 -0700 (PDT)
OK, I found a solution. In the awakeFromNib method,
replace the setup texture image code with this:
// 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 );
gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB,
(GLsizei)[bitmapImageRep pixelsWide],
(GLsizei)[bitmapImageRep pixelsHigh], GL_RGB,
GL_UNSIGNED_BYTE, [bitmapImageRep bitmapData] );
[bitmapImageRep release];
> > 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