Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Really weird bug  (Read 3075 times)
0 Members and 1 Guest are viewing this topic.
Offline coramoor

Senior Newbie




Java games rock!


« Posted 2003-02-14 23:00:31 »

I'm getting nuts over this really weird bug in the image rendering in my applet  Tongue
I'm using a VolatileImage as a backbuffer, and rendering to it from ordinary images, with and without alpha channels. With the background (w/o alpha) enabled, the FPS is extremely bad, but when I turn it off, the framerate skyrockets. If I play around, disabling most of the tile layers, and then enable the background, the FPS is about the same as with all layers except the background. When I re-enable the foreground, the FPS get really bad, as in the start. This could be normal, if not for the following: when I then disable the foreground, the framerate doesn't come back as expected, it stays as if nothing had happened. This must be some weird internal blitting strategy of the VolatileImage.. I've disabled all timing code, so it's not the inaccuracy of the timer coming into play.
Has anyone else experienced this? I really hope there is a workaround, as I can't predict the behaviour of the rendering at all..  Huh Huh Huh
Offline coramoor

Senior Newbie




Java games rock!


« Reply #1 - Posted 2003-02-14 23:15:50 »

it seems the bug comes into play when there are many transparent images on-screen. Seems like it's disabling acceleration then.

I've recently replaced my graphics card, with the same behaviour both before & after, so it's unlikely thats what's causing the bug.

For the rendering I'm using Graphics.drawImage(Image,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,ImageObserver)


Some more info:
Only the backbuffer is a VolaTileImage, created with Component.createVolatileImage(int,int). The other images I blit are png images created with Toolkit.getImage, with  (mostly) 1-bit alpha channels.
Offline coramoor

Senior Newbie




Java games rock!


« Reply #2 - Posted 2003-02-15 07:38:27 »

Could someone try to reproduce the bug, so I can be sure it's not my system that's influencing this? The applet is here:

http://www.idi.ntnu.no/~erlinga/vibug/frogma.php


Try pressing these keys, in the order given, pressing key Up to jump in between (to see the performance):

