NSBitmapImageRep to OpenGL texture
NSBitmapImageRep to OpenGL texture
- Subject: NSBitmapImageRep to OpenGL texture
- From: Aidas Dailide <email@hidden>
- Date: Wed, 1 Oct 2003 18:24:31 +0300
Hi,
I am using NSBitmapImageRep's -
(id)initWithFocusedViewRect:(NSRect)rect to load "screenshot" of view
to NSBitmapImageRep. The next thing what I want to do is to use it as
OpenGL texture in OpenGL drawing. I can easily load .bmp files to
NSBitmapImageRep and then to OpenGL texture, but for some reason
initWithFocusedViewRect doesn't work. Could anyone help me?
I am using code from one of the ports of NeHe tutorials. Here it is:
BOOL success = FALSE;
int bitsPPixel, bytesPRow;
unsigned char *theImageData;
int rowNum, destRowNum;
NSLog(@"ziurim");
if( theImage != nil )
{
NSLog(@"ne nilas");
bitsPPixel = [ theImage bitsPerPixel ];
bytesPRow = [ theImage bytesPerRow ];
if( bitsPPixel == 24 ) // No alpha channel
texFormat[ texIndex ] = GL_RGB;
else if( bitsPPixel == 32 ) // There is an alpha channel
texFormat[ texIndex ] = GL_RGBA;
texSize[ texIndex ].width = [ theImage pixelsWide ];
texSize[ texIndex ].height = [ theImage pixelsHigh ];
texBytes[ texIndex ] = calloc( bytesPRow * texSize[ texIndex
].height,
1 );
if( texBytes[ texIndex ] != NULL )
{
success = TRUE;
// theImageData=[theImage bitmapData];
theImageData = [ theImage bitmapData ];
destRowNum = 0;
for( rowNum = texSize[ texIndex ].height - 1; rowNum >= 0;
rowNum--, destRowNum++ )
{
// Copy the entire row in one shot
memcpy( texBytes[ texIndex ] + ( destRowNum * bytesPRow ),
theImageData + ( rowNum * bytesPRow ),
bytesPRow );
}
}
}
return success;
Thanks,
Aidas
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.