Slick Forums

Discuss the Slick 2D Library
It is currently Wed Nov 20, 2019 11:40 am

All times are UTC




Post new topic Reply to topic  [ 57 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
PostPosted: Fri Jan 06, 2012 9:54 pm 
Offline

Joined: Sun Jun 12, 2011 2:27 pm
Posts: 90
It has sample code slick2d+TWL (current)?


Top
 Profile  
 
PostPosted: Sun Jan 22, 2012 8:01 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
Renders a 2D Slick Image in a 3D space (with x/y/z rotation). Example:
Image

Requires lwjgl-util.jar for the GLU portion. You could do without the dependency by writing your own gluPerspective method.

The position is defined by world coordinates (0,0,0 is center). Here is an example call (notice the negative Z value to scale it down):
Code:
drawImage3D(container, myImage, 0f, 0f, -5f, 0f, 0f, 0f, null);


Code:
    import org.lwjgl.opengl.GL11;
    import org.lwjgl.util.glu.GLU;
    ...
    public void drawImage3D(GameContainer container, Image image,
                float worldX, float worldY, float worldZ,
                float xTilt, float yTilt, float zTilt, Color filter) {
        SlickCallable.enterSafeBlock();
       
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        GLU.gluPerspective(45.0f,container.getWidth()/(float)container.getHeight(),0.1f,100);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glLoadIdentity();
       
        GL11.glShadeModel(GL11.GL_SMOOTH);
        GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        GL11.glClearDepth(1.0f);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glDepthFunc(GL11.GL_LEQUAL);
        GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
       
        GL11.glLoadIdentity();
       
        GL11.glTranslatef(worldX, worldY, worldZ);
        GL11.glRotatef(xTilt, 1f, 0, 0);
        GL11.glRotatef(yTilt, 0f, 1f, 0);
        GL11.glRotatef(zTilt, 0f, 0f, 1f);
       
        image.bind();
       
        float textureOffsetX = image.getTextureOffsetX();
        float textureOffsetY = image.getTextureOffsetY();
        float textureWidth = image.getTextureWidth();
        float textureHeight = image.getTextureHeight();
       
        float x = 0;
        float y = 0;
        float width = 1f;
        float height = -image.getHeight()/(float)image.getWidth();
       
        if (filter!=null)
            filter.bind();
        else
            Color.white.bind();
        GL11.glBegin(GL11.GL_QUADS);
        //TOP LEFT
        GL11.glTexCoord2f(textureOffsetX, textureOffsetY);
        GL11.glVertex3f(x, y, 0);
        //BOTTOM LEFT
        GL11.glTexCoord2f(textureOffsetX, textureOffsetY + textureHeight);
        GL11.glVertex3f(x, y + height, 0);
        //BOTTOM RIGHT
        GL11.glTexCoord2f(textureOffsetX + textureWidth, textureOffsetY
                        + textureHeight);
        GL11.glVertex3f(x + width, y + height, 0);
        //TOP RIGHT
        GL11.glTexCoord2f(textureOffsetX + textureWidth, textureOffsetY);
        GL11.glVertex3f(x + width, y, 0);
        GL11.glEnd();
       
        SlickCallable.leaveSafeBlock();
    }


Top
 Profile  
 
PostPosted: Sun Jan 22, 2012 3:06 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Really really cool davedes! Would you mind writing a test case or something? This is cool stuff I would like to add to my engine (and you have permission for the developer forum so you post there too :))

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Sun Feb 26, 2012 10:07 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
EDIT: I've added this functionality to Slick's development branch via a new drawEmbedded method.

I needed a way to rotate and scale sprites/tiles/etc. in a texture atlas between startUse/endUse. I wrote up a small utility to do this, ImageTransform, as well as a test: ImageTransformTest. It seems to be pretty efficient; and it also does without the numerous glTranslate/glRotate calls that would usually occur every time we call Image.draw().

Basic usage:
Code:
   //We don't want to calculate a new array every time we rotate our image,
   //so we will re-use it if the rotation hasn't changed
   private final float[] vertices = new float[ImageTransform.ARRAY_LENGTH];
      
   ... init ...
      ... create our sprite sheet, get our sub images ...
   
      //This resets our shared vertex array to the new rotation (90 degrees clockwise)
      //Alternatively, we could use AffineTransform or Slick's geom Transform to get the point array
      ImageTransform.updateVertices(mySubImage, vertices, 90f);

   ... render ...
      myImage.startUse();
      //render the sub image with our new transform by specifying the vertex data
      ImageTransform.drawEmbedded(mySubImage, x, y, vertices)
      myImage.endUse();


