Page 1 of 3

Long Term Texture / NSBitmapImageRep issue

Posted: Mon Mar 06, 2006 1:09 am
by milinks
There has been an issue since the inception of the Windows port of oolite in relation to the recognition of textures/ images. I would suggest the error

Code: Select all

initWithFocusedViewRect: failed
is spat out in the stderr.txt every time the game is played. This would now appear to be quite a significant stumbling block. If i am correct, due to the use of GNUstep within windows oolite and its faiure to recognise the images within, further expansion is very limited. Correct me if i am wrong, but from the extensive reading on this, it appears that windows just cannot recognise this part of the GNUstep code that id's the image code. Ive mentioned about docked screens in the suggestion box, to implement further atmospheric images within oolite such as from Elite plus etc, but unless this issue can be overcome, then static images cannot be used from OXP's or inbuilt missions for Windows.

Now here comes the thing..... I Definately do not have the ability to rectify this :oops: But if anyone has any idea as to how this is caused, or can be rectified, just simply point me in the direction, and i will try to do the rest, as it is seriously hindering me at the moment with the ideas put forward in the Suggestions forum.

For info, what are the thoughts of other windows users. Has anyone, engaged in the Nova mission as yet, as this appears to be the only mission as yet that uses a static image, rather than a ship model. Has any Windows user had displayed the solar.png - which is an easy test for this.

I would welcome opinions / suggestions re this please. ( oh yeas, did i mention that i would also welcome, an easy 2 minute fix to this problem :wink: )

Posted: Mon Mar 06, 2006 8:13 am
by aegidian
IIRC the PC version doesn't use any NS objects to load the image data, it uses an SDL_Surface instead. So I'm not sure where that error is coming from - although I suspect it may be to do with the missing splash-screen on the linux and PC versions.

Posted: Mon Mar 06, 2006 8:46 am
by Nic
@aegidian: Well I finally have my PC back home, although no internet, hopefully I can look into a work around for this issue soon.

I've been wondering if a new CVS build of the GNUStep for Windows might help, but haven't had time to get everything ready required to build it.

Maybe I could post on the GNUStep boards, they may already have a solution/workaround....(Or has this already been done?)

Cheers.
-Nic

ps
Oh, there does seem to be a new GNUStep released. I'll look into workarounds for this issue.

Posted: Mon Mar 06, 2006 10:45 am
by TGHC
What's your new address I'll get pizzas sent round, cleaners, decorators, nanny, landscape gardeners, just let me know. :wink:

Posted: Tue Mar 07, 2006 4:09 pm
by Nic
@TGHC: Thanks :) I could always use a good pizza :)

Had a little time to debug the problem. It's very peculiar and as you probably know stems from:

makeTextureFromImage in OpenGLSprite.m

Code: Select all

 image = [[NSImage alloc] initWithSize:textureRect.size];	// retained

    [image lockFocus];
    [[NSColor clearColor] set];
    NSRectFill(textureRect);
    [texImage drawInRect:textureCropRect fromRect:cropRect operation:NSCompositeSourceOver fraction:1.0];
    bitmapImageRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:textureRect];	// retained
    [image unlockFocus];

    [image release];				
And as we know initWithFocusedViewRect fails.

No matter what I try, I can't get initWithFocusedViewRect to work correctly. I've tried everything I can think of (but my knowledge of ObjC/Cocoa/etc is only very small).

Any suggestions?

The new GNUStep release looks like it has issues....Certainly nothing helpful.

Sorry for this terse message, I'm at work and rather busy :D

-Nic

Posted: Tue Mar 07, 2006 4:29 pm
by winston
I have the sneaking feeling you may need to write a replacement NSBitmapRep for Win32. Or build a debug version of the GNUstep libraries and step through it with the debugger (if it is failing on something trivial, it may be easiest to just modify GNUstep and ship your modded GNUstep).

Posted: Tue Mar 07, 2006 4:42 pm
by Nic
@winston:
Already looked through the GNUstep code for initWithFocusedViewRect to see why it's kicking out the error message. My ObjC is probably not good enough to track down a solution in the time I have available. Although I could try.
you may need to write a replacement NSBitmapRep for Win32
Don't even know where to begin with that. But if you have any clues let me know and i'll try to give it a go.

-Nic

Posted: Tue Mar 07, 2006 5:41 pm
by winston
A quick primer on ObjC that should make things be a little clearer and help get you bootstrapped:

In C++:

Code: Select all

