Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (602)
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  
  1.5 accelerated images are dodgy  (Read 4901 times)
0 Members and 1 Guest are viewing this topic.
Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Posted 2004-10-26 07:23:00 »

No matter what I do my buffered images are not accelerated.

Here is how I get my information:

System.out.println( img.getCapabilities(img.createGraphics().getDeviceConfiguration()).isAccelerated() );

It returns false.

167fps when I display one image on the screen. 2500fps without any images on screen.

I've tried at least 3-5 methods of creating the images, none of them are accelerated.

I've read several articles explaining that creating a BI from a constructor makes it a managed image.

BufferedImage b = ImageIO.read(new File(szI));
                 img = new BufferedImage( b.getWidth(), b.getHeight(), BufferedImage.TYPE_INT_ARGB );

Here is my code and it is not accelerated like it is said to be.
Given that the code will not display the intended image but that can be fixed.

My problem is that managed images don't work as advertised.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2004-10-26 07:42:12 »

I didn't think BIs were ever accelerated.

Cas Smiley

Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Reply #2 - Posted 2004-10-26 08:26:18 »

Quote
I didn't think BIs were ever accelerated.

Cas Smiley



They are in 1.5 according to docs.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

« JGO Spiffy Duke »


Medals: 212
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #3 - Posted 2004-10-26 08:51:52 »

Where does it say that? I thought the deal was that they'd "try their damndest to accelerate managed images".

Also I was under the impression that ImageIO.read() was going to attempt to return already accelerated images (which presumably would be a special subclass of buffered image or something?)

What you've done is copied (well not yet) the return of ImageIO into a new buffered image. I'd hope we still have the ability to create a BufferedImage that isn't accelerated (I might not want to use video mem up!) and hence the default constructor would create a non-accelerated image.

Could you point me in the direction of the articles and documentation you mention?

Kev

Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Reply #4 - Posted 2004-10-26 09:01:07 »

Quote

As of J2SE 5.0, all images created with a BufferedImage constructor are now managed images and can be cached in video memory...


http://java.sun.com/j2se/1.5.0/docs/guide/2d/new_features.html

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2004-10-26 09:25:07 »

You're using ARGB format which I seem to recall requires a special flag to accelerate (transAccel or something like that).

Cas Smiley

Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Reply #6 - Posted 2004-10-26 10:20:31 »

I'm using it:
System.setProperty( "sun.java2d.translaccel", "true" );

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #7 - Posted 2004-10-26 10:35:58 »

You also need:
System.setProperty("sun.java2d.accthreshold", "0");

if you want to have it accelerated asap (and not after some drawing... that getting accelerated is somewhat "lazy" in order to prevent temporary junk images from getting accelerated).

And there's also:
System.setProperty("sun.java2d.ddforcevram", "true");

弾幕 ☆ @mahonnaiseblog
Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Reply #8 - Posted 2004-10-26 10:46:58 »

Neither setting changes my frame rate.
They are enabled by default anyhow.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline Malohkan

Senior Devvie




while (true) System.out.println("WOO!!!!");


« Reply #9 - Posted 2004-10-26 17:01:25 »

Here's something I just discovered.  When I start Rimscape fullscreen, the opening sequence has these results:

with:
System.setProperty("sun.java2d.accthreshold", "0");
FPS = 20

with
System.setProperty("sun.java2d.accthreshold", "1");
FPS = 110

Pretty big difference Wink  I think the culprit is my AffineTransform rotating all the ships and projectiles and such flying around, and every time it creates one, it tries to put it into VRAM, which is stupid because that particular rotation will never be drawn again, and even if it is, I doubt it's smart enough to reuse it.  Try messing with that!

EDIT:  Just tried this test in Windowed mode:
with:
System.setProperty("sun.java2d.accthreshold", "0");
FPS = 80-86

with
System.setProperty("sun.java2d.accthreshold", "1");
FPS = 100-110

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trembovetski

Senior Devvie




If only I knew what I'm talking about!


« Reply #10 - Posted 2004-10-26 18:46:35 »

