Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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 617 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 Duke


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 opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« 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.

https://github.com/mattdesl/lwjgl-basics/wiki

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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (46 views)
2014-10-17 03:59:02

Norakomi (37 views)
2014-10-16 15:22:06

Norakomi (29 views)
2014-10-16 15:20:20

lcass (32 views)
2014-10-15 16:18:58

TehJavaDev (62 views)
2014-10-14 00:39:48

TehJavaDev (62 views)
2014-10-14 00:35:47

TehJavaDev (52 views)
2014-10-14 00:32:37

BurntPizza (70 views)
2014-10-11 23:24:42

BurntPizza (40 views)
2014-10-11 23:10:45

BurntPizza (82 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!