SomeObject *foo=new SomeObject();
int bar=1;
foo->baz(bar);
In ObjC this would be:

Code: Select all

SomeObject *foo=[[SomeObject alloc] init];
int bar=1;
[foo baz: bar];
Just knowing that tidbit makes it a LOT easier to follow :-)
ObjC is a fairly lightweight extension of C.
Method calls in C++ (or function calls in C) are generally in the form:

Code: Select all

someObject->someFunction(arg1, arg2, arg3);

(the function defined:)
void someClass::someFunction(int arg1, float arg2, anotherClass *arg3)
{
     arg1++;
     arg3->boo(arg1, arg2);
}
and the equivalent in ObjC is:

Code: Select all

[someObject someFunction: arg1 bar: arg2 baz: arg3];

(the function defined:)
@implementation someClass
....functions....

void someFunction: (int)arg1  bar: (float) arg2  baz: (anotherClass *) arg3
{
   arg1++;
   [arg3 boo: arg1  flarm: arg2];
}

....more functions....
@end
(Well, they are actually called messages, not functions, because ObjC has a proper message passing model, but if you're coming from C, then they do a similar job to functions).
GNUstep.org has some handy tutorials, too.

Posted: Tue Mar 07, 2006 8:08 pm
by milinks
I know I'm way off base here, but.... I've been searching the web using the "how can i get Oolite to run on Windows" search factor :wink: and one thing that i read a number of times was that there isnt this type of problem with icons, and there is a "fix" for icons in win32. Its a 99% certianty i am talking rubbish.

Posted: Wed Mar 08, 2006 9:37 am
by Nic
milinks is right and I'm an idiot. Fact.

Yup there is code to make all this work. And it's obvious. And i'd seen it before and forgotten about it. And, i'm an idiot.

Ok so here's the the thing. And it's been done before with the cursorSprite code, it just hadn't been done every where. I will demonstrate below.

Code: Select all

#ifndef WIN32
	cursorSprite = [[OpenGLSprite alloc]   initWithImage:[ResourceManager imageNamed:@"cursor.png" inFolder:@"Images"]
											cropRectangle:NSMakeRect(0, 0, 128, 128)
											size:NSMakeSize(32, 32)];	// alloc retains
#else
	cursorSprite = [[OpenGLSprite alloc]   initWithSurface:[ResourceManager surfaceNamed:@"cursor.png" inFolder:@"Images"]
											cropRectangle:NSMakeRect(0, 0, 128, 128)
											size:NSMakeSize(32, 32)];	// alloc retains
There is the key part. So changing a few NSImage* to SDLImage* and a few initWithImage to initWithSurface when WIN32 is defined, gets everything working :D :D :D

So now I've got a fully functioning 1.62-4 with the planet radar thing showing correctly etc.

I should really work on getting Gusto going now and making a patch :)

-Nic

EDIT:
ps
Just compiled Gusto (trunk). Wasn't any harder than compiling normally. :)

pps
In Gusto initWithImage is only used once and that is for the addLegend function in HeadUpDisplay. So a lot less changes needed than in 1.62-4.
Also the demo at the start (where the cobra spins) the 3D graphics look very strange...but in game they are ok.

But the game runs a fair bit slower than 1.62-4. (EDIT: This might not be true, FPS values are about the same and this is a very slow machine (gfx wise))

Posted: Wed Mar 08, 2006 11:36 am
by flap
Hey ! Thank you for all your hard work everybody.

Posted: Wed Mar 08, 2006 11:48 am
by TGHC
/me rubs hands in anticipation

You guys rock

Posted: Wed Mar 08, 2006 2:06 pm
by winston
Nic wrote:
Ok so here's the the thing. And it's been done before with the cursorSprite code, it just hadn't been done every where. I will demonstrate below.
Don't forget to commit it into the 1.62 branch as well as GUSTO (the trunk) :-) (And tag it as tags/1.62-4w when you've finished)

Posted: Wed Mar 08, 2006 3:03 pm
by Nic
@winston: Do you know why on startup the intro/demo screens that show the spinning Cobra and other models aren't looking quite right. They seem to have some sides missing. I thought to begin with it might just be a lighting issue....But it looks like something else.

As soon as I know the cause of that I will release a new build for people to test. And then if that goes well, i'll try to make some sort of useful patch.

-Nic

Posted: Wed Mar 08, 2006 4:39 pm
by Rxke
That's a big yay for milinks and Nic!

Oolite-PC out of Beta soon! 8)