Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  Transparency in overlay  (Read 1695 times)
0 Members and 1 Guest are viewing this topic.
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Posted 2003-11-19 18:34:38 »

Hi
 I'm trying to get transparent components into the overlay with xith. The following code is how i'm creating my object I'm trying to set it so that the text is non transparent, the first colour block is non transparent, the middle block is semi transparent, and the last block is 100% transparent. All that currently happens is that the colour is scaled by the alpha chanel, so the 100% transparent part comes out black, the 50% comes out dark blue.
 I add the panel by calling
1  
2  
3  
4  
5  
        UIWindow window = new UIWindow(component, width, height, true, true);
        uiComponentMap.put(component, window);
        uiWindowManager.addOverlay(window);
        uiWindowManager.setPosition(window, x, y);
        uiWindowManager.setVisible(window, true);


Does anyone know what i'm doing wrong?, or have any required debug info?

Cheers

Endolf

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
public class TestLabel extends JPanel {
    private Color backGroundColour = new Color(Color.BLUE.getRed(), Color.BLUE.getGreen(), Color.BLUE.getBlue(), 255);
    private Color backGroundColourFaded = new Color(Color.BLUE.getRed(), Color.BLUE.getGreen(), Color.BLUE.getBlue(), 128);
    private Color backGroundColourAlphad = new Color(Color.BLUE.getRed(), Color.BLUE.getGreen(), Color.BLUE.getBlue(), 0);
    private Color clearColour = new Color(Color.white.getRed(), Color.white.getGreen(), Color.white.getBlue(), 0);
   
    /** Creates a new instance of TestLabel */
    public TestLabel() {
        setDoubleBuffered(true);
        setSize(250, 100);
        setLocation(0,0);
    }
   
    public void paint(Graphics graphics) {
        if(graphics == null) {
            System.out.println("Erm, panel.getGraphics() is null");
        } else {
            System.out.println("Graphics is of type: " + graphics.getClass().getName());
        }
        graphics.setPaintMode();
        graphics.setColor(clearColour);
        graphics.fillRect(0,0,249,99);
        graphics.setColor(backGroundColour);
        graphics.fillRect(0,0,90,99);
        graphics.setColor(backGroundColourFaded);
        graphics.fillRect(90,0,90,99);
        graphics.setColor(backGroundColourAlphad);
        //graphics.fillRect(180,0,69,99);
       graphics.setColor(java.awt.Color.WHITE);
        graphics.drawRect(0,0,249,99);
        graphics.setColor(java.awt.Color.WHITE);
        graphics.drawString("Test", 2 ,2 + graphics.getFontMetrics().getAscent() );
       
    }
}

Online kevglass

JGO Kernel


Medals: 117
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2003-11-19 18:37:46 »

I thought the (true,true) on the end of the UIWindow construction was meant to enable transparency, but I've never been able to get it to work.

I just assumed it's one of them things that'll get fixed eventually.

Kev

Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #2 - Posted 2003-11-19 18:46:50 »

Hi
 I wasn't sure if it's something in xith on the 'todo' list, or if it's my code, it's copied from my old j3d hud (the painting bits), but then I had a Graphics2D which you had to call setBackground on and then clearRect the bits you wanted, you could then paste over the rest with a new colour (again with alhpa bits set) and it would work, if you didn't clear it with a color with alpha first then it wouldn't be transparent. Graphics doesn't have a setClearColor method, but it does have the clearRect, so i'm not sure what i'm really supposed to be doing here Smiley

Just hoped someone might have tried and got it working.

Cheers

Endolf

Edit: fixed some typos, again

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DavidYazel

Junior Member




Java games rock!


« Reply #3 - Posted 2003-11-19 22:57:52 »

We use this.  Yes you have to clear the alpha channel in the gtaphics context to get this to work.

g.setColor(new Color(1,1,1,0.5));
g.fillrect(0,0,getWidth(), getHeight());

Or somthing to that effect.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #4 - Posted 2003-11-20 05:57:41 »

Hi
 It turns out I was doing it right, I just needed to update my xith3d.jar.

Cheers

Endolf

Online kevglass

JGO Kernel


Medals: 117
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2003-11-20 20:38:56 »

Further to this, I've worked out what I was doing to make transparency *not* work..

The only way to update a component that you've drawn to seems to be to call setRoot() on the UIWindow associated with. This is work around, I believe calling repaint() is meant to work but doesn't seem to want to.

Calling setRoot() later on undoes the transparency settings and stops the component supporting the alpha channel drawing..

That made no sense, I'll try and edit it to rephrase in the morning.

Kev

Offline DavidYazel

Junior Member




Java games rock!


« Reply #6 - Posted 2003-11-20 23:02:44 »

That doesn't seem right to me.  I never call set root more than once.  In fact I never call repaint() on a regular component..., just do a label.setText(), etc and it update properly.

If you have a simple test case I can try to debug it for you.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Online kevglass

JGO Kernel


Medals: 117
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #7 - Posted 2003-11-21 05:14:45 »

I'll knock one together over the weekend, on a jolly today I'm afraid.

The difference is that I'm drawing directly to my component. I have an extension of JPanel, called in this case HealthPanel. I override the paint() method to draw some images and a bar to the panel.

Now, in Swing if I call repaint on the panel it redraws the panel, calling my paint method which allows me to update the health bar. However, if I call repaint on HealthPanel when I've added it Xith is has no effect. Last time I check it didn't even result in paint() being recalled (although I'll check this).

So, the point is I don't have any sub-components, and hence don't have anything to call setText() on. Although, come to think of it, Jens mentioned in his GUI tutorial that the only way he could get his JTextField for his FPS counter to update was to call setRoot() again.

Kev

Online kevglass

JGO Kernel


Medals: 117
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #8 - Posted 2003-11-21 15:01:24 »

A test case:

http://www.cokeandcode.com/xith/ GUITest.java

It simply(?) creates two components based on JPanels over the top of a single quad scene. There is a count displayed in both panels that should be updated.

To cause an update to the UIWindows I have two different methods.

1) call repaint() on the JPanel - this doesn't seem to work at all.
2) call setRoot() on the UIWindow with the JPanel (as Jens does in the tutorial) - this works but the transparency of the component is reset.

Kev

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.

ctomni231 (33 views)
2014-07-18 06:55:21

Zero Volt (29 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (26 views)
2014-07-16 23:30:00

Cero (41 views)
2014-07-16 00:42:17

Riven (43 views)
2014-07-14 18:02:53

OpenGLShaders (31 views)
2014-07-14 16:23:47

Riven (30 views)
2014-07-14 11:51:35

quew8 (29 views)
2014-07-13 13:57:52

SHC (64 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!