PDA

View Full Version : screensavers and selector oddities


Tasnu Arakun
2004.08.27, 05:46 PM
i'm working on a opengl screensaver using apple's framework.
since i wanted to be able to test it easily i built it as a normal, windowed cocoa application using an OpenGLView subclass. after verifying that my code worked as it should i added a new target to my project plus created a subclass to ScreenSaverView. i then followed the instructions from apple's "OpenGL Screensaver"-example and added my OpenGLView as a subview. after a successful compile i then tried to load it in the system preferences, but got this strange error message:

*** - [Shape initWithFrame:isPreview:]: selector not recognized

now, what in earth is this supposed to mean? the class Shape is used to hold information on the shapes that are to be drawn to screen. but this is clearly a call to the ScreenSaverView gone astray.

doing a quick search with google tells me that this error is not that uncommon and that the problem might lay within the macosx rather than my code. i found however neither explaination nor solution.

is there anyone here who have tried their hand at writing a screensaver and have encountered this same problem? any ideas for a workaround? please tell if you want to see any part of the source.

i hope this is not to far off topic. screensavers and games have after all in common that they are often very graphics intense. ;)

arekkusu
2004.08.27, 10:18 PM
I've followed exactly the same steps, but not gotten that error. My ScreenSaverView subclass adds the application's view subclass just like in the GL screensaver sample code:

- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview {
self = [super initWithFrame:frame isPreview:isPreview];
if (self) {
NSRect newFrame = frame;
newFrame.origin = NSZeroPoint;
view = [[BlobView alloc] initWithFrame:newFrame];
if (view) {
[self setAutoresizesSubviews:YES];
[self addSubview:view];
[self setAnimationTimeInterval:1/30.0];
}
}
return self;
}


The only problem I have is that System Preferences like to crash switching from my saver to another one. But it works fine in SaverLab and as a standalone app...

Tasnu Arakun
2004.08.28, 05:27 AM
:???: no real difference appart from me doing a call to awakeFromNib after setting up the subview.

arekkusu
2004.08.28, 05:56 AM
Your screensaver target doesn't need a nib, except for your configure panel...

Tasnu Arakun
2004.08.28, 07:51 AM
it doesn't have a nib - it has been deactivated. awakeFromNib is just a place as good as any to do the opengl setups.

Tasnu Arakun
2004.12.21, 08:01 PM
i managed to fix it (almost). this time i created a new project instead of trying to add a new target to an existing project. somehow it seems there's more to screensavers than just a bundle with suffix .saver using the screensaver framework. maybe i aught take a closer look at the target settings.

however for some reason blending and texturing don't work and i can't get the preview to display. i call initWithFrame: pixelFormat: and awakeFromNib from the ScreenSaverView, but otherwise the code looks just like my fully working test application. i can get blending to work by moving glEnable.( GL_BLEND ) and glBlendFunc( ... ) from awakeFromNib to the drawRect: method. quite odd.

i did a search and found this relevant thread: http://www.idevgames.com/forum/showthread.php?t=7820. it seems to discuss a similar problem. no solution unfortunately.

Tasnu Arakun
2004.12.27, 03:47 PM
another hint - it seems the NSBitmapImageRep that i create to use as a texture is not properly initialized in the screensaver. anybode have any idea why that is?

i checked the dimensions of the image...

NSLog( @"dimensions: %f, %f", [ img size ].width, [ img size ].height );

...and got the following output:
application: dimensions: 128.000000, 128.000000
screensaver: dimensions: 176.000000, -0.000000


here's some code:


- ( void ) loadTextures {
NSString * path;
NSBundle * bundle = [ NSBundle mainBundle ];

glGenTextures( 1, &textures[ 0 ] );

path = [ bundle pathForResource:@"star" ofType:@"png" ];
NSBitmapImageRep * img = [ NSBitmapImageRep imageRepWithContentsOfFile:path ];
unsigned char * bitmapData = [ img bitmapData ];

glBindTexture( GL_TEXTURE_2D, textures[ 0 ] );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 128, 128,
0, GL_RGBA, GL_UNSIGNED_BYTE, bitmapData );
}

Steven
2004.12.27, 11:01 PM
Are you sure that awakeFromNib is called even when you don't have a nib file to awake from?

Tasnu Arakun
2004.12.28, 04:25 PM
Are you sure that awakeFromNib is called even when you don't have a nib file to awake from?

pretty much since i do the call myself from the screensaverview's init. plus i have some information printed using NSLog() so i know it has been called. actually i recently renamed the method since i need to pass some information with it - (but it doesn't change anything).

Tasnu Arakun
2005.08.14, 06:05 PM
Hmm. Maybe I should have mentioned that I managed to solve this problem eventually. The problem was me trying to add a new target to an existing project. When i created a new project of type screensaver and copied all of my files over things worked fine. (Well, almost!)

Steven
2005.08.14, 07:39 PM
Maybe it had something to do with the primary class being set wrong. That sounds like a likely problem...