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  
  GradientPaint with Alpha Color: Broken in Java 7?  (Read 411 times)
0 Members and 1 Guest are viewing this topic.
Offline Nyhm

Full Member
**

Posts: 143


Island Forge


« on: 2012-02-05 15: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.

Offline ra4king

JGO Kernel
*****

Posts: 3155
Medals: 196


I'm the King!


« Reply #1 on: 2012-02-05 15: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

Full Member
**

Posts: 238
Medals: 8



« Reply #2 on: 2012-02-05 15: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! Go get 'em!
Offline Nyhm

Full Member
**

Posts: 143


Island Forge


« Reply #3 on: 2012-02-05 15: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.

Offline yuma

JGO n00b
*

Posts: 44
Medals: 2


Monkeys are listening


« Reply #4 on: 2012-02-05 16: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
*****

Posts: 3155
Medals: 196


I'm the King!


« Reply #5 on: 2012-02-05 17: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

Full Member
**

Posts: 143


Island Forge


« Reply #6 on: 2012-02-05 19: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).

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.084 seconds with 20 queries.