Doing 2d with Xith

I’d like to use Xith to “draw” 2d “sprites” so that it’s HW accelerated and I can use 8bpp alpha blending, blendet zooming, rotating etc.
For example all objects (being a TransformGroup for example) contain a planar rectangle (or 2 triangles) in a Shape3D with a texture. Let’s call this sprite. The sprite’s Z value is zero (usually).

With the View’s standard projection (perspective) this works basically, but I don’t know how to set the view’s position so that the sprites’ textures aren’t being zoomed/scaled (in normal case: for effects I’d like to zoom them and/or the camera by changing their/its z position).
Is a 1:1-zoom possible somehow?

Or do I have to use View.setProjectionPolicy(View.PARALLEL_PROJECTION) ?
I tried that, like many of the Xith demos do when you hit Space, but… then I can’t change the distance of the view, neither could I change the zoom of the sprites by changing their z value. So I guess with parallel projection you can’t “zoom” by changing an object’s z value? (I’ve to admit I’ve never used parallel projection.)

Is there a beginner’s guide how to use 2d (with or without Parallel_Projection) with Xith/Java3d maybe? :slight_smile: Thanks!

Part b) of the question: Many textures. I intend to use many textures because most of the sprites will be animated. I load them with TextureLoader.loadTexture(…). Since textures will get obsolete after a certain time: do I have to take care of the not needed textures (so they don’t fill the 3d card’s memory) ? Or does Xith do this magicially?
Also: what is the fastest and most memory efficient method to swap textures in Xith3d (for an animated 2d sprite) ?

Thanks again for any answers/hints/tips.

Hi
My suggestion would be to use parallel projection and to add your scaled sprites to a tranformGroup with a transform3D set to the identy matrix and then set the scale component of it. The reson I suggest this is that with perspective projection, any z location will have some kind of scaling applied, although using trial and error you could work out where the number of pixels drawn on screen match the number in the texture. I can’t help yoy on your other queries i’m affraid, someone else should be able to though.

HTH

Endolf

Thanks Endolf for the hint. Using Parallel_Projection and scale the TG - that’s it. Works fine for sprite like flat polygons, when it comes to “zoom” them.
Since the View also uses a TransformGroup I could use it for camera zooming, too, probably.

Still, even with Parallel_Projection the texture to pixel relation isn’t perfectly clear to me. There’s the Gl_canvas physical dimension, the polygon’s dimension, and the texture size. Now I’ve to put them so that I don’t get scaled sprites for the normal case.
Maybe I should read the OpenGL redbook again, but then the question is how to put this into relation to Xith (luckily I can use Xith so I don’t have to go the “metal” way). :slight_smile:

There are some answers on that topic when you choose the OpenGL way for example, please see the newless clubie forum’s thread.

The OpenGL Technical FAQ, 9 Transformations, suggests in section “9.030 How do I draw 2D controls over my 3D rendering?” to use Parallel_Projection and set the glOrtho and glViewport. (This is what Kevin does in his Space-invadars Jogl tutorial, too). Those ID engine games do 1:1 texture mapping, too.

But… how to do this in Xith?

I set view.setProjectionPolicy(View.PARALLEL_PROJECTION) and then try the Ortho thing on the view’s Transform3D():[quote]
Transform3D t3d = view.getTransform();
t3d.ortho(0, glGanvas.getWidth(), 0, glCanvas.getHeight(), -1, 1);
view.setTransform(t3d);
[/quote]
but still I don’t get a 1:1 world coordinate to screen coordinate mapping.

For example I load a 256x256 sized texture, draw a rectangle Shape3D with coordinates 0 to 255 and texcoords 0…1f. Still, the resulting textured polygon is way too big on screen.

What am I missing?

PS1: Probably even Xith’s userinterface uses such a technique, but looking at the code doesn’t tell me how to do it.

PS2: Wouldn’t this be a nice chapter for the Xith tutorial? :slight_smile: