Animated 2D Sprites

Nope, doesn’t work either. It still shows me the upper left quadrant of the picture, instead of the upper right.



Also I was wondering: I accidentally wrote Materials/Sprite.vert and Materials/Sprite.frage (in the j3md) but the program did not protest in any way that it couldn’t find the shaders, which I thought it should. whatever I set for float x doesn’t effect the picture that is shown to me. :frowning:

mhh

could you show how your texture looks like?

okay, I forgot that I overwrote the updateGeometricState function (when I was still inheritinf from the Picture class [now from Geometry])!



Now, instead of only the upper left portion of the picture, the whole picture is shown and changing the calculation of float x still doesn’t do anything.



P.S.: Sorry for so many posts, but when I wanted to post the picture, I accidentally used a wrong url, thus fucking up the forum. But I fixed it. :smiley:



Another thing I also noticed is, that the particle shader, while being able to show several different pictures, does the computation of which picture to use not in its shader, but in the ParticleTriMesh class.

wickermoon said:
Another thing I also noticed is, that the particle shader, while being able to show several different pictures, does the computation of which picture to use not in its shader, but in the ParticleTriMesh class.

Yes, that is done to maintain compatibility with OpenGL1 GPUs.

Found it. Apparently the JOGL-Renderer doesn’t make use of shaders. With LWJGL_OPENGL3 it now does, but all I get are stripes.



Okay, got that one too:



If I define a MaxFrames in the j3md it is also called MaxFrames in the *.vert-file and not m_MaxFrames (LWJGL_OPENGL3-Renderer)!

