Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (593)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (646)
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  
  2d Animation with VBO's  (Read 1359 times)
0 Members and 1 Guest are viewing this topic.
Offline Devereux

Junior Newbie

« Posted 2013-10-02 19:10:04 »

Okay So I am not quite sure how to go about this.
I want to be able to create a sort of animation system where a sprite changes texture.

I am thinking it could be done if you reloaded the texture into opengl and store in a vbo everytime you change frame, but that would be horribly inefficient.

I'm not really sure how to go about this..
Offline RobinB

JGO Ninja

Medals: 44
Projects: 1
Exp: 3 years

Spacegame in progress

« Reply #1 - Posted 2013-10-02 19:53:34 »

Dont make the sprite change texture, use an texture atlas merging all frames into one image.
changing the frame of the animation will be the fastest with shaders.
Offline Devereux

Junior Newbie

« Reply #2 - Posted 2013-10-03 06:10:07 »

I'm not very familiar with texture atlas's
I don't have a shader either, All the examples of shaders have been for 3d games. My game is only 2d.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline RobinB

JGO Ninja

Medals: 44
Projects: 1
Exp: 3 years

Spacegame in progress

« Reply #3 - Posted 2013-10-03 08:26:24 »

its the same thing, but without the z.

the 3 main options you have are:
- rebuild vbo each frame (using texture atlas, setting diffrent textcoords).
- bind diffrent texture each frame (just bind the texture of the current frame).
- use texture atlas with shaders, so you dont need to update the data each frame.
Offline Devereux

Junior Newbie

« Reply #4 - Posted 2013-10-03 16:44:27 »

Could you please explain texture atlas'.
I don't understand textures well enough to know how to implement them.
Online opiop65
« Reply #5 - Posted 2013-10-03 16:56:31 »

A texture atlas is just a big image that is split into smaller images. So, you could have a tile spritesheet that is, say, 512x512 pixels, and then you jut draw your textures in 16x16 little squares, for instance. Then you just create a bufferedimage and loop through the atlas and to pick a texture, you get the coordinates of the texture you need and then read the rgb data in that square. To get the texture you want, loop from coordinate x to x + width and y to y + height, and get the rgb values of each pixel.

The whole point of spritesheets is to reduce the number of images loaded. With a texture atlas, you only need to load the atlas and then you're done unless you need a different atlas.

Offline Devereux

Junior Newbie

« Reply #6 - Posted 2013-10-03 19:37:21 »

So would I store each subimage in a seperate bytebuffer, and then just store the bytebuffers and bind them everytime that subimage is used?
Offline RobinB

JGO Ninja

Medals: 44
Projects: 1
Exp: 3 years

Spacegame in progress

« Reply #7 - Posted 2013-10-03 19:45:47 »

No, its just one image like this:

then instead of setting textcoord to 0f and 1f, you set the textcoord to "(1f / atlassize) * x" and "(1f / atlassize) * width".
Online opiop65
« Reply #8 - Posted 2013-10-03 19:52:58 »

Yeah, I guess you could do it that way, although I dont think loading an image would be that expensive. I guess if you constantly change textures you should store them. But if you're just changing them every couple minutes or never, its not worth the effort. Just make sure to sort your bind calls so you only bind each texture once!

Offline Devereux

Junior Newbie

« Reply #9 - Posted 2013-10-03 23:05:32 »

Alright thankyou Smiley
I'll look into it a bit
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

deepthought (33 views)
2015-06-30 22:39:44

deepthought (37 views)
2015-06-30 22:39:09

deepthought (47 views)
2015-06-30 22:36:52

Za\'Anzabar (21 views)
2015-06-29 12:44:54

TritonDreyja (38 views)
2015-06-25 00:10:40

CopyableCougar4 (35 views)
2015-06-23 07:34:45

BurntPizza (39 views)
2015-06-22 03:36:46

cookiecompiler (82 views)
2015-06-11 22:42:53

cookiecompiler (45 views)
2015-06-11 22:41:14

NegativeZero (75 views)
2015-06-11 16:49:18
How Do I Expand My Game?
by bashfrog
2015-06-14 18:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 12:37:30

Intersection Methods
by Roquen
2015-05-29 15:19:33

List of Learning Resources
by SilverTiger
2015-05-05 17:20:32

How to: JGO Wiki
by Mac70
2015-02-18 03:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-02 03:25:42

How do I start Java Game Development?
by gouessej
2014-12-28 02:41:21

Resources for WIP games
by kpars
2014-12-18 17:26:14 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‑
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!