Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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  
  Making Zplax (the Xith3D bits)  (Read 1230 times)
0 Members and 1 Guest are viewing this topic.
Offline Alistair_Dickie

Senior Newbie




Java games rock!


« Posted 2005-03-30 22:01:52 »

It thought I should share some of the challenges that I faced using Xith to make Zplax. Xith3D is an excellent API and I am really greatfull to all that have contributed. There were a few things that I found presented a challenge to me. In this post I will outline some of them.

UI Stuff

Zplax makes extensive use of the ui part of Xith. I really enjoyed being able to use swing to make my UI as I am pretty familiar with it, but there were a few things that need a little work. The event processing framework does not allow a lot of Swing stuff to happen as it normally does. I had to overload UIWindowManager and alter the way mouse events are processed to get my MouseEntered functionality.

TextureLoader

TextureLoader is nice in that there are many ways you can pass a path to a resource to it. One thing that did not work for me though is getting it to find a resource from a jar file that is added to a new URLClassLoader. This was largely because of the way that this static TextureLoader.tf hangs around. I overloaded TextureLoader and added some functionality to tell it what ClassLoader to use to look for resources at. I also added the ability to give it an absolute URL.

ASE Loader

I guess it would not be too much work to read simple (non- texture) materials from the ASE file. It surprised me that it was not done.

Transparency

I tried for ages to get a texture that included transparency draped over some geometry, then fade out the whole thing. I am sure there is a way to do this but I did not stumble upon it.

Sounds

Sounds did not work quite the way I wanted. When I play a little sound I did not want the HD to be accessed, rather I wanted all little sounds preloaded. I also wanted to be able to play multiple copies of the same sound at the same time. While I used part of the Xith Javasound stuff I did a lot of my own.

Thanks again to all.

Regards,

Alistair
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #1 - Posted 2005-03-31 00:59:31 »

I would love to see a follow up post explaining how you worked around these problems (e.g. the transparency issue that you appeared to solve).  Have you looked at the Xith3D code?  You are more than welcome to submit any fixes you make, chances are they will go into the core.

Will.

Offline Alistair_Dickie

Senior Newbie




Java games rock!


« Reply #2 - Posted 2005-03-31 08:49:32 »

I will follow up on all of these at some stage. I should get the CVS and comit a few things. I spent many hours reading a range of Xith classes (TextureLoader, UIWindowManager amongst others) There are only a few little changes that I "had" to make but there were more that I could of.

Now for more on the transparency. This is particulary in relation to the banner. That is the bit in the game that contains tutorial information. Fly it in with i and out with o. Show and hide it with b. It is still not what I want. You can see that on the edges of the banner there are some fully transparent pixels (so the image used for the texture has transparency). What I want to be able to do is fade the whole thing in and out, without sacrificing the ability to have a partially transparent image.

The banner's geometry is a simple TriangleStripArray created like this:

1  
2  
geom = new TriangleStripArray(widthN * 2 * heightN, GeometryArray.COORDINATES |
        GeometryArray.TEXTURE_COORDINATE_2, stripVertexCounts);


I then do stuff to set the coordinates and texture coordinates point wise.

To create the appearance I use this:

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  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
Appearance app = new Appearance();

    PolygonAttributes polygonAttributes = new PolygonAttributes(PolygonAttributes.POLYGON_FILL,
        PolygonAttributes.CULL_NONE, 0f);

    app.setPolygonAttributes(polygonAttributes);


    tmp = DirectBufferedImage.make(w, h, DirectBufferedImage.DIRECT_RGBA);

    try {
      BufferedImage img = null;
      img = ImageIO.read(this.getClass().getResource("data/parchment.png"));
   
      BufferedImage rgb = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
      rgb.getGraphics().drawImage(img, 0, 0, rgb.getWidth(), rgb.getHeight(), 0, 0, img.getWidth(), img.getHeight(), null);


      Graphics2D g = (Graphics2D) tmp.getGraphics();
      g.drawImage(rgb, 0, 0, null);
      cache = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
      cache.getGraphics().drawImage(tmp, 0, 0, null);


    }
    catch (IOException e) {
      e.printStackTrace();
    }

    tex = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, tmp.getWidth(), tmp.getHeight());
    ImageComponent2D im = new ImageComponent2D(ImageComponent.FORMAT_RGBA, tmp.getWidth(),
        tmp.getHeight(), tmp);

    tex.setImage(0, im);

    app.setTexture(tex);

    //this is vital!!
   TransparencyAttributes transAttr =
        new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.0f, TransparencyAttributes.BLEND_SRC_ALPHA,
            TransparencyAttributes.BLEND_ZERO);
    app.setTransparencyAttributes(transAttr);

    TextureAttributes texAtt = new TextureAttributes();
    texAtt.setTextureMode(TextureAttributes.REPLACE);
    app.setTextureAttributes(texAtt);

    shape.setAppearance(app);


To explain this a little. The polygon attributes part is standard. tmp is one of the DirectBufferedImages that is in Xith. If I understand correctly these things are really great as the backing store for the direct buffered image is the same bytes that are used by jogl to send to the video card. Note I create a RGBA one. The image I actually want is read in to img using ImageIO. The type of this buffered image is unknown so I turn it into a TYPE_4BYTE_ABGR the cheats way using the graphics.drawImage method. I then do the same thing to put rgb onto tmp. (tmp is a bit of a misnomer - it is actually the one that goes on the texture). Finally on the image creation I store a copy of the image in cache for later (see below).

To create the texture I use the Texture2D aand ImageComponent2D constructors. Note that ImageComponent2D really likes DirectBufferedImage's.

Now comes the bits I don't really understand, and still have not got working the way I want. You can see what I have done to create the appropriate TransparencyAttributes and TextureAttributes. The combination of BLENDED, BLEND_SRC_ALPHA, REPLACE, etc in these has caused me heartache. I do not really understand what is going on under the hood. I would like to be able to set new transparency attributes over time and fade out the whole thing, while continuing to have a partially transparent image as I loaded above.

A few more nicities are listed below. I like that as I have this DirectBufferedImage I can draw on it using getGraphics and all I need to do is tell the Texture it is dirty and all will be well.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
    public void clearText() {


    tmp.getGraphics().drawImage(cache, 0, 0, null);


  }

  public void addText(String text, int fontSize, int x, int y) {
    Graphics2D g = (Graphics2D) tmp.getGraphics();
    g.setColor(Color.white);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);
    g.setFont(new Font("serif", Font.BOLD, fontSize));
    g.drawString(text, x, y);
    tex.setDirty(true);

  }


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.

Riven (12 views)
2014-07-29 18:09:19

Riven (8 views)
2014-07-29 18:08:52

Dwinin (9 views)
2014-07-29 10:59:34

E.R. Fleming (25 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
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!