Java 2D Abstraction Layer (J2DA!)

Troggan and myself have been considering commoning up some of the code we’ve written independantly wrt abstracting the 2D drawing layer and making it available as a reusable code base.

Just wondering if anyone was interested in this sort of thing and hopefully if anyone would like to get involved (reviewing/dev).

The basic scope is to provide sprites, fonts and other 2D game related paraphernalia in an abstract manner with a couple of implementations based using JOGL and Java2D (what about LWJGL?).

Primarily this is to provide a simple starting place for writing 2D games, but additionally a way to allow swapping over to pure Java2D once it becomes a viable alternative (hopefully Tiger?).

Kev

PS. Not trying to step on the toes of GAGE here (http://java.dnsalias.com), really do appreciate the good work that JBanes has done/is doing there.

hmmmm, interesting idea you’ve got there.

I like the idea… Unfortante I don’t have the time to help developing but I can help with testing/reviewing

I can’t get at CVS like a normal person can. But I would be glad to review/test for you. After all you’ve been more than helpful to me. BTW… it seems to me like JBanes has no objections to his code being adapted. Maybe you should consider combining his codebase w/ yours in this process.
Just a thought.

Oh Yeah,
If I’m gonna test the jogl stuff I’ll need to know if you found a fix for the “Red Primitive” syndrome as I like to call it on my S3 card. ;D

Yep, think there is a fix for that now, its just getting it to reliably work on your type of card and the “normal” cards without one or other crashing :slight_smile:

Kev

[quote]Yep, think there is a fix for that now, its just getting it to reliably work on your type of card and the “normal” cards without one or other crashing :slight_smile:

Kev
[/quote]
Is that fix in the latest webstart ?

For astroprime? No, last time I tried it, it was having problems on some peoples machines, crashing the whole machine in fullscreen mode (so I took it out again :)).

If you want to try something out:

http://www.newdawnsoftware.com/astroprime/test/JoglModeTest.zip

Should contain a little test program to let you try a selection of different modes. I think its to do with the selection of the accumulaters supported…

Kev

I have commited a very early version to the CVS on Sourceforge. There is no example, nor an Website explaining the Stuff. That will be comming in the later versions ;).

Sorry for everyone that has no CVS, but the current state is not ready for creating a real zip with everything you might need.

troggan

Works on some modes, although It says I have no hardware acceleration?

I guess thats what jogl see’s your machine as then. Do you know if the driver you’re using for your GFX card has any OpenGL support, or only DirectX ?

Kev

I quess it has opengl, some of the jogl demos run…Very few though.

kev and i just released the first early alpha of j2da. it’s usable, but the api could change every moment ;).

you will find the first release there:

sourceforge has some problems (they had a raid crashed) that makes it impossible to post a homepage for it :(.

if you want to use it, this might help :


package j2daexample;

import java.io.File;

import net.sf.j2da.graphic.AnimatedSprite;
import net.sf.j2da.graphic.BitmapFont;
import net.sf.j2da.graphic.GameFactory;
import net.sf.j2da.graphic.GameFrame;
import net.sf.j2da.graphic.GameFrameRenderer;
import net.sf.j2da.graphic.GeomDrawer;
import net.sf.j2da.graphic.ResourceFactory;
import net.sf.j2da.util.J2DAColor;

/**
 * A small example for j2da
 * @author bodo tasche
 */
public class Main implements GameFrameRenderer {
      ResourceFactory factory;
      BitmapFont font;
      GeomDrawer drawer;
      
      AnimatedSprite animspr;
      
      public Main() {
            // Create a JOGL-Factory
            factory = GameFactory.getResourceFactory(GameFactory.JOGL);
            // Creates the Frame
            GameFrame frame = factory.getGameFrame(this, "Test Game", 300, 240, true);
      }

      // This is called from the frame created above
      public void init(GameFrame gameFrame) {
            try {
                  // creating geomDrawer
                  drawer = factory.getGeomDrawer(gameFrame);
                  // creating Font
                  font = factory.getBitmapFont(gameFrame, "bobfonts.png",16,8);
                  
                  // Creating an animated Sprite
                  animspr = new AnimatedSprite();
                  animspr.addImage(factory, gameFrame, "weiss-os201.gif", 250);
                  animspr.addImage(factory, gameFrame, "weiss-os202.gif", 50);
                  animspr.addImage(factory, gameFrame, "weiss-os203.gif", 50);
                  animspr.addImage(factory, gameFrame, "weiss-os204.gif", 50);
            } catch (Exception ex) {
                  ex.printStackTrace();
            }
            
      }

      // this is called by the GameFrame to draw the Frame
      public void draw(GameFrame gameFrame) {
            // draw a filled rectangle
            drawer.fillRect(10,10,150,150,J2DAColor.pureBlue, false);
            // draw a animated sprite
            animspr.draw(100, 100, 0);

            if (font != null) {
                  // draw the font
                  font.draw(10,100,"All your base are belong to us");
                  // draw the fps
                  font.draw(10,70, ""+gameFrame.getFPS());
            } 
      }

      public static void main(String[] args) {
            System.out.println("J2DA Test");
            Main test = new Main();
      }

}

as you see it’s quit easy to use. hope you enjoy the stuff.
feel free to comment this stuff :wink:

troggan

If someone is interested in creating the LWJGL-part of this, please leave me a message. I think it’s not too hard to do. Simply take the jogl part and change a few gl calls :slight_smile:

troggan

I think we’d need to wrap the event system to support abstracting LWJGL. But thats only what I remember from my brief look at it.

Incidently, AstroPrime now runs on J2DA!!! :slight_smile:

I’ve also updates the J2DA javadoc, so it should be much more readable/useful now.

Kev

Hi,
just curious but how do you currently deal with player input (keyboard, mouse)?
Don’t you need wrapper classes for this?

But I really like your idea of J2DA - please keep on going!

Tommy

This is what I was trying to get at above. At the moment we have a method called getActiveComponent() on GameFrame which returns a java.awt.Componet.

You can then add event listeners to that component and expect the event notifications to flow. However, if we were to go and implement a LWJGL version we’d have to support the input polling style event.

But thinking about it, we’d also want to do input and visual seperatly since you might want to use a combination of JInput and another rendering technology.

Kev

The Homepage is running now. It can be reached at http://j2da.sf.net. Kevglass has coded a small example on how to use it (http://www.cokeandcode.com/j2da-dash/), and I will create a Tutorial based on that.

Before releasing a new 0.2 release we have to fix one thing: Is it possible to draw a image with another Color? We have a Image with a white Letter, but it should be drawn in Red. We need that Stuff for the FontEngine. In OpenGL it was very easy, but we don’t know a way to do it in Java2D :(.

Is there avail bobfonts.png and sprite gifs files somewhere in j2da site?
I could test a testprogram posted above.
thx

All the sprites and font files should be in the resources direction in CVS.

Kev

Finaly Version 0.2 is out ! You can grab it here : http://j2da.sf.net. Now 2 Examples are included: the class I have posted here and the BoulderDash clone made by kev.

Hope you all like it. Comments are welcome, Developers too ;).

And don’t forget: this game library is actually used by me and kev to write our games :D.