Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (564)
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  
  Alpha Composite  (Read 2335 times)
0 Members and 1 Guest are viewing this topic.
Offline Coinerson

Junior Member




Introducing the world's cutest zombie, Timmy


« Posted 2007-02-20 05:19:21 »

So i have this particle engine which worked great. Now that I am trying to make them fade like good little particles, the performance is shot.

here is my drawing code before and after. Before had fantastic performance, after is choppy and bad.

Before:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
 public void draw(Graphics2D g) {
       
        Iterator i = particles.iterator();
        while (i.hasNext()) {
            Particle p = (Particle)i.next();
            g.setColor(p.getColor());
            g.drawRect((int)p.getX()-p.getSize()/2,
                       (int)p.getY()-p.getSize()/2,
                       p.getSize(), p.getSize());
        }

    }


After:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
 public void draw(Graphics2D g) {
       
        Composite c = g.getComposite();
        Iterator i = particles.iterator();
        while (i.hasNext()) {
            Particle p = (Particle)i.next();
            g.setColor(p.getColor());
            g.setComposite(AlphaComposite.getInstance(
                           AlphaComposite.SRC_OVER, p.getAlpha()));
            g.drawRect((int)p.getX()-p.getSize()/2,
                       (int)p.getY()-p.getSize()/2,
                       p.getSize(), p.getSize());
        }
       
        g.setComposite(c);
    }



I am not aware of the performance compared to other ways to do any of that realy, so any way to make it not be terrible would be great.
Offline cylab

JGO Ninja


Medals: 49



« Reply #1 - Posted 2007-02-20 13:26:43 »

I am afraid you can't do much about it. I am not a Java2D guru, but I heard, the use of transparency breaks the hardware acceleration :/

Mathias - I Know What [you] Did Last Summer!
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #2 - Posted 2007-02-20 15:04:27 »

Try specifying either -Dsun.java2d.translaccel=true or, if you have a fairly recent graphics card with recent and good OpenGL drivers, -Dsun.java2d.opengl=true on the command line. For some background, try doing a Google search for sun.java2d.translaccel; also see this or this article.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Coinerson

Junior Member




Introducing the world's cutest zombie, Timmy


« Reply #3 - Posted 2007-02-20 18:34:08 »

That made no decernable difference. It was suposed to ues directdraw 3D to accelerate the drawing of transparency right?

Unrelated but in my particle im using lots of set and get, should I be making the fields public and accessing them that way?
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #4 - Posted 2007-02-20 18:37:04 »

That made no decernable difference. It was suposed to ues directdraw 3D to accelerate the drawing of transparency right?

Yes, I thought it should. One of the Java 2D engineers will hopefully chime in here.

Unrelated but in my particle im using lots of set and get, should I be making the fields public and accessing them that way?

No. The Java HotSpot VM will inline calls to these accessors. Please see some of the JavaOne presentations on the HotSpot publications page. The high-level point is to please write good code.
Offline campbell

Junior Member




Java games rock!


« Reply #5 - Posted 2007-02-20 18:47:15 »

That made no decernable difference. It was suposed to ues directdraw 3D to accelerate the drawing of transparency right?

You haven't mentioned which JDK release you're using, or which graphics board, or which graphics driver version... All of these are required bits of information.

In JDK 6, you can use -Dsun.java2d.opengl=True or -Dsun.java2d.d3d=True (note the uppercase 'T'), which will print to the console whether or not the pipeline can be enabled.  For more startup details, set J2D_TRACE_LEVEL=4 (that's an environment variable) before running your application.

Either pipeline can accelerate the case you mention in hardware.  If you're not seeing a difference, then there's something about your configuration causing the problem.

Chris
Offline Coinerson

Junior Member




Introducing the world's cutest zombie, Timmy


« Reply #6 - Posted 2007-02-20 20:06:00 »

Alright, using =True worked nicly. I cant tell how well it is compared to when I wasn't using. I did =true before and it failed.

Graphics stuff should be irrelivant since releasing it would require the most stuff possible. But JDK 6. Im on a MBP using bootcamp and on the XP for 6. And im sick of XP already, so hard to do basic tasks.

But anyway, how do I give it that argument without wrapping it in an .exe (or .app when 6 comes out for OS X). Ive never used manifests to give command line args. I dont even know if you can, i suppose I could always go check myself.... OFF I GO. Thanks for the help.

Can I use Sysetem.setProperty for this?

Looks like I cannot, this does not work at the very least:

1  
System.setProperty("Dsun.java2d.translaccel", "True");




Edit:.... hahahhah,...ha? I removed the D because I wasn't sure what it stood for anyway and it works dandy now. Thank you for all your help.

Now to get this straight, on a java 5 machine it wil ignore that call? Or will it crash error out. By that I mean should i put an if (System...java version >= 6) before it? Or just leave it alone?
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.

Grunnt (23 views)
2014-09-23 14:38:19

radar3301 (14 views)
2014-09-21 23:33:17

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

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

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

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

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

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

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

TehJavaDev (108 views)
2014-09-10 06:39:09
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!