(startup: very slow)
1 (disables background -> fast)
2 (disables 1st object layer)
3 (disables 'middle ground' tile layer)
9 (disables status info)
1 (enable background. notice it becomes slow)
5 (disable 2d object layer)
6 (disable player layer - notice how the speed comes back)
5
6 (turning these back on doesn't reduce the performance!!)
4 (enable collision detection tiles)

that is: 1,2,3,9,1,5,6,5,6,4

After this, the performance should still be high. But if you now move the player down, so you can see the monsters, the water, etc., the performance suddenly drops back down.

Isn't this really weird? It seems as though the VolatileImage will change its blitting strategy/accelleration if transparency above a certain amount is encountered when rendering. The water tiles have every other pixel transparent, to avoid using semi-transparency.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #3 - Posted 2003-02-15 09:38:11 »

Hrm, I just get a grey screen and "Class FrogmaApplet not found".

Hellomynameis Charlie Dobbie.
Offline coramoor

Senior Newbie




Java games rock!


« Reply #4 - Posted 2003-02-15 09:42:27 »

Uhmm. I forgot I compiled it with 1.4.1_01.. It's recompiled with 1.4.0 now.. Try again
Offline Backmask

Junior Member




586: The average IQ needed to understand a PC


« Reply #5 - Posted 2003-02-15 12:10:37 »

I get the same bad frame rate when I followed the instructions...

What's causing it I have no idea...

Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #6 - Posted 2003-02-15 13:16:29 »

Hrm, still didn't work - looks like my browser plugin has broken.  Works fine through Appletviewer though!

Yep, I see the same slow down - it's not just your system.

Hellomynameis Charlie Dobbie.
Offline zparticle

Senior Member




Thick As A Brick


« Reply #7 - Posted 2003-02-15 13:38:14 »

Quote
Isn't this really weird? It seems as though the VolatileImage will change its blitting strategy/accelleration if transparency above a certain amount is encountered when rendering. The water tiles have every other pixel transparent, to avoid using semi-transparency.


I had the exact same problem in a project I'm working on. You can't have small non-contiguous areas of transparency in your graphics. I think what happens is this: When an image has contigous areas of transparency the video drivers can optimize the bits. When you have say evey other pixel transparent then the driver has to switch to some internal mode for each pixel. You'll find this is true even when it isn't every other pixel. For instance I had a tile of a tree that had a number of small bumps (tranparent pixels) in the top of the graphic. As soon as I filled in the bumps the performance went way up.

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #8 - Posted 2003-02-15 14:13:47 »

Quote


I had the exact same problem in a project I'm working on. You can't have small non-contiguous areas of transparency in your graphics. I think what happens is this: When an image has contigous areas of transparency the video drivers can optimize the bits. When you have say evey other pixel transparent then the driver has to switch to some internal mode for each pixel. You'll find this is true even when it isn't every other pixel. For instance I had a tile of a tree that had a number of small bumps (tranparent pixels) in the top of the graphic. As soon as I filled in the bumps the performance went way up.


Whoa, thats a weird one. I used the old-skool 'mesh' technique for fake shadows a while ago and didn't notice anything like this happening Huh On the other hand, this was using automatic images, not Volatile, so this could be related in some way (although it sounds more like a driver issue to me).

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline coramoor

Senior Newbie




Java games rock!


« Reply #9 - Posted 2003-02-15 14:47:01 »

Seems I have to stay with normal Images in windowed mode then. Using semi-transparency would be too slow anyway. Using normal Images is much faster than using VolatileImages with slowdown.

There's an application version of the game using fullscreen, I haven't had any problems with it there. In the windowed level editor, though, I have the same problem. If the drivers can cope with it in fullscreen mode, why can't they do it in windowed?  Huh Huh Huh
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zparticle

Senior Member




Thick As A Brick


« Reply #10 - Posted 2003-02-15 14:59:55 »

Let us know but I would be extreemly surprised if you get high frames in windowed mode when using a buffer strategy or even your own buffer flipping. And without either of those it is going to flash like crazy.

Offline coramoor

Senior Newbie




Java games rock!


« Reply #11 - Posted 2003-02-19 17:29:02 »

I fixed the problem!
The problem was that I was using images with an 8 bit alpha channel (loaded directly from png files). I found some code I wrote earlier to make 1 bit alpha images from 8 bit ones, and used it. The problem went away! It's really fast now :-)


I'm sure this code could be a lot better (and of course lots more optimized), but if anyone wants to have a look, here it is:

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  
public Image create1bitAlpha(Image src){
            PixelGrabber pg;
            MemoryImageSource memSrc;
            Image retImg;
            ColorModel colModel;
            int[] pix;
            int w=src.getWidth(null);
            int h=src.getHeight(null);
            int rgb,alpha;
           
            pix = new int[w*h];
            pg = new PixelGrabber(src,0,0,w,h,pix,0,w);
            try{
                  pg.grabPixels();
            }catch(InterruptedException e){
                  System.out.println("Unable to create 1bit alpha: couldn't grab pixels from image.");
                  return null;
            }
           
            // Fix alpha channel:
           for(int i=0;i<pix.length;i++){
                  rgb = pix[i];
                  alpha = (rgb>>24)&0xFF;
                  if(alpha==255){
                        alpha = 1;
                  }else{
                        alpha = 0;
                        rgb=0;
                  }
                  pix[i] = (rgb&0x00FFFFFF)|(alpha<<24);
            }
           
            // Create an image out of it:
           colModel = new DirectColorModel(Color.black.getColorSpace(),32,0x00FF0000,0x0000FF00,0x0000FF,0x01000000,true,DataBuffer.TYPE_INT);
            memSrc = new MemoryImageSource(w,h,colModel,pix,0,w);
            retImg = createImage(memSrc);
            memSrc.newPixels();
            return retImg;
      }


(I dont' know how to format the code nicely here, or even if it can be done.. may not look nice)
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #12 - Posted 2003-03-07 03:49:40 »

I think this could be done a bit easier - just create a 1-bit transparent image (for example, using GraphicsConfiguration.createCompatibleImage(w, h, Transparency.BITMASK)) and copy your original image onto it. It should be faster.
Offline coramoor

Senior Newbie




Java games rock!


« Reply #13 - Posted 2003-03-07 07:03:47 »

But how do I copy the whole image w/alpha channel onto it? I'm a n00b in this, so could anyone tell me how I would do that? If I use the normal drawImage methods, the alpha channel wouldn't be copied, it would be used to modify the rgb channels as usual? The alpha channel in the destination image wouldn't be modified?
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #14 - Posted 2003-03-07 22:44:07 »

here ya go, this will maintain the alpha channel of the source image.

1  
2  
3  
4  
Graphics g = autoImage.getGraphics();
g.setComposite(AlphaComposite.Src);
g.drawImage(sourceImage,0,0,null);
g.dispose();


that must be the 10 squilianth time i've posted that code  Grin

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline coramoor

Senior Newbie




Java games rock!


« Reply #15 - Posted 2003-03-07 23:32:56 »

Thanx!!!  Cheesy Grin
Offline coramoor

Senior Newbie




Java games rock!


« Reply #16 - Posted 2003-03-10 10:17:00 »

The easier code didn't work as expected.. I get the same slowdown on the second level in the game, perhaps it's because the alpha values are rounded differently? Also, when I do this in fullscreen mode, it gets 10 times slower than before.. Seems like I'll have to use LWJGL for the fullscreen version.
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.

BurntPizza (19 views)
2014-09-21 02:42:18

BurntPizza (14 views)
2014-09-21 01:30:30

moogie (14 views)
2014-09-21 00:26:15

UprightPath (25 views)
2014-09-20 20:14:06

BurntPizza (27 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (73 views)
2014-09-10 13:57:51

TehJavaDev (96 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!