Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 1371 times)
0 Members and 1 Guest are viewing this topic.
Offline trollwarrior1
« Posted 2013-07-03 11:54:55 »

Hello,

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 Coder


Medals: 29



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

 

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

The first screenshot will be displayed as a thumbnail.

BurntPizza (15 views)
2014-09-19 03:14:18

Dwinin (33 views)
2014-09-12 09:08:26

Norakomi (58 views)
2014-09-10 13:57:51

TehJavaDev (80 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (63 views)
2014-09-08 06:06:29

BurntPizza (46 views)
2014-09-07 01:13:42

Longarmx (33 views)
2014-09-07 01:12:14

Longarmx (37 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!