Slick Forums

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

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Modulate Image Colors
PostPosted: Sat Jun 09, 2012 7:20 pm 
Offline

Joined: Mon Jun 04, 2012 3:08 pm
Posts: 4
Is there not a built-in way to modulate (multiply) all colors on an image, i.e. color a grayscale image? I wrote one myself just fine; just wondering if I missed anything.


Top
 Profile  
 
PostPosted: Sun Jun 10, 2012 11:09 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
Since we don't have direct access to a texture's pixel data in OpenGL, you need to go about this a little differently. Here's some options...

  • Use "vertex colouring" which looks like this in Slick:
    Code:
    image.draw(30, 30, Color.red);

    Using the above, every color in your image will be multiplied by red (RGB = 1, 0, 0). For example, all white pixels (RGB = 1, 1, 1) will turn red. This is very fast since it's done in hardware, and you can modulate it differently by using texture combiners (OpenGL).
  • "Upload" an array of pixel data to the GPU. This is probably what you're doing now, using ImageBuffer (i.e. constructing a texture from an array of pixels). This is relatively slow since (a) ImageBuffer requires creating a new OpenGL texture, (b) ImageBuffer isn't very optimize, (c) you aren't changing the pixel data on the GPU and (d) the upload is not asynchronous (by default) so relying on it heavily may affect performance. For a more efficient and more flexible way of modifying pixel data than ImageBuffer, look into my PixelData utility.
  • Fragment shaders. This is generally accepted as the "best" and most efficient manner of modifying images on a per-pixel (or "fragment") basis. This is done in hardware, so it's as fast as vertex colouring. It's generally the way you would do things like invert colours, polar coordinates, advanced blend modes, etc. GLSL is a pretty big topic and it's well outside the scope of Slick, but there are some shader utilities and examples in the dev branch. This site is a really interesting place to learn/dissect GLSL.


Top
 Profile  
 
PostPosted: Mon Jun 11, 2012 2:18 pm 
Offline

Joined: Mon Jun 04, 2012 3:08 pm
Posts: 4
Ah, thanks! You were right; I am using ImageBuffer to modulate each color using setRGBA then converting it to an image. But vertex coloring looks like the simplest solution right now; I think I'll go with that. Thanks for the response! :)


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 2 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