Slick Forums

Discuss the Slick 2D Library
It is currently Thu Jun 20, 2013 8:36 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sat Apr 28, 2012 11:12 pm 
Offline

Joined: Mon Feb 13, 2012 6:31 pm
Posts: 40
Hello, I'm drawing 500 units of an image of rain using drawEmbeded method. I want to rotate the image by 40 to -40 degrees depending on the wind that affects rains but it seems setRotation method doesn't work with drawEmbeded. Is there any way to rotate the image? All the 500 rains should have same degree of rotation, and use the same image. thanks.


Top
 Profile  
 
PostPosted: Sat Apr 28, 2012 11:51 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1477
Image.setRotation depends on OpenGL's glRotate/glTranslate, which won't work within startUse/endUse (this is simply an OpenGL limitation).

Instead, to rotate within startUse/endUse, you need to transform the vertices before passing them to the GPU.

I've added this functionality to the dev branch on bitbucket: Image.drawEmbedded(x, y, width, height, rotation)

The downside is that it needs to perform the rotation transform every time you call drawEmbedded. If you are finding this to be a bottleneck (which it probably won't be...) then you can use something like this utility which would allow you to store the transformed vertices instead of calculating the rotation more than necessary.

--

For those wondering:
Why overload with a rotation parameter when Image has setRotation/getRotation? Here's my rationale for overloading and ignoring getRotation: (a) IMO it is a design flaw to have Image store things like alpha/rotation, (b) drawEmbedded has never relied on getAlpha/getRotation in the past, (c) to maintain consistency with the drawEmbedded method which draws a sub image (i.e. a "fresh copy" so to speak, as if we used getSubImage to draw).

The Image class is a bit of a mess; I'm doing what I can to clean it up when I have time. :)


Top
 Profile  
 
PostPosted: Sun Apr 29, 2012 4:25 am 
Offline

Joined: Mon Feb 13, 2012 6:31 pm
Posts: 40
Thank you that utility class worked :) Before using that, I tried preparing rotated image by calling the method below, before start drawing 500 rains with drawEmbeded but somehow it lowered my FPS greatly.

Code:
   var rain_image = new Image(32, 64)
   var rain_g = rain_image.getGraphics()

   def prepare_image(r: Float) {
      rain_g.setBackground(Color.black)
      rain_g.clear()
      rain_g.rotate(16, 0, r)
      rain_g.drawImage(rain_image_original, 8, 0)
      rain_g.flush()
   }
onRender, call prepare_image once then rain_image.startUse() and rain_image.drawEmbeded() 500 times


Anyway xD Could you possibly add scaling feature to the utility like Image class' drawEmbedded(float x, float y, float width, float height)? I still can't seem to understand native openGL codes much.


Top
 Profile  
 
PostPosted: Sun Apr 29, 2012 5:31 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1477
Why not just use the drawEmbedded method which was added to Image in the dev branch? There are also a lot of other bug fixes going on that would be worth adding to your project. :)

Now that it's in the Slick codebase, the utility class I had earlier is obsolete (unless you are running into a CPU bottleneck when rotating the vertices, which seems unlikely).


Top
 Profile  
 
PostPosted: Sun Apr 29, 2012 6:40 am 
Offline

Joined: Mon Feb 13, 2012 6:31 pm
Posts: 40
I think I'm going to try the one in the dev branch. Might be a silly question but do you have to build the dev version yourself and make whole set of jar files like the slick2d official releases has to use it? Or you can just use specific class? I'm not sure how everyone is doing it :(


Top
 Profile  
 
PostPosted: Thu May 03, 2012 12:15 pm 
Offline
Regular
User avatar

Joined: Wed Apr 27, 2011 3:29 pm
Posts: 197
Location: United State of California
I'm not sure how everyone else is doing it either. I go to this url: https://bitbucket.org/kevglass/slick . Then I click "branches >> development" Finally, I click "sources >> zip" to download a zip file that contains the entire library. I make a new project with the source files and compile the jars myself.

_________________
Current Testing Machine:
Windows 7 x64, 4GB RAM DDR3, 3.3ghz AMD Athlon II X3 455, AMD Radeon HD 6800 series.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


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:  
Powered by phpBB® Forum Software © phpBB Group