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  
  Rendering 2d tile map using VBO  (Read 3357 times)
0 Members and 1 Guest are viewing this topic.
Offline trollwarrior1
« Posted 2013-07-03 11:54:55 »


Anyone knows how to properly render a 2d tile map using VBO?
For example, I have a 16x12 tiled map. There are 4 different tiles. Each tiles has it's own color handle or color buffer.
When I want to render with specific color, all I do is point opengl to my color handle and everything is fine.
The problem comes when I need to point openGL to vertices. How do I do that? With immidiate mode that's pretty simple: tell openGl where vertices are where you want and it renders it.
But how do I do it with VBO? When I start my program, I create a vertex buffer with these coordinates:
0, 0;
50, 0;
50, 50;
0, 50;
This gives me a square of 50x50 pixels and it is rendered at top left of the screen. (I setup my display to be like java2d.)
But how do I tell opengl I want to render that square to somekind of an offset? I can translatef, but that takes away 1000fps when rendering a 16x12 map! What if had 40x30 for example? My fps would go down to 500 or less IDK.

So how do I tell opengl to render at an offset? Or do I need to change my rendering pipeline? Like store whole map into a single VBO and render that single vbo?

I have another idea: I recently took  a basic look at shaders and now I have a question: Would I be able to change position of every vertex that goes into opengl by a value I send to shaders? For example I tell opengl to render a square at basic coordinates I have written in the post, and with shaders to add some kind of offset to all the vertices?
Offline quew8

JGO Knight

Medals: 53

« Reply #1 - Posted 2013-07-03 14:00:15 »

To begin with, you are probably doing something wrong with translatef if it reduces your framerate by 1000. But you are right that is a bad way to do it anyway.

You can do this very simply with shaders (use a uniform vec2 and add it to the position of each vertex, but if you only took a basic look you probably don't understand that). Shaders will be very fast but I bet that vbos would be faster.

With vbos, you cannot give it an offset (except through shaders) and the general ethos would be to store the whole map in one or more vbos. Hardware being what it is today, you could store 3600 floats (30 * 40 *3) in a single vbo no problem. The advantage of vbos is that you send the data to the video card once, then only one command to draw it all. (speedy)
Pages: [1]
  ignore  |  Print  

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

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

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

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

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

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

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

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

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

Solater (158 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!