Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Transparent images. What am I doing wrong?  (Read 2689 times)
0 Members and 1 Guest are viewing this topic.
Offline whatever

Senior Newbie





« Posted 2002-11-15 14:59:00 »

For a game I have created an VolatileImage as a backbuffer. I have tried to blit transparent gif images to this backbuffer and this works ok. The sprite is accelerated. When I try to create my own transparent BufferedImage the sprite works, but is not accelerated. I know that it can be done. So what im I doing wrong.

Below is the part of the code that blits the sprite to the backbuffer. the gif image is accelerated, but my own Image is not accelerated.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public class TestTransparent 
{    
    private Image img = null;
   
    /** Creates a new instance of TestTransparent */
    public TestTransparent(GraphicsConfiguration graphConfig)
    {
//      img = Toolkit.getDefaultToolkit().getImage("G:\\trans.gif");
       
        img = graphConfig.createCompatibleImage(400, 400, Transparency.BITMASK);
    }
   
    public void draw(Graphics g, int x, int y)
    {
        g.drawImage(img, x, y, null);
    }
}
Offline cknoll

Junior Duke




Flame On!


« Reply #1 - Posted 2002-11-15 16:00:51 »

Actually, I thought I read that transparancy isn't supported with volitile image (accellerated images) so if there's transparancy indicated in the image, the 'automatic' image will fall back to a buffered image (ie. non-accellerated).  I could be wrong tho.

Makes sense, tho, that the vram operations isn't going to take transparancy into account..it's just going to do a straight blit.

-Chris
Offline whatever

Senior Newbie





« Reply #2 - Posted 2002-11-15 16:17:40 »

It is true, that transparency doesn't work on VolatileImages. It is however possible to do hardware acceleration on images with 1bit transparency. This requires a "workaround" that I have read in another post. However I can't seem to get this working.

Quote

In answer to your first question, there is unfortunately no way to create a VolatileImage that is non-opaque (translucent or transparent).  This is API that we should introduce in jdk1.5 (a ways off, but I just thought I'd mention it).  The main idea behind the first VolatileImage API was to have the ability to force the back buffer to live in hardware.  Back buffers are usually opaque, so this simple API did the trick.  Now that that functionality is there, we can beef up the Volatile API to include other related operations/formats that people care about.

As to how you work around the issue, you should be able to use createCompatibleImage(w,h,transparent) for any background which will remain static.  Say you have a scrolling starfield (or whatever); you can create this as a compatible image and simply copy from there into your Volatile back buffer.  At some point (usually the second copy), we will recognize this as something that we can do better in hardware and we will create a VRAM version of that compatible image to use from then on.  As long as you are not touching the pixels of the compatible image, we will continue to use the VRAM version of it and you will get native-hardware speeds.

Things to watch for:
- DO NOT grab the Raster or DataBuffer for the compatible image.  If you do this, we give up on accelerating that image because we cannot guarantee that our VRAM version matches the original image (because you can tweak the pixels directly without our knowing).  We will probably introduce some sort of Lock/Unlock API for this in the future, but for now just avoid it if at all possible.
- Accelerating compatible images only works for opaque and transparent images for now.  We're working on translucency acceleration; this should be there in jdk1.5.
- There can be problems with images larger than the screen size (we may not be able to create a VRAM image larger than that size), so if you need a background image larger than this, you'll have to tile it into several images.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cknoll

Junior Duke




Flame On!


« Reply #3 - Posted 2002-11-15 17:49:40 »

Not sure, I think I'll defer to someone more 'in the know'.  From your example,  is the image from createCompatableImage accellerated?  What if you don't create it with Transparency.BITMASK?  

-Chris
Offline themaze75

Innocent Bystander





« Reply #4 - Posted 2002-11-17 12:27:23 »

Alpha compositing is not accelerated.  

1 bit alpha masking can be done, though.  I don't know how to manuallly create an accelerated masked image.  I've tried in many ways and the only way I got it working is by loading a gif file that has transparency in it.

This one can be blitted in a volatile image and remain accelerated.

I've have a sprite engine at work that works fine with this (roughly 100 frames per seconds running a about 80 sprites in 800x600x32).  But as soon as there's an alpha image being blitted in there, the frame rate drops dramatically (drawing a 200x200 square at 50% opacity dropped me at 4 fps).

So, I'm looking for another way to do this (or for JDK1.5 to come out Wink )

Offline trembovetski

Senior Duke




If only I knew what I'm talking about!


« Reply #5 - Posted 2002-11-17 17:10:18 »

Images created with
GraphicsConfiguration.createCompatibleImage(w,h,Transparency.BITMASK) will be accelerated (after the first copy from it to the backbuffer or screen) giving there's enough vram and you're not running with your desktop in 8-bit depth mode.
Offline whatever

Senior Newbie





« Reply #6 - Posted 2002-11-21 09:12:28 »

I have been able to create 1-bit transparent accelerated images with gif's and 8-bit color indexed png files. Creating 1-bit transparent accelerated images with "Transparency.BITMASK" has failed however.

Anyway I want to be able to create images with at least a colordepth of 16-bit and with 1-bit transparency. Is it possible (and so yes. how?) to create 16-bit indexed images (png files) in wich one color represents transparency and are these images accelerated?

Second question: Has anyone a full working example of creating an 1-bit transparent accelerated image with "Transparency.BITMASK"?
Offline Backmask

Junior Duke




586: The average IQ needed to understand a PC


« Reply #7 - Posted 2002-11-21 11:10:13 »

Try something like this... I havn´t tried it just coded it from memory (that isn´t that good)...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
import .....

public class TestTransparent  
{    
    private Image img = null;
     
    /** Creates a new instance of TestTransparent */
    public TestTransparent(GraphicsConfiguration graphConfig)  
    {
Image tempImage = Toolkit.getDefaultToolkit().getImage("G:\\trans.gif");
   int spriteW = tempImage.getWidth(null);
   int spriteH = tempImage.getHeight(null);
   img = graphConfig.createCompatibleImage(spriteW, spriteH, Transparency.BITMASK);
   Graphics2D g = (Graphics2D)img.getGraphics();
   g.drawImage(tempImage, null, null);
   g.dispose();
    }
     
    public void draw(Graphics g, int x, int y)
    {
   g.drawImage(img, x, y, null);
    }
}


That should work. Hope it helps.

/Backmask

Offline whatever

Senior Newbie





« Reply #8 - Posted 2002-11-28 08:53:32 »

Drawing an accelerated "gif" image into an Image with Transparency.BITMASK does not accelarate this Image.

The only ways that I have found to create an working accelerated image with 1-bit transparency is by creating an gif or png file with an 8-bit indexed palette in wich one color is specified as transparent.

I'am now using indexed png files as a workaround. What also could work is creating an BufferdImage of type TYPE_BYTE_INDEXED. I havend tried it yet but it seems to fit the patern.

Has anybody else simular experiences with transparent images?
Offline trembovetski

Senior Duke




If only I knew what I'm talking about!


« Reply #9 - Posted 2002-11-30 05:25:51 »

Could you try to create an isolated example which shows the problem?

I can assure you that the images created with createCompatibleImage(w,h, Transparency.BITMASK) will be accelerated unless you're doing something with the image which forces us to punt on acceleration  (like grabbing the raster, or rendering to this image on every frame), or if there's not enough resources.

Also, which jdk version are you using?
OS, video board?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (20 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (46 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (69 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!