Source code + test:
http://www.mediafire.com/?wwmw6wby35b2ubx


Last edited by davedes on Sun Mar 11, 2012 4:07 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Mon Feb 27, 2012 9:04 am 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
again awesome! I mean, really awesome!

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Wed Feb 29, 2012 1:26 am 
Offline
User avatar

Joined: Mon Feb 27, 2012 11:21 pm
Posts: 24
Location: Spain
Hi, I'm new to the forums so I would like to start sharing something I've been working for the last month.

I'm from Spain so I created a Blog and "translated" some of the basic Slick2D tutorials from the Wiki to Spanish, I also have made some new simple tutorials about sound management and user input, loading Tilemaps, etc. And I'm going to continue working on various aspects of Slick2D.

The bad news is that all the posts on the blog are written in Spanish, except the code, which is in English. There are also a lot of images during the tutorials, so hopefully it can be helpful for everybody.

Here is the Slick2D category on my blog using google to translate:
http://translate.google.es/translate?sl ... 2F&act=url

The translation it's really bad, but if you don't know spanish you can see what's the post about and just look to the code and images.

That's all, I hope it is helpful for somebody, I offer myself to translate any post if there is someone very interested on it.


Edit: Looks like the code tags get messed up with google translate, visit the regular site if interested on the source...

_________________
Sorry for my English, trying to improve!


Top
 Profile  
 
PostPosted: Tue May 22, 2012 8:35 pm 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
Can anyone help me here, I'm learning slick, and lwjgl. I'm trying to program a simple game to click and hold on image, and move it around, but I managed to make it so that when I click on image, it centers to my mouse cursor, I want it to just move, without centering to mouse cursor, similar to moving icons on our OS .


Top
 Profile  
 
PostPosted: Thu May 24, 2012 9:24 am 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
override the mousesDragged method in a BasicGame/BasicGameState. Then have a Vector2f which holds the position. in the mouseDragged method you do this:
Code:
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
   position.x += (newx - oldx);
   position.y += (newy - oldy);
}


then in render just draw the image at the position and done.

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Thu Aug 09, 2012 2:03 pm 
Offline

Joined: Tue Jul 31, 2012 3:08 pm
Posts: 16
Heres a link to some beginner video tutorials for Slick
http://www.youtube.com/playlist?list=PL210C2267A8922854&feature=plcp
They go over setting up eclipse for slick and introduce people to basic slick concepts and bits of code
There are currently 21 videos but the creator seems intent on making more

_________________
"I reject your reality and substitute my own" - Mythbusters


Top
 Profile  
 
PostPosted: Wed Aug 22, 2012 9:45 pm 
Offline

Joined: Tue Aug 21, 2012 9:16 pm
Posts: 16
I agree with the above. Thenewboston vids on YouTube really helped me get started. Worth a look.

If you get time, or have the need, they have vids covering tutorials on all sorts on their website. You just got to put up with Bucky's levels of self-excitement!!


Top
 Profile  
 
PostPosted: Thu Oct 11, 2012 7:35 pm 
Offline
User avatar

Joined: Tue Jul 17, 2012 11:27 am
Posts: 67
Short question: Which is faster?
  • Render little bigger images
  • Render many smaller images

_________________
Open source isometric engine made with libGDX: http://wurfelengine.net


Top
 Profile  
 
PostPosted: Thu Oct 11, 2012 8:23 pm 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 290
Here is a good thread about large sprite sheets:
viewtopic.php?f=3&t=5633


Top
 Profile  
 
PostPosted: Fri Oct 12, 2012 10:46 am 
Offline
User avatar

Joined: Tue Jul 17, 2012 11:27 am
Posts: 67
dayrinni wrote:
Here is a good thread about large sprite sheets:
viewtopic.php?f=3&t=5633

This doesn't really help me. I am referring to the case that you have one sprite sheet.

_________________
Open source isometric engine made with libGDX: http://wurfelengine.net


Top
 Profile  
 
PostPosted: Fri Oct 12, 2012 2:38 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
Rendering fewer big images will be more performant than many little images.


Top
 Profile  
 
PostPosted: Sat Oct 13, 2012 2:12 pm 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 290
Cbeed wrote:
dayrinni wrote:
Here is a good thread about large sprite sheets:
viewtopic.php?f=3&t=5633

This doesn't really help me. I am referring to the case that you have one sprite sheet.


Sorry, I didn't mean that for you - my bad. I should of said that in my original post.

I wanted to put that thread on this thread because it was a great one (IMO) for people to use.

My bad!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 57 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 216 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group