Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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  
  Drawing Transparent Images in 1.4 is buggy  (Read 1596 times)
0 Members and 1 Guest are viewing this topic.
Offline MGodehardt

Junior Devvie




why does the chicken cross the road?


« Posted 2002-12-05 23:46:17 »

Today i compiled a old game tool with 1.4 and found following feature / bug ?

1  
2  
3  
4  
5  
6  
        
BufferedImage aBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

... write your data here in  BufferedImage ...

itsImage = Toolkit.getDefaultToolkit().createImage(aBufferedImage.getSource());


when u use transparent Pixels (Alpha Mask is 0x00) and paint Image its not painted where it should when i use TYPE_INT_RGB everything is ok when i use sun.java2d.noddraw=true everything is ok

Painting is done in ScrollPane, but that cant be the problem.

when u use TYPE_INT_ARGB x , y in translated -2,-2 so image apperas 2 pixels to the left and 2 pixel to the top

brb

took me 3 hours to find that nasty bug, i hope they will fix that in the next release
Offline trembovetski

Senior Devvie




If only I knew what I'm talking about!


« Reply #1 - Posted 2002-12-07 04:12:03 »

Looks like a bug. You might also want to try -Dsun.java2d.ddoffscreen=false to confirm.
Have you tried 1.4.1_01?

Also, try just blitting the argb image to the image created with createCompatibleImage or 'new BufferedImage', it should be  faster.

I assume you want the compatible image to be argb, too, right?
Then just use "new BufferedImage(w, h, TYPE_INT_ARGB), since the images created with createCompatibleImage(w,h,Translucency.TRANSLUCENT) are not currently accelerated anyway.

Something like this:

itsImage = <create the image>
Graphics2D g2d = (Graphics2D)itsImage.getGraphics();
// g2s.setComposite(AlphaComposite.Src);  - if you like
g2d.drawImage(aBufferedImage, 0, 0, null);

Why do you need this intermediate image in the first place?

Offline MGodehardt

Junior Devvie




why does the chicken cross the road?


« Reply #2 - Posted 2002-12-07 22:33:42 »

I am using the lastest JDK 1.4.1_01 on a Win98SE machine with PentiumIII (Geforce2MX/MX400 with 64MB)

and i modified my code now a little bit

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
... loading pixel data (special format)

// now create image from pixels
itsImage = gc.createCompatibleImage(width, height, Transparency.BITMASK);
BufferedImage aBufferedImage = (BufferedImage)itsImage; // <-- is this safe ????

... use setRGB to set only some pixels
aBufferedImage.setRGB(..);

aBufferedImage = null; // <-- is this needed ?


now we come to the funny part in a ScrollPane i draw the Image in paint() and i do not use an special Offscreen technic, first i call super.paint() then i do my g.drawImage on a Graphics Object

with Dsun.java2d.trace=log output is

sun.java2d.loops.Blit::Blit(IntArgbBm, SrcOverNoEa, Ushort565Rgb)

image is not drawn correctly i paint it on (11,11) but its displayed at (9,9)

then i click on my console created ( i use java not javaw ) but any other window will do fine 2.

the window will overlap and hide my image so when i return to my application screen must be redrawn

sun.awt.windows.Win32BlitLoops$DelegateBlitBgLoop::BlitBg(Any, SrcNoEa, "Short 5
65 RGB DirectDraw with 1 bit transp")
sun.java2d.loops.SetFillRectANY::FillRect(AnyColor, SrcNoEa, Any)
sun.java2d.loops.Blit::Blit(IntArgbBm, SrcOverNoEa, Ushort565Rgb)
sun.java2d.loops.Blit::Blit(Ushort565Rgb, SrcNoEa, Ushort565Rgb)
sun.awt.windows.Win32BlitLoops::Blit("Short 565 RGB DirectDraw with 1 bit transp
", SrcOverNoEa, "Short 565 RGB DirectDraw")

looks nice because now java uses hw acceleration
and image is now painted correctly at (10,10)

now i click again at my console window which comes to foreground and overlaps my application again and then i click again in my application , so my image and window must be redrawn

sun.java2d.loops.Blit::Blit(IntArgbBm, SrcOverNoEa, Ushort565Rgb)

hw acceleration is not used anymore, funny, but now i click again in my console it comes to foreground and overlapps my image and then switch back to my application

sun.awt.windows.Win32BlitLoops::Blit("Short 565 RGB DirectDraw with 1 bit transp
", SrcOverNoEa, "Short 565 RGB DirectDraw")

what happened ? its now using hw acceleration again !!! and now u can click in console or move any other window over my image it will use hw acceleration every time.

My Image is a Tile for a Game its isometric ( its a floor tile ) and some parts are transparent, my application is a tile editor and draws a white rect first and paints then the image over it, otherweise i wouldnt recognize the wrong position (9,9) instead of (11,11)

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

Junior Devvie




why does the chicken cross the road?


« Reply #3 - Posted 2002-12-07 22:37:56 »

i forgot this is my drawing code

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
    /**********************************************************************************************
     * Create peer
     *********************************************************************************************/

    public void addNotify()
    {
        super.addNotify();

        setBackground(SystemColor.control);

        Insets insets = getParent().getInsets();
        setLocation(insets.left, insets.top);
        setSize(10, 10);
    }

    /**********************************************************************************************
     * paint
     *********************************************************************************************/

    public void paint(Graphics g)
    {
        super.paint(g);

        int xpos = 10;
        int ypos = 10;

        for ( int idx=0; idx<TerrainItem.itsItemList.size(); idx++)
        {
            g.setColor(Color.white);
            g.fillRect(xpos+1, ypos+1, TerrainItem.width, TerrainItem.height);
            g.setColor(Color.black);
            g.drawRect(xpos, ypos, TerrainItem.width+1, TerrainItem.height+1);

            TerrainItem aItem = (TerrainItem)TerrainItem.itsItemList.elementAt(idx);
            if ( null != aItem )
            {
                if ( null != aItem.itsImage )
                {
                    g.drawImage(aItem.itsImage, xpos+1, ypos+1, null);
                }
            }

            xpos += TerrainItem.width + 4;
            break;
        }

        // Hack - this copies Images to VRAM
        if ( 10 == getSize().width )
        {
            setSize(50, 50);
        }
        else if ( 50 == getSize().width )
        {
            setSize(100, 100);
        }
        else if ( 100 == getSize().width )
        {
            Insets insets = getParent().getInsets();
            setSize(getParent().getSize().width - insets.left - insets.right, getParent().getSize().height - insets.top - insets.bottom);        
        }
    }
Offline trembovetski

Senior Devvie




If only I knew what I'm talking about!


« Reply #4 - Posted 2002-12-18 04:04:58 »

I doubt that this causes your problems, but just in case:
First, why did you need that fiddling with insets and sizes?

Also, never use addNotify. There's no need for it, and it's documented that you shouldn't call or override it.

What problem were you solving with this?

We might chose not to use accelerated copy of the image in some cases (like weird clipping, for example). That's what could be happening.

The thing with the image going like
 not accelerated -> accelerated -> not accelerated -> accelerated -> accelerated ->**
is most likely due to a bug we've recently fixed (1.4.1_02, 1.4.2).
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.

trollwarrior1 (34 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (66 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
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!