Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Alpha Composite  (Read 1610 times)
0 Members and 2 Guests are viewing this topic.
Offline Coinerson

Jr. Member
**

Posts: 76


Introducing the world's cutest zombie, Timmy


« on: 2007-02-20 00: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 Kernel
*****

Posts: 1939
Medals: 27



« Reply #1 on: 2007-02-20 08: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 Kernel
*****

Posts: 3446
Medals: 3


Java games rock!


« Reply #2 on: 2007-02-20 10: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! Go get 'em!
Offline Coinerson

Jr. Member
**

Posts: 76


Introducing the world's cutest zombie, Timmy


« Reply #3 on: 2007-02-20 13: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 Kernel
*****

Posts: 3446
Medals: 3


Java games rock!


« Reply #4 on: 2007-02-20 13: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

Full Member
**

Posts: 179
Medals: 2


Java games rock!


« Reply #5 on: 2007-02-20 13: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

Jr. Member
**

Posts: 76


Introducing the world's cutest zombie, Timmy


« Reply #6 on: 2007-02-20 15: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]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.122 seconds with 19 queries.