littleflylongbow / guichan

Automatically exported from code.google.com/p/guichan
Other
0 stars 0 forks source link

drawImage usage Problem #126

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. I got guichan running and have got this code: 
http://codepad.org/2UJ0qXho
2. If I compile it everything works but it starts and crashes.
3. This Error is returned: Clip stack is empty, perhaps you called a draw 
funtion outside of _beginDraw() and _endDraw()?

What is the expected behaviour? What happens instead?
Actually I want the image to be displayed - it crashes.

What version of the product are you using? On what operating system? 
Which back-end (SDL/Allegro/OpenGL/other)?
0.8.0, Mac OS 10.5, SDL

Please provide any additional information below.
I thought this would help me but it doesnt:
http://guichan.sourceforge.net/api/0.8.0/classgcn_1_1Graphics.html#ed3
0c3aa213a2d225b1c119b3f5f8d60

I am sure I made a pretty stupid mistakes but I asked some more 
experienced programmers via IRC and noone could help me.

Original issue reported on code.google.com by littlega...@web.de on 21 Dec 2009 at 2:51

GoogleCodeExporter commented 8 years ago
Perhaps you should read the error message. You are calling graphics->drawImage
(quit_game, 0, 0); in the init function which is not allowed, you can only call 
draw 
after graphics->_beginDraw() and before graphics->_endDraw() has been called. 
These 
functions are called automatically in Gui::draw, so widgets that are drawn 
during 
Gui::draw doesn't need to bother calling _beginDraw and _endDraw.

Original comment by olof.nae...@gmail.com on 21 Dec 2009 at 4:56

GoogleCodeExporter commented 8 years ago
gui->logic();
graphics->_beginDraw();
gui->draw();    
graphics->drawImage(background, 0, 0);
graphics->_endDraw();

SDL_Flip(screen);

I replaced the wrong code with this - it runs now but I can not see the image, 
what 
do I do wrong?

PS: The MouseListeners are amazing, never added mouse support that easily and 
fast.

Original comment by littlega...@web.de on 22 Dec 2009 at 9:29

GoogleCodeExporter commented 8 years ago
Try this instead:
gui->logic();
gui->draw();
graphics->_beginDraw();
graphics->drawImage(background, 0, 0);
graphics->_endDraw();

SDL_Flip(screen);

Note that it would be better if you drew the image as part of the GUI's drawing
routine instead.

Original comment by jaxad0...@gmail.com on 23 Dec 2009 at 2:24

GoogleCodeExporter commented 8 years ago
How would I do that?

Original comment by littlega...@web.de on 23 Dec 2009 at 8:24

GoogleCodeExporter commented 8 years ago
You'd create a subclass of gcn::Widget and reimplement its virtual draw method. 
Then 
you'd place that widget where you want it go get drawn.

Original comment by b.lindeijer on 23 Dec 2009 at 8:35

GoogleCodeExporter commented 8 years ago
Well, this issue's been declared invalid, but I personally think that the 
responses
so far haven't been too helpful at all. First off, Jaxad's solution isn't a real
solution, so don't try it. It's a fairly horrible hack, and isn't anything 
that'll
get you anywhere.

What I would suggest is to pass your image to a new gcn::Icon, and then add 
that icon
to the top widget. That is a far better practice than what you're trying to do, 
and
actually attempts to use GUIChan, instead of trying to fight against it.

If that isn't clear, then what I'm saying is this. Replace this:
    quit_game = gcn::Image::load("./GUI.app/Contents/Resources/close_n.png");
    graphics->drawImage(quit_game, 0, 0);

with this:
        quitIcon = new gcn::Icon("./GUI.app/Contents/Resources/close_n.png");
        top->add(quitIcon);

You will then benefit from actually using GUIChan as intended, instead of 
trying to
hack images on top of it. Oh, and as a short answer as to why your image doesn't
draw, the real answer is that it does, except that you are drawing the image 
once,
then the SDL drawing polling keeps redrawing over it, and it never redraws again
throughout the life of the program.

Hope this is more helpful than the previous bits of advice.

Original comment by irar...@gmail.com on 23 Dec 2009 at 9:42

GoogleCodeExporter commented 8 years ago
I tried this aswell but it doesnt show up. No error occurs though and no stderr 
message. Its pretty confusing. I basically want to have an image instead of 
this odd 
grey:
http://img526.imageshack.us/img526/3043/picture4ox.png

And when I do the stuff you said it runs well but I can not see the image. I 
tried this 
aswell: 
        background = gcn::Image::load("./GUI.app/Contents/Resources/bg.png");
    background_icon = new gcn::Icon(background);
    background_icon->setPosition(0, 0);
    top->add(background_icon);
    top->moveToBottom(background_icon);

...

Thanks for all the help!

Original comment by littlega...@web.de on 23 Dec 2009 at 10:44

GoogleCodeExporter commented 8 years ago
Did you try doing this?

top->setOpaque(false);

You better make sure that you have a background to substitute for the whole 
program
area, though.

Original comment by irar...@gmail.com on 23 Dec 2009 at 5:18

GoogleCodeExporter commented 8 years ago
Ira, feel free to be more verbose or suggest other solutions, but please avoid 
bashing 
other people who also tried to help. It's not nice.

Original comment by b.lindeijer on 25 Dec 2009 at 1:52

GoogleCodeExporter commented 8 years ago
Ira, the issue has been declared invalid because this is an issue tracker, not 
a forum, 
and the stated issue is _not_ an issue, it is excpected behaviour.

We have an issue with images not in 32bit format, what is the format of your 
image? Try 
to convert it to 32bit if it's not already.

Original comment by olof.nae...@gmail.com on 25 Dec 2009 at 3:04

GoogleCodeExporter commented 8 years ago
It was that 32bit thing. :| Sorry for all the problems you had because of me, 
it works 
fine now, though. Thanks for your help.

Original comment by littlega...@web.de on 27 Dec 2009 at 10:18

GoogleCodeExporter commented 8 years ago
No need to apologies, the 32bit issue is in fact a bug in Guichan which we 
haven't been 
able to resolve yet. I'll keep this issue invalid because we already have an 
issue 
about the 32bit issue.

Original comment by olof.nae...@gmail.com on 27 Dec 2009 at 2:28