OpenGL/TK Texture Animation Problems

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Odin
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 5
Joined: Fri Aug 10, 2012 3:15 am
Favorite Gaming Platforms: PC, NES, SNES, PSX/1, GBA
Programming Language of Choice: C/C++/C#/AngelScript

OpenGL/TK Texture Animation Problems

Post by Odin »

Yay another problem :I sorry just keep running into problems i can't seem fix myself :]

I have been re-writing my game engine and wanted to move away from the problem I'm having now.

I have a class that takes care of my animations per texture/tileSet
C# tile class snippet...

Code: Select all

/*
X = _x;
Y = _y;
_sizeX = size of tile in set width
_sizeY = size of tile in set height
_width = full tileSet width
_height = full tileSet Height
*/

public void e2Tile(float x, float y)
{
    float tx = (x * _sizeX) / _width;
    float ty = (y * _sizeY) / _height;

    X = tx;
    Y = ty;

    Width = _sizeX / _width;
    Height = _sizeY / _height;

    _frames = new List<float[]>();
    _frames.Add(new float[] { X, Y });
}

public void Update()
{
    if (_frames.Count <= 1)
        return;

    FMR++;
    if (FMR >= (1000 / FPS))
    {
        _frame++;
        FMR = 0;
    }

    _frame = _frame % _frames.Count;

    _x = _frames[_currentFrame][0];
    _y = _frames[_currentFrame][1];
}
Then drawn to the 'entity' class by

Code: Select all

GL.Enable(EnableCap.Texture2D);
GL.BindTexture(TextureTarget.Texture2D, textureID);

GL.Begin(BeginMode.Quads);
GL.TexCoord2(tile.X, tile.Y + tile.Height); GL.Vertex2(-1.0f, -1.0f);
GL.TexCoord2(tile.X + tile.Width, tile.Y + tile.Height); GL.Vertex2(1.0f, -1.0f);
GL.TexCoord2(tile.X + tile.Width, tile.Y); GL.Vertex2(1.0f, 1.0f);
GL.TexCoord2(tile.X, tile.Y); GL.Vertex2(-1.0f, 1.0f); 
GL.End();
i used this tile class for changing frames without animating (button on/off etc.) so i couldnt tell if there was a problem until now,
but I'm at the point of character animations (sprint,swim,run)
and would like to run them at a smooth 30-60fps

But when i run a 4 frame animation like this it skews when changing frames like motion blur on a projectors film strip.
My first guess was it being a float problem and trying to catch up with the data but really dunno how to confirm or compare that lol :1

Then i thought it was a problem with TK so i wrote a different animation system instead pretty much a standard for gl texture animations,
and instead of one texture its per texture so (CharAnim1.png, CharAnim2.png etc..)

Code: Select all

GL.Enable(EnableCap.Texture2D);
GL.BindTexture(TextureTarget.Texture2D, textures[tile._frame]);

GL.Begin(BeginMode.Quads);
GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(-1.0f, -1.0f);
GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(1.0f, -1.0f);
GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(1.0f, 1.0f);
GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-1.0f, 1.0f); 
GL.End();
Now the thing that i don't get here i loaded 1000 of my entities running at 60fps in this manner with no problem
but wouldn't THAT be way more data? i mean im loading 4000 textures here
i don't like this way at all it seams inefficient and tedious i would rather have just 1 tileSet and load frames by my old version.

i mean if i wrote a decent game with alot of item graphics i would have to split them all into seperate files
and then track them all in a jumble of code and i know this is how alot of older games do this, but :I is that really the only possible way? is there no in between?

thanks for reading :]
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: OpenGL/TK Texture Animation Problems

Post by qpHalcy0n »

Your texture selection is frame limited, if the primitive rendering isn't limited by that EXACT same limiter, then you can run into this problem. Where your primitives are coming down the pipeline willy nilly, but your texture selection is inconsistently limited. From what I can see, your limiter looks like it should work, but will not be consistently smooth.
Post Reply