It seems very odd to me that jme3 does not have built in functional 2d sprite wrapper to abstract the work being done by the shader. I think this framework could benefit greatly from something like what XNA offers with spritebatch. I am going to take a stab at it, and will post back on this thread later on this week. I don’t think it would take too long to develop this library. (Please let me know if it has already been done by someone else :slight_smile:

This is a 3D game engine, not a 2D one ^^ There is Billboard controls…

1 Like

Two points here:



Java2d/swing lack pixel shading and are generally not well suited for building ‘real’ games.



Many great games use combination of 2d drawing and 3d, and even more use 2d drawing for particle effects.



I maintain that jme3 would be a more complete 3d engine, and hold some weight as a general purpose game platform if it had this ‘syntactical suger’ for drawing in 2d. Billboard is fine, but not really what I mean

Use slick or something. This is a 3D engine :stuck_out_tongue:

jME3 has lots of tools for 3D games. 2D support is not great, and is only there for game HUD and such.

For example, we do not support collision detection, physics, animation or batching for 2D.If we add one 2D feature we really should add them all.

1 Like
normen said:
Use slick or something. This is a 3D engine :P


Simply repeating your previous point without responding to another point of view is not how you have a productive conversation. My response to this comment is above.

Momoko_Fan said:
jME3 has lots of tools for 3D games. 2D support is not great, and is only there for game HUD and such.
For example, we do not support collision detection, physics, animation or batching for 2D.If we add one 2D feature we really should add them all.


Personally, I think it would be a great, great thing. I am thinking of games that use 3d world graphics and 2d sprites. (mostly arcade style games/ top down shooters). With XNA, the spritebatch has methods that inherently support animation, by accepting a parameter for the source rectangle to display. (useful for animating from spritesheets). Just supporting a few draw methods would be great. I am already working on this, and will happily share what I have when its done.
jjhavokk said:
Simply repeating your previous point without responding to another point of view is not how you have a productive conversation. My response to this comment is above.

Ok, maybe I was thinking that a hint at an engine that does what you want (OpenGL accelerated 2D) was too simple and I wrecked it by abusing it to underline my previous point. Anyway I should have known that you are aware of all OpenGL engines on the web, I am sorry.
normen said:
Ok, maybe I was thinking that a hint at an engine that does what you want (OpenGL accelerated 2D) was too simple and I wrecked it by abusing it to underline my previous point. Anyway I should have known that you are aware of all OpenGL engines on the web, I am sorry.


No, I am sorry. Maybe I misunderstood.

I don't want to use some 2d engine, I want to use jme3 (cause its awesome!)

I would like a simple wrapper class that allows me to do something like:

SpriteWrapper.draw( texture, position, displayRect, rotation, origin, scale, zIndex);

So I can more easily:


  • Create an OpenGL accelerated 2D game

  • Create a game that mixes 2d/3d

  • Create a game that can apply lighting effects to 2d graphics

SpriteWrapper.draw( texture, position, displayRect, rotation, origin, scale, zIndex);



Thats not tat hard at all, you basially onle need to use a textured quad at that position.

What about you look into creating a custom set of controllers for NiftyGUI for that? You seem to have an Idea of what you want to do there and nifty supports the basics of 2D effects etc. and is our “2D support” basically. You could even create whole levels as XML files, possibly simply with the GUI editor of jMP in the future…

Hi!



Thanks for this topic! I did an Animated Texture Shader.



http://i.imgur.com/v9NqI.jpg



Shader: http://code.google.com/p/jme-glsl-shaders/source/browse/assets/Shaders/SimpleSprite/?r=ecf224d6f57665c78fc9d9805132d14a0f46db10

MatDef: http://code.google.com/p/jme-glsl-shaders/source/browse/assets/?r=ecf224d6f57665c78fc9d9805132d14a0f46db10#assets%2FMatDefs%2FSimpleSprite

Materials: http://code.google.com/p/jme-glsl-shaders/source/browse/assets/?r=ecf224d6f57665c78fc9d9805132d14a0f46db10#assets%2FMaterials%2FSimpleSprite

Textures: http://code.google.com/p/jme-glsl-shaders/source/browse/assets/?r=ecf224d6f57665c78fc9d9805132d14a0f46db10#assets%2FTextures%2FSimpleSprite

Hi @mifth could you provide the java src file for the example?
thanks in advance!

i found it on git … :smiley:

Hi @juglarx !

There is official ShaderBlow project with examples.
http://code.google.com/p/jmonkeyplatform-contributions/source/browse/#svn%2Ftrunk%2Fshaderblowlib%2FShaderBlow

hi i @mifth when i try to run the example o get this error on the vertex shader, o got support for glsl 1.2 and 1.2, so i dont know what is happen… any clue?

ERROR: 0:39: ‘mod’ : no matching overloaded function found
ERROR: 0:39: ‘/’ : wrong operand types no operation ‘/’ exists that takes a left-hand operand of type ‘float’ and a right operand of type ‘int’ (or there is no acceptable conversion)
ERROR: 0:40: ‘-’ : wrong operand types no operation ‘-’ exists that takes a left-hand operand of type ‘float’ and a right operand of type ‘int’ (or there is no acceptable conversion)
ERROR: 0:40: ‘/’ : wrong operand types no operation ‘/’ exists that takes a left-hand operand of type ‘float’ and a right operand of type ‘int’ (or there is no acceptable conversion)

here is the code for the shader taken from git server

uniform mat4 g_WorldViewProjectionMatrix;
uniform float g_Time;

attribute vec3 inPosition;
attribute vec2 inTexCoord;
varying vec2 texCoordAni;

// if these are passed as ints, then it doesn’t work for some reason
uniform int m_numTilesU;
uniform int m_numTilesV;
uniform int m_Speed;

#ifdef FOG
varying float fog_z;
#endif

#if defined(FOG_SKY)
varying vec3 I;
uniform vec3 g_CameraPosition;
uniform mat4 g_WorldMatrix;
#endif

void main(){

gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
texCoordAni = inTexCoord;

int iNumTilesU = int(m_numTilesU);
int iNumTilesV = int(m_numTilesV);

int numTilesTotal = iNumTilesU * iNumTilesV;
int selectedTile = 1;

selectedTile += int(g_Time*m_Speed);

// the "1 - " bit is because otherwise it goes from right to left
texCoordAni.x = -(1.0 - ((texCoordAni.x + mod((selectedTile),  (iNumTilesU))) / iNumTilesU)); ///selectedTile;
    texCoordAni.y = ((-texCoordAni.y - (selectedTile / iNumTilesU)) / iNumTilesV); ///selectedTile;

// if (index = 8) index = 3;

//texCoordAni.x = texCoordAni.x / numTilesTotal + float(index) / numTilesTotal;

#if defined(FOG_SKY)
vec3 worldPos = (g_WorldMatrix * pos).xyz;
I = normalize( g_CameraPosition - worldPos ).xyz;
#endif

#ifdef FOG
fog_z = gl_Position.z;
#endif

}