Transformations are not accelerated in 1.5 (unless you're using the opengl pipeline). So if you're rendering an image using a transform (other than translation), the operation will be done by the software loops.
Offline Malohkan

Senior Devvie




while (true) System.out.println("WOO!!!!");


« Reply #11 - Posted 2004-10-26 20:00:22 »

yeah, so the improvement I found was a result of not forcing the game to move everything to VRAM upon creation only to pull it right back out in order to do the software transformation.  Instead I just never put it in VRAM since it doesn't help.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #12 - Posted 2004-10-26 21:33:38 »

>Instead I just never put it in VRAM since it doesn't help

You do. But not asap (and temporary "junk" images won't end up there too).

弾幕 ☆ @mahonnaiseblog
Offline Malohkan

Senior Devvie




while (true) System.out.println("WOO!!!!");


« Reply #13 - Posted 2004-10-26 23:44:43 »

Well whatever is happening, it's much much faster now Smiley

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Reply #14 - Posted 2004-10-27 06:50:01 »

I've done both. No change in performance.

C#.NET seems to accelerate images nicely. Why can't Java?

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline Mikael Grev

Junior Devvie




Appearance is everything!


« Reply #15 - Posted 2004-10-27 07:43:01 »

I have no trouble at all getting accelerated BI:s on my setup (1.5). Might it be the Gfx card, drivers, settings in windows or something else that is in your way.

I use ATI cards, all kinds, dual screen and all. big res. No trouble. Though the PNG images from ImageIO is about 8x slower than unaccelerated (yes) ones. That is because of some transparency data incompatibility or something. They know about it anyway, so it will be a problem no more soon. Smiley

Cheers,
Mikael Grev

Mikael Grev.
www.migcalendar.com - Advanced Calendar Component
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #16 - Posted 2004-10-27 07:56:42 »

>Why can't Java?

How should we know?

Well, you can try BufferedImage.TRANSLUCENT instead.

like...

GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage bi = gc.createCompatibleImage(w,h,Transparency.TRANSLUCENT);
Graphics2D g2d = (Graphics2D)bi.getGraphics();
g2d.setComposite(AlphaComposite.Src);
copy.. dispose... yadda yadda (you wont need all this with 1.5)

If all fails do a (simple) test case.

弾幕 ☆ @mahonnaiseblog
Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Reply #17 - Posted 2004-10-27 09:48:41 »

Quote

How should we know?


Sorry for upsetting you but when you are working on something for hours and come to a problem which takes much longer than needed it tends to frustrate people.

Mikael Grev, I have an Ati Radeon 9700 Pro with an A64 3000+ and 1GB DDR400 RAM and an NForce 3 mobo.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #18 - Posted 2004-10-27 12:31:27 »

>Sorry for upsetting you

You didn't Smiley

It's just... we can't know why it isn't working, because we don't have something specific to look at (a small test case).

For example Cas suggested to set the transaccel flag to true and you said *then* that you already did that. Y'know... it kinda leads to a thread with 10 pages and no answer Wink

If you want to get the answer you're looking for asap you should tell everything which is relevant in this order:
-what you want to do (the "goal")
-what you tried (the "way" - in detail [simple sample case preferred])
-what happened and what you've expected
-additional "bonus points"/related/random questions here

This way the reader can see what you want to do, how you tried to do it and what didn't worked. Thanks to that order he/she will be able pretty fast if he/she might be able to answer the question, because it's explained at the beginning. Reading across that part, which explains how you tried it, allows the reader to check common pitfalls and the like. And at the end there is a kind of summary, which can be used for comparison.

Trust me... you'll get a usable answer faster this way Wink

弾幕 ☆ @mahonnaiseblog
Offline Mikael Grev

Junior Devvie




Appearance is everything!


« Reply #19 - Posted 2004-10-27 12:36:55 »

Have you got the latest driver for the Gfx card?
Installed DirectX 9?
Check that you have full acceleration in windows turned on.
run "dxdiag" and check if windows reports any problems.

Cheers,
Mikael Grev

Mikael Grev.
www.migcalendar.com - Advanced Calendar Component
Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Reply #20 - Posted 2004-10-28 13:03:04 »

Yep, latest drivers for all my components.

DirectX acceleration is at full and all my games work perfectly, both GL and DX.

http://members.optusnet.com.au/ksaho/show/testCaseImage.zip

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #21 - Posted 2004-10-28 19:51:29 »

I'll just, totally unhelpfully, add at this stage this is why we developed LWJGL :/

Cas Smiley

Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #22 - Posted 2004-10-29 02:30:47 »

The testcase didn't compile right away.

After some fixing it compiled and yea it wasn't accelerated at all.

After adding thag GraphicsConfiguration stuff (I mentioned that before) it was accelerated after the image was drawn once.

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  
import java.awt.image.*;
import java.awt.*;
[...]
static BufferedImage img = null;
private GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
[...]
public Main( int w, int h )
{
      render = new Renderer(w, h);

      try
      {
            Image timg = ImageIO.read(new File("4.png"));
            img=gc.createCompatibleImage(timg.getWidth(null),timg.getHeight(null),Transparency.OPAQUE);
            Graphics2D g2d=(Graphics2D)img.getGraphics();
            g2d.setComposite(AlphaComposite.Src);
            g2d.drawImage(timg,0,0,null);
            g2d.dispose();
      }
      catch ( IOException e )
      {
            // TODO Auto-generated catch block
            e.printStackTrace();
      }
}
[...]
//added to that "execute" method
acc = img.getCapabilities(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration()).isAccelerated();
[...]

弾幕 ☆ @mahonnaiseblog
Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Reply #23 - Posted 2004-10-29 06:18:04 »

THANK YOU oNyx. Cheesy

Thanks, it works now.

I'm going to analyse your code so I can understand what you've done compared to what I've done and didn't do. Smiley

I love you oNyx

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline kevglass

« JGO Spiffy Duke »


Medals: 212
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #24 - Posted 2004-10-29 06:22:21 »

Aww, isn't appreciation grand. Smiley

Kev

Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Reply #25 - Posted 2004-10-29 06:29:19 »

Question, why doesn't Sun auto enable hardware acceleration for transparent images?

Why do I need to enable it via commandline when Sun can force it automatically?

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #26 - Posted 2004-10-29 07:02:23 »

>Why do I need to enable it via commandline when Sun can
>force it automatically?

Because it doesn't work with all configurations (crappy drivers are to blame). So Sun picked the correct choice... working > fast.

弾幕 ☆ @mahonnaiseblog
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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (49 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (103 views)
2014-11-26 15:20:36

toopeicgaming1999 (31 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!