Display two Slick2d Graphics side by side with "World Clip"

Started by overjag, October 20, 2014, 13:01:45

Previous topic - Next topic

overjag

Hello,

I'm using LWJGL and Slick2d. I want to use "Graphics" (http://slick.ninjacave.com/javadoc/org/newdawn/slick/Graphics.html), it's something like a "Canvas", you can draw images and so on. I'm using...
    Graphics g = new Graphics();
    g.setWorldClip(50, 50, 250, 250);

... so that I can draw something and rotate it and it shows only what fits into that area (50, 50, 250, 250). Fine, this works great for me. Now I want to have another graphic that does *nearly* the same.

So the result should be one "Graphics" left and one "Graphics" right. Now my problem is not what the "Gpahics" looks like, that workes, but as soon as I add a second "Graphics", the first "Graphics" does no longer show up.

Before the while-loop for the display I've this code:
    Graphics g1 = new Graphics();
    g1.setWorldClip(50, 50, 250, 250);
    Graphics g2 = new Graphics();
    g2.setWorldClip(350, 50, 250, 250);


When I delete or out-comment all g2-related code, g1 does show up again. I want that g1 and g2 shows up side by side. Do you know why g1 does not show up?

When I out-comment both "setWorldClip" functions, both Graphics show up but ofc not like I need them...

BTW: Is there a better documentation than http://slick.ninjacave.com/javadoc/org/newdawn/slick/Graphics.html ? It's a paint because it's poor documentated...

kappa

This is not really the correct forum for Slick related questions and you should post on the Slick one.

In any event, you could solve this problem using one Graphics object rather than two.

1) Just call Graphics.setClip() for the left view then draw on it
2) then Graphics.clearClip() and Graphics.resetTransform()
3) then call Graphics.setClip() again for the right view and draw on it.

Above should fine unless you have some other reasons for needing two Graphics?

Another option if you really need two graphics is to get the graphics of an Image (use one image for the left side and one for the right side)

e.g.

1) Image leftImage = new Image(width, height);
2) get image graphics object using "Graphics g = leftImage.getGraphics()"
3) Draw on graphics object and after you are done don't forget to call g.flush();

Do the same for the second image and draw them as needed.

overjag

Thanks for the fast reply. I'll search a Slick forum and ask there as well.

I'll try your first suggestion. There is no need for two Graphics but the Images I use (and rotate) are bigger than the area I want to be have visible (that's why Im using world clip). I need that left and right and when I've only one Graphics, the big images could "crash" (the last picture lies then maybe a few pixels above the other). Btw, here is my current code snippet:

Graphics graphicsLeft = new Graphics();
    graphicsLeft.setWorldClip(50, 50, 250, 250);
    Graphics graphicsRight = new Graphics();
    graphicsRight.setWorldClip(300, 50, 250, 250);
    
    while(!Display.isCloseRequested() && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && !Keyboard.isKeyDown(Keyboard.KEY_DELETE)) {
        
        // LEFT
        graphicsLeft.drawImage(img, 0, 0); // Image is greater as world clip (50, 50, 250, 250), it should not show what lies outside of that area 
        graphicsLeft.rotate(400, 400, 1);
        // [...]
        
        // RIGHT
        graphicsRight.drawImage(img, 0, 0); // Image is greater as world clip (50, 50, 250, 250), it should not show what lies outside of that area 
        graphicsRight.rotate(500, 500, 1);
        // [...]
        
        Display.update();
        Display.sync(30);
    }

overjag

By using "setClip" the window remains black whatever I do  :-\

overjag

But I've an idea that seems to work: I draw the left side as standard image. It's too big but that does not matter here. For the right image I use a Graphic with world clip, so that it does not lie over the first image. And yup, it's a bit dirty but does what I want. But for some reason my Graphics (right side) does not rotate now, but I guess and hope that's just because I did something wrong what I can fix soon. But now I need something to eat, cheers

overjag

Nope. I'm swiming from problem to problem. The Graphics (right side) does not rotate, no matter what I do. This is now not in my test project but in my real project. I don't know and I don't have an idea of what's wrong. But the rotate-method just does NOTHING here.

I hope the work on this part of the project is soon over, otherwise I'll suffer from serious depressions soon -.-


P.S. NO Graphics do rotate in this project. This means there is something wrong with the "context" in which I use Graphics, but Ive no idea...


EDIT: I solved it. It works now.