Slick Forums

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

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Solid Image
PostPosted: Sat Feb 11, 2012 5:45 pm 
Offline

Joined: Fri Dec 30, 2011 11:29 pm
Posts: 12
Hi,
I'm currently trying to create solid image with just hight width parameters added.
I made pretty fast code which loops every pixel in image and sets its color, but it looks too much work.
For example in 2000x2000 image buffer.setRGBA(x, y, r, g, b, a); should be called 4 000 000 times..
Is there any smarter way to do this?

Code:
public Image getImage(int width, int height, int r, int g, int b, int a) {
   ImageBuffer buffer = new ImageBuffer(width, height);
   for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
         buffer.setRGBA(x, y, r, g, b, a);
      }
   }
   return buffer.getImage();
}


Top
 Profile  
 
 Post subject: Re: Solid Image
PostPosted: Sat Feb 11, 2012 7:54 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1477
If the color has the same RGBA components, this is the easiest way of writing it:
Code:
    img = new ImageBuffer(width, height);
    Arrays.fill(img.getRGBA(), (byte)255);
    return new Image(img);


The above produces a white, opaque texture. If you are looking for something more efficient and more flexible (i.e. specific colors), check out my changes to EmptyImageData here:
viewtopic.php?f=27&t=4454

Some considerations:
  • Slick uses power-of-two sizes for textures, so your 2000x2000 image will be stored as a 2048x2048 OpenGL texture.
  • You might be pushing it with your texture size; if compatibility with older systems is important to you, it would be safer to use no greater than 1024x1024 textures
  • If you plan to change the texture with getGraphics, don't bother creating a coloured texture -- see here
  • Why do you need a solid texture anyways? And why does it need to be so large? Maybe there is a better way of doing whatever it is you're trying to do...


Top
 Profile  
 
 Post subject: Re: Solid Image
PostPosted: Mon Feb 13, 2012 3:33 pm 
Offline

Joined: Fri Dec 30, 2011 11:29 pm
Posts: 12
Thanks for the replay!
I'm aware of power of two rule, this is not my first lwjgl engine, I just used 2000x2000(it's image not texture size, i used it so i could easier multiply it) as an example.
The constructor new Image(int, int, Color) you described in your topic is pretty much all i needed.
The texture i want is screen width x height, i need this image to use it as my fade in, fade out, dim mechanism.
I need image because i have already created animation system, so with this image I could nicely fade in and out.
Yes there is probably better way, but I'm too lazy to implement it :) .
And no, compatibility with older systems is not important.

EDIT:
I have just figured out that all kind of transissions already exist in states.transition package :P


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

All times are UTC


Who is online

Users browsing this forum: No registered users 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