Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 3:54 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Modify an Image
PostPosted: Sat Feb 11, 2012 7:03 pm 
Offline

Joined: Sat Feb 11, 2012 6:57 pm
Posts: 2
Hi,

First things sorry for the few english mistakes i'm about to make, english isn't my motherlangage.

Here's my question, before using java i was programming in C++ (i was using SFML for 2d graphics). With SFML it was quite easy to modify an image because an image and the thing use to draw an Image on the screen were two totaly different things. I've been searching in the Slick documentation a way to modify an image but the only way i find was using a ImageBuffer and then make getImage() on it, but this isn't fast enough for me, so i ask you: is there a way to make fast modifications on images?

Thanks for your answers


Top
 Profile  
 
 Post subject: Re: Modify an Image
PostPosted: Sat Feb 11, 2012 7:39 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
Generally in slick you would do it like so:
Code:
Graphics g = myImage.getGraphics();

//modify the image
g.setColor(Color.red);
g.fillRect(0, 0, 15, 15);

//call this after modifications
g.flush();


Some considerations:
  • Calling getGraphics will create a new OpenGL texture. For better memory management, you should release the old texture if you no longer need it (i.e. if the modifications are intended to be permanent):
    Code:
    Texture oldTex = myImage.getTexture();
    Graphics g = myImage.getGraphics(); //myImage will now have a new texture
    // ... modify image .. //
    g.flush();
    oldTex.release(); //releases the old texture that we no longer need
  • If you need modifications on a per-pixel basis, you can use ImageBuffer. If you need something faster, you can implement your own image modification code that uses glTexSubImage2D. For something even faster, you might want to look into shaders.

What kind of modifications are you trying to do?


Top
 Profile  
 
 Post subject: Re: Modify an Image
PostPosted: Sun Feb 12, 2012 12:26 pm 
Offline

Joined: Sat Feb 11, 2012 6:57 pm
Posts: 2
I'm trying to blend two texture, for a better transition between them.


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