Alpha blending...

Well im using full screen exlusive mode and active rendering, with page flipping and buffer strategy.

Now... on top of the actual game, i want to draw a "console" thing.

I want this to use alpha blending... so the background behind the console is shaded (but still visible).

Now how do i procceed to do this?

Create the console as an image, but then in the rendering... how do i draw that image upon the graphics that i get from the bufferstrategy etc?

[483 byte] By [Hephos] at [2007-9-27 22:02:43]
# 1
Lookup PixelGrabber and ImageMemoeySource. I'm not exactly sure how to do that, But I've seen that done.
javatypo at 2007-7-7 11:57:53 > top of Java-index,Other Topics,Java Game Development...
# 2

Hey, just use colors with low alpha levels when filling the console.

g.setColor(new Color(0,0,0,100)); // Transparent black

So if you draw the game first, then the console with tranparent colors, you'll see through to the game.

Alpha blending is used when you need to blend a sprite image with the background.

Heres some code that does alpha blending with image pixels.

public static Image alphaBlendPixels(int [] imageData,int width,int height,int alpha,Component comp)

{

for(int i=0; i<width; i++)

{

for(int j=0; j><height; j++)

{

int pixel = imageData[i +( j * width)];

int red = (pixel >> 16) & 0xff;

int green = (pixel >> 8) & 0xff;

int blue = (pixel ) & 0xff;

imageData[i +( j * width)] =(alpha <<24) | (red << 16) | (green << 8) | blue;

}

}

return comp.createImage(new MemoryImageSource(width,height,imageData,0,width));

}

Hope that helps!

Harley.

harleyrana at 2007-7-7 11:57:53 > top of Java-index,Other Topics,Java Game Development...