Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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  
  Shaders & VBO Spritebatcher  (Read 2297 times)
0 Members and 1 Guest are viewing this topic.
Offline OrelBitton

Junior Newbie

« Posted 2014-01-08 19:58:11 »

Hello there! I've started developing using opengl and learned the basics of 2d and now I know how to create a game and manage all the main stuff, but if for an example I am trying to draw 10000 32x32 textures I barely get FPS and that is because I need to implement a SpriteBatcher to fix my performance.

Correct me if I'm wrong, but a spritebatch simply stores all the vertex data of all the rendering on the screen, same for textures and then simply draws them at once? I need to do this with VBOs, then how can I do this? (Just give me a little push and I'll figure out myself)

Another thing is that I saw and read about shaders and I questioned my self, are shaders useful for 2d projects?
Offline Phibedy

Senior Devvie

Medals: 9

« Reply #1 - Posted 2014-01-08 20:19:41 »

you collect all vertices of your "drawing objects" and give them at once to the gpu.
In addition you can use a spritesheet/textureatlas to reduce the amount of texturebinding.
Offline OrelBitton

Junior Newbie

« Reply #2 - Posted 2014-01-08 20:24:14 »

So you mean I create a FloatBuffer and put all the vertices in it? I need to create a FloatBuffer for the texture coords too, no?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Opiop
« Reply #3 - Posted 2014-01-08 21:19:49 »

Well yes, it's the same process of having one buffer object per object, but just modifying the process to store many objects to decrease the amount of time it takes to send all your geometry to its destination (GPU). But you need to find the balance; too much data per batch and it'll be less efficient than throwing in one buffer per time. Too little and you'll starve it, which isn't good either.
Offline davedes
« Reply #4 - Posted 2014-01-08 22:12:04 »

Poke around the tutorials here, a few discuss a sprite batcher and how it's made. If you're using the modern pipeline you'll probably want shader, matrix, texture, and VBO utils to make things easy and clean.

See the API and it's source as an example of how it might be implemented. Lots is inspired by LibGDX, which is another good source reference for sprite batching.

Offline nerb
« Reply #5 - Posted 2014-01-09 01:03:04 »

Another thing is that I saw and read about shaders and I questioned my self, are shaders useful for 2d projects?

In my very limited OpenGL experience so far, I've found them useful. I very recently created a little 2d program where different coloured ameoba-like cells wander around the screen and eat eachother. The whole "wobbly moving cell" appearance was implemented in shaders, using only a single 128 x 128 texture; and the wobble effect varied slightly & randomly for each cell. I'm sure you could imagine how hard that effect would be to implement in a more traditional, no-shader 2d approach.

I guess if you are using fixed-pipeline and rendering a texture on screen, as-is, then they probably aren't so useful. But don't limit yourself to this thinking; you can acheive some awesome things with shaders.
Pages: [1]
  ignore  |  Print  

EgonOlsen (45 views)
2018-06-10 19:43:48

EgonOlsen (27 views)
2018-06-10 19:43:44

EgonOlsen (47 views)
2018-06-10 19:43:20

DesertCoockie (210 views)
2018-05-13 18:23:11

nelsongames (127 views)
2018-04-24 18:15:36

nelsongames (126 views)
2018-04-24 18:14:32

ivj94 (867 views)
2018-03-24 14:47:39

ivj94 (128 views)
2018-03-24 14:46:31

ivj94 (779 views)
2018-03-24 14:43:53

Solater (143 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!