|
-
Feb 23rd, 2003, 08:23 PM
#1
Thread Starter
Lively Member
alphablending?
hey guys
i am sure some of you guys have used sonique or the new opera 7..have you noticed (especially in sonique) how pressing a button results in a nice effect?it looks lke it is being pressed slowlly (sortof)..is that called alphablending?
anyways, does anyone know of a tutorial or the like where i could learn the basics of those effects? thanks in advance (all i have found oin the web is for directX)
-
Feb 23rd, 2003, 08:28 PM
#2
Thread Starter
Lively Member
btw, i wouldn't be using any actual buttons..just images (png)..
-
Feb 23rd, 2003, 08:29 PM
#3
Hyperactive Member
Search the MSDN for Alphablend, there is a API for it.(win98 and above)
[Edited: I think the API is for BMP only]
-
Feb 23rd, 2003, 08:32 PM
#4
Thread Starter
Lively Member
is it hard to implement? because i am not on windows..
-
Feb 23rd, 2003, 08:41 PM
#5
Hyperactive Member
Err... shouldn't be hard for me. The formula is given in the MSDN. You have to do it pixel by pixel
You have to make sure the results are within 0-255.
Eg,After calculation, red component is the biggest number of the 3 components and is more than 255, you have to set it to 255. If you scale down red by 20%, green and blue have to be scaled down by 20% too, no matter whether they are bigger than 255 in the first place. The same thing applies to results less than 0.
-
Feb 23rd, 2003, 08:43 PM
#6
Thread Starter
Lively Member
cool thanks i'll look at that
-
Feb 23rd, 2003, 08:53 PM
#7
Hyperactive Member
if any color component is more than 255.0, use the code below to make it positive.
FinalRed, FinalGreen and FinalBlue are floats.
nFinalRed, nFinalGreen and nFinalBlue are integers.
Code:
if(FinalRed>=FinalGreen && FinalRed>=FinalBlue)
{
if(FinalRed>255.0f)
{
nFinalRed=255;
nFinalGreen=(int)(FinalGreen/FinalRed*255.0f);
nFinalBlue =(int)(FinalBlue/FinalRed*255.0f);
}
else
{
nFinalRed =(int)(FinalRed);
nFinalGreen=(int)(FinalGreen);
nFinalBlue =(int)(FinalBlue);
}
}
else if(FinalGreen>=FinalRed && FinalGreen>=FinalBlue)
{
if(FinalGreen>255.0f)
{
nFinalRed =(int)(FinalRed/FinalGreen*255.0f);
nFinalGreen=255;
nFinalBlue =(int)(FinalBlue/FinalGreen*255.0f);
}
else
{
nFinalRed =(int)(FinalRed);
nFinalGreen=(int)(FinalGreen);
nFinalBlue =(int)(FinalBlue);
}
}
else if(FinalBlue>=FinalRed && FinalBlue>=FinalGreen)
{
if(FinalBlue>255.0f)
{
nFinalRed =(int)(FinalRed/FinalBlue*255.0f);
nFinalGreen=(int)(FinalGreen/FinalBlue*255.0f);
nFinalBlue=255;
}
else
{
nFinalRed =(int)(FinalRed);
nFinalGreen=(int)(FinalGreen);
nFinalBlue =(int)(FinalBlue);
}
}
Last edited by transcendental; Feb 26th, 2003 at 04:40 AM.
-
Feb 23rd, 2003, 09:13 PM
#8
Thread Starter
Lively Member
thanks a lot..one thing though: is this the formula(s) you were talking about?
http://msdn.microsoft.com/library/de...tmaps_3b3m.asp
thanks again
-
Feb 23rd, 2003, 09:17 PM
#9
Thread Starter
Lively Member
i think this is what you meant:
Blend = Alpha * Source + (1 - Alpha) * Destination
what exactly do the variables stand for? i dont understand what they represent.
basically i would have to do this for every pixel, and for all 3 chanels?
-
Feb 24th, 2003, 12:04 AM
#10
Hyperactive Member
Originally posted by paneb
i think this is what you meant:
Blend = Alpha * Source + (1 - Alpha) * Destination
what exactly do the variables stand for? i dont understand what they represent.
Yes, that is the formula I meant. Alpha is from 0 to 255, Alpha means (degree of) transparency(0 is transparent and 255 is opaque.)
Source means the source pixel and destination means the destination pixel; Basically they are the 2 you want to mix together to form the effect.
Blend is the result.
Originally posted by paneb
basically i would have to do this for every pixel, and for all 3 chanels?
Yes, you have to do it for all the 3 primary colors of every pixel.
-
Feb 24th, 2003, 06:49 AM
#11
What system are you on? Linux?
You might want to use libart, it supports alpha blending.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 24th, 2003, 08:44 AM
#12
Thread Starter
Lively Member
yea i know about libart..but i wanna try writing the function though.. 
i have one question: i havent' done much gfx stuff..how would go about calculating the Blend for each pixel? i mean how would i sotre the pixels i have worked on, and how would i move on to the next one? would i need to create an arrya or something?
-
Feb 24th, 2003, 12:41 PM
#13
Depends on what you want to do. Basically you're drawing to a target. The target might be the screen or a memory buffer. So for each pixel you get the two source pixels, blend them together and store the result at the output location. For efficiency this should be a memory location which you then blit to the screen all at once.
transcendental:
Given the formula here Alpha ranges from 0.0 to 1.0. If it was from 0 to 255 then the formula would be
Blend = Alpha * Source + (255 - Alpha) * Destination
or in general
Blend = Alpha * Source + (AlphaRange - Alpha) * Destination
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 25th, 2003, 08:28 AM
#14
Hyperactive Member
If it was from 0 to 255 then the formula would be
Blend = Alpha/255.0 * Source + (1.0 - Alpha/255.0) * Destination
-
Feb 25th, 2003, 12:00 PM
#15
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|