Xcode OpenGL Application Template
Well here it is, the long awaited update to the Template 
Xcode OpenGL Template Version 3
as said in the Read Me:
Fullscreen is now implemented
Window resizing now works, altho it flickers while resizing
Minimize to the dock now shows the last frame of animation
it took me this long to get it working!
but thanks to OneSadCookie and ThemsAllTook I got it working
as you can probably see
perhaps sometime I'll fix the flashing
regards and hope you like it,
ss2cire

Xcode OpenGL Template Version 3
as said in the Read Me:
Fullscreen is now implemented
Window resizing now works, altho it flickers while resizing
Minimize to the dock now shows the last frame of animation
it took me this long to get it working!

but thanks to OneSadCookie and ThemsAllTook I got it working

as you can probably see

perhaps sometime I'll fix the flashing
regards and hope you like it,
ss2cire
yay!
thanks a lot.
thanks a lot.
There was a long silence...
'I claim them all,' said the Savage at last.
I downloaded the template, and am using it for my first baby steps on Mac/OpenGL programming. Very much appreciated!
I do have one suggestion, though. There are currently two places where you define the perspective transform: initGL and reshape. Perhaps this could be factored out into its own method? (Or drawFrame call reshape directly on first draw?)
I do have one suggestion, though. There are currently two places where you define the perspective transform: initGL and reshape. Perhaps this could be factored out into its own method? (Or drawFrame call reshape directly on first draw?)
ad this to MyOpenglView.m, and then impliment it in MyOpenGLView.h:
Code:
- (IBAction)takeScreenshot:(id)sender
{
NSData *imageData;
/*
'self' is your NSOpenGLView
*/
//width needs to be divisible by four
NSSize imageSize = [self bounds].size;
imageSize.width = ( imageSize.width - ( ((int)imageSize.width) % 4 ));
int imageWidth = imageSize.width;
int imageHeight = imageSize.height;
int bytesPerPixel = 4;
int bytesPerImage = imageWidth * imageHeight * bytesPerPixel;
char *imageBuffer = ( char * ) malloc( bytesPerImage );
/*
Now, extract image bytes
*/
[[self openGLContext] makeCurrentContext];
glReadPixels(0, 0, imageWidth, imageHeight, GL_RGBA, GL_UNSIGNED_BYTE, imageBuffer);
/*
Now, make 24bit image rep
*/
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:nil
pixelsWide:imageWidth
pixelsHigh:imageHeight
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:0
bitsPerPixel:0];
/*
Copy RGB over, but not alpha
*/
unsigned char *src, *end, *dest;
src = imageBuffer;
end = src + bytesPerImage;
dest = [rep bitmapData];
while ( src < end )
{
*dest = *src; dest++; src++; //R
*dest = *src; dest++; src++; //G
*dest = *src; dest++; src++; //B
++src; //A
}
NSImage *image = [[NSImage alloc] init];
[image addRepresentation:rep];
/*
Flip image vertically
*/
[image setFlipped:YES];
[image lockFocusOnRepresentation:rep];
[image unlockFocus];
/*
The original NSImage loses its NSBitmapImegreRep when its flipped, and the
only way I can come up with to get an NSBitmapImageRep back is to make a
new NSImage from the original. The horror!
*/
NSImage *flipped = [[NSImage alloc] initWithData: [image TIFFRepresentation]];
/*
Free up temporaries
*/
[rep release];
[image release];
free( imageBuffer );
imageData = [flipped TIFFRepresentation];
[imageData writeToFile:[@"~/Desktop/Screenshot.tiff" stringByExpandingTildeInPath] atomically:YES];
}
It's not magic, it's Ruby.
What's up with this comment?
//width needs to be divisible by four
You never actually divide it by four, and I see no reason you'd ever want to. There's no arbitrary requirement that width has to be a multiple of 4 in glReadPixels or -[NSBitmapImageRep initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:].
- Alex Diener
//width needs to be divisible by four
You never actually divide it by four, and I see no reason you'd ever want to. There's no arbitrary requirement that width has to be a multiple of 4 in glReadPixels or -[NSBitmapImageRep initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:].
- Alex Diener
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
iPad, OpenGL ES, and XCode Instruments problem! | Bandit | 0 | 5,265 |
Dec 13, 2010 01:21 PM Last Post: Bandit |
|
Xcode OpenGL GLUT help please! | cloudcrono | 11 | 14,286 |
Sep 23, 2006 04:58 PM Last Post: jpalm |
|
OpenGL problem in Xcode deployment build | grandall | 6 | 6,198 |
Mar 29, 2006 11:12 AM Last Post: grandall |
|
Cocoa / Objective-C / OpenGL Template | mdavis1982 | 13 | 9,390 |
Feb 28, 2005 01:54 PM Last Post: arekkusu |