Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
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  
  GradientPaint with Alpha Color: Broken in Java 7?  (Read 936 times)
0 Members and 1 Guest are viewing this topic.
Offline Nyhm

Senior Member


Medals: 3
Projects: 1


Island Forge


« Posted 2012-02-05 21:05:42 »

I recently added some gradient fill areas, just to polish up some interfaces. In cases where I was filling with translucent colors (Color objects created with alpha value), Java 6 runtime will fill the area with the proper gradient, and the area is translucent, as expected. Running the same code (compiled with Java 6) in a Java 7 runtime (on the same platform) behaves differently. The alpha-gradient areas are not transparent at all.

It appears that Java 7 will not honor the alpha byte of the Color objects when performing a GradientPaint fill. I've only tested this in Ubuntu, with Sun/Oracle Java runtimes.

I have not found any articles or bugs reported on this. I'm not well-versed in gradient painting, so can anyone clarify if this is a known issue (or if I'm doing it wrong)? I should code up a simple test case to demonstrate.

The quick work-around was to remove any alpha bytes from my gradient areas, so they paint consistently.

Island Forge: Create Islands with Stories for Others to Explore!
Free-to-Play with Membership and Upgrade options!
Offline ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #1 - Posted 2012-02-05 21:29:32 »

Could you show us code? My game uses alpha gradient fill for the button highlight and it works fine in Java 7.

Offline BoBear2681

JGO Coder


Medals: 18



« Reply #2 - Posted 2012-02-05 21:49:45 »

@ra4king, FYI, your game throws an NPE on startup.  Doesn't seem to affect anything though (I didn't actually play but title screen renders okay):

1  
2  
3  
4  
5  
java.lang.NullPointerException
   at com.ra4king.jdoodlejump.gui.a.p(Unknown Source)
   at com.ra4king.jdoodlejump.JDoodleJump.g(Unknown Source)
   at com.ra4king.a.e.f(Unknown Source)
   at com.ra4king.a.l.run(Unknown Source)

Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline Nyhm

Senior Member


Medals: 3
Projects: 1


Island Forge


« Reply #3 - Posted 2012-02-05 21:58:09 »

Could you show us code?

Yep, I knew that would be the next question. This is pieced together a bit, but shows what I'm doing:

1  
2  
3  
4  
5  
6  
7  
8  
9  
int w = getWidth();
int h = getHeight();
Graphics2D g2 = (Graphics2D)g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color top = new Color(0,0,0,64);
Color bot = new Color(255,0,0,64);
GradientPaint gp = new GradientPaint(0,0,top,0,h,bot);
g2.setPaint(gp);
g2.fillRoundRect(0,0,w,h,8,8);


I have not yet tested this in isolation (need to make a test driver). Any insights welcome.

Island Forge: Create Islands with Stories for Others to Explore!
Free-to-Play with Membership and Upgrade options!
Offline yuma

Junior Member


Medals: 2
Projects: 1


Monkeys are listening


« Reply #4 - Posted 2012-02-05 22:03:41 »

@ra4king, FYI, your game throws an NPE on startup.  Doesn't seem to affect anything though (I didn't actually play but title screen renders okay):

1  
2  
3  
4  
5  
java.lang.NullPointerException
   at com.ra4king.jdoodlejump.gui.a.p(Unknown Source)
   at com.ra4king.jdoodlejump.JDoodleJump.g(Unknown Source)
   at com.ra4king.a.e.f(Unknown Source)
   at com.ra4king.a.l.run(Unknown Source)



I have no problems playing it (except I have some pending grudge with xjump). Definitely no NPE here.

Offline ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #5 - Posted 2012-02-05 23:37:47 »

That error is caused when trying to retrieve the list of cookies (the game stores your name and score in a local cookie). Looks like your browser didn't want to give it to me Smiley
However that whole area is surrounded with a try-catch so if it fails, it just prints the stack trace and returns quietly Smiley

Anyway, I tried your code on Windows 7 with Java 7 and Ubuntu with OpenJDK 7. I painted the background light green and then used your code: it worked fine. I could see the red tint on the bottom.

Either you're doing something wrong somewhere or your flavor of Linux is messed up Cheesy

Offline Nyhm

Senior Member


Medals: 3
Projects: 1


Island Forge


« Reply #6 - Posted 2012-02-06 01:27:12 »

Thanks for running those tests, ra4king. In my context, the bad behavior is definitely triggered by the the alpha color. Maybe it's specific to my graphics card/driver (ATI Radeon / FGLRX driver).

Island Forge: Create Islands with Stories for Others to Explore!
Free-to-Play with Membership and Upgrade options!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (123 views)
2013-05-17 21:29:12

alaslipknot (131 views)
2013-05-16 21:24:48

gouessej (161 views)
2013-05-16 00:53:38

gouessej (153 views)
2013-05-16 00:17:58

theagentd (166 views)
2013-05-15 15:01:13

theagentd (151 views)
2013-05-15 15:00:54

StreetDoggy (195 views)
2013-05-14 15:56:26

kutucuk (219 views)
2013-05-12 17:10:36

kutucuk (218 views)
2013-05-12 15:36:09

UnluckyDevil (221 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.142 seconds with 21 queries.