Hi !
Featured games (88)
games approved by the League of Dukes
Games in Showcase (678)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (730)
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 2478 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: 51

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

theagentd (39 views)
2016-05-14 18:38:35

theagentd (70 views)
2016-05-10 22:37:41

theagentd (74 views)
2016-05-10 22:33:46

IanParcs (106 views)
2016-04-18 14:18:53

KaiHH (99 views)
2016-04-18 08:35:41

KaiHH (125 views)
2016-04-15 12:43:58

theagentd (130 views)
2016-04-14 02:16:17

theagentd (152 views)
2016-04-14 02:15:43

IanParcs (243 views)
2016-04-12 03:51:16

IanParcs (91 views)
2016-04-12 03:50:03
FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50 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!