Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
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 1474 times)
0 Members and 1 Guest are viewing this topic.
Offline Nyhm

Senior Member


Medals: 3
Projects: 1


Island Forge


« Posted 2012-02-05 20: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: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2012-02-05 20: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 20: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!
Legends of Yore - The Casual Retro Roguelike
Offline Nyhm

Senior Member


Medals: 3
Projects: 1


Island Forge


« Reply #3 - Posted 2012-02-05 20: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 21: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: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-02-05 22: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 00: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.

 

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

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (13 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
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!