I put together a tiny test program to try out some OpenGL functions. I'm having trouble with glDrawPixels(). The image displays but it's basically just like looking at static. You cannot distinguish the real image at all. I don't know much about OpenGL, but I can make a cube rotate in 3D. Here's the code I'm working with:
Code:
- (void)drawRect:(NSRect)aRect
{
if (! hasBeenSetup)
{
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
theImage = [NSBitmapImageRep imageRepWithContentsOfFile:@"/Users/Brian/Pictures/tnmt-small.jpg"];
NSLog(@"theImage = %@", theImage);
[theImage retain];
hasBeenSetup = YES;
}
// Draw image when needed
glViewport(0,0,[self bounds].size.width,[self bounds].size.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,[self bounds].size.width,0,[self bounds].size.height,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0,0);
glDrawPixels([theImage size].width,[theImage size].height,GL_RGB,GL_UNSIGNED_BYTE,[theImage bitmapData]);
glFinish();
}