Slick Forums

Discuss the Slick 2D Library
It is currently Sat Apr 19, 2014 1:48 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Blend modes
PostPosted: Mon Jan 02, 2012 10:40 am 
Offline

Joined: Mon Jan 02, 2012 10:24 am
Posts: 4
Hi everyone,

I'm trying to deal with a problem I encountered using the graphicss blend mode with Slick2D.
I want to use the ADD blend mode to highlight a part of a background image.

So we have the background :
Image

Then the image we want to highlight the background with :
Image

I was expecting something like that :
Image


But something like that happens :
Image


I just used a code like that :
Code:
void render(Graphics g)
{
g.setDrawMode(Graphics.MODE_NORMAL);
g.drawImage(backgroundImage, 0, 0);

g.setDrawMode(Graphics.MODE_ADD);
g.drawImage(highlightImage, hx, hy);
}


Do you have an idea of the source of the problem ?


Top
 Profile  
 
 Post subject: Re: Blend modes
PostPosted: Tue Jan 03, 2012 5:47 am 
Offline

Joined: Mon Dec 05, 2011 1:36 pm
Posts: 27
There is no need for you to change the blending mode all you need to do is load the images as org.newdawnsoftware.slick.Image and use the draw method. Make sure you draw the background first, and then the highlight. I would refrain from using org.newdawnsoftware.slick.Graphics to draw images as it is not needed but that is just a word from the wise.

EDIT: are you trying to achieve a highlighted affect or just plain draw the images? if so i will take another look


Top
 Profile  
 
 Post subject: Re: Blend modes
PostPosted: Tue Jan 03, 2012 7:32 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
If you want to use additive blending mode then you need to make the areas you don't want to modify black (in your additive texture).

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: Blend modes
PostPosted: Tue Jan 03, 2012 8:22 pm 
Offline

Joined: Mon Jan 02, 2012 10:24 am
Posts: 4
Quote:
Make sure you draw the background first, and then the highlight. I would refrain from using org.newdawnsoftware.slick.Graphics to draw images as it is not needed but that is just a word from the wise.


It's just because I prefer to write Graphics.drawImage() (programming legacy with Java graphics). But if you tell me that is slower than Image.draw(), I will reconsider it.

Quote:
EDIT: are you trying to achieve a highlighted affect


That's it. I want to make an effect like the Photoshop additive layer mode over the landscape behind.

Quote:
If you want to use additive blending mode then you need to make the areas you don't want to modify black (in your additive texture).


I see ...
I thought that the pixels with an alpha value equal to zero would not affect the drawing.

So I have to add a black background to the highlight image, I'm right ?



EDIT : I have just tried it and it works. Thank you !
But could you explain a little more the fact that I have to put a black background ?


Top
 Profile  
 
 Post subject: Re: Blend modes
PostPosted: Wed Jan 04, 2012 3:08 pm 
Offline

Joined: Tue Jan 03, 2012 3:58 am
Posts: 5
Black is probally your transparency color.


Top
 Profile  
 
 Post subject: Re: Blend modes
PostPosted: Wed Jan 04, 2012 9:03 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
You should read about glBlendFunc it explains how it works (look at GL_ADD).

_________________
TWL - The Themable Widget Library


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: Dan, Jon 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