Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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 Multiple Vertex Buffer Objects  (Read 263 times)
0 Members and 1 Guest are viewing this topic.
Offline zFollette

Junior Member


Exp: 2 years


I like jokes


« Posted 2014-01-11 22:36:52 »

So can someone tell me why this works:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);

        for (int i = 0; i < text.size(); i++) {
            loader.getByFloat(i).bind();
            glBindBuffer(GL_ARRAY_BUFFER, text.get(i));
            glVertexPointer(3, GL_FLOAT, 0, 0);

            glBindBuffer(GL_ARRAY_BUFFER, texture);
            glTexCoordPointer(2, GL_FLOAT, 0, 0);

            glDrawArrays(GL_QUADS, 0, 24 * (chunkWidth * chunkHeight * chunkDepth));
        }

        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);


This works but is very very inefficient.

Any why this does not:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);

        for (int i = 0; i < text.size(); i++) {
            loader.getByFloat(i).bind();
            glBindBuffer(GL_ARRAY_BUFFER, text.get(i));
            glVertexPointer(3, GL_FLOAT, 0, 0);
        }

        glBindBuffer(GL_ARRAY_BUFFER, texture);
        glTexCoordPointer(2, GL_FLOAT, 0, 0);

        glDrawArrays(GL_QUADS, 0, 24 * (chunkWidth * chunkHeight * chunkDepth));

        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);


So I set up my program to run off of arrays, to allow easy modifying and texture changing, so I want the program to iterate through all of the VBO handles that I have, then bind the texture that matches it, then bind it, and repeat. When its done, it should draw the array. That is what my second code should do, but it doesnt show anything. Can anyone tell me why?

Humor will keep you alive.
Offline Dxu1994
« Reply #1 - Posted 2014-01-11 22:40:11 »

Because in your second one in the loop you repeatedly bind a new VBO but do nothing with it.


Offline zFollette

Junior Member


Exp: 2 years


I like jokes


« Reply #2 - Posted 2014-01-11 22:40:53 »

So is there any way to bind multiple arrays, then draw them all at one time?

Humor will keep you alive.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #3 - Posted 2014-01-11 22:44:02 »

Unless I'm mistaken, no. You render one thing after another, that's how graphics programming has always worked.

Offline zFollette

Junior Member


Exp: 2 years


I like jokes


« Reply #4 - Posted 2014-01-11 22:47:02 »

Unless I'm mistaken, no. You render one thing after another, that's how graphics programming has always worked.

Alright, maybe ill look into adding texture data into the vbo so I only have to render one thing that has multiple textures.

Humor will keep you alive.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #5 - Posted 2014-01-11 23:02:19 »

Oh yeah, terrible idea to only bind one texture per face unless you specifically need to (Voxel based games). You should also look into spritesheets, that way you only have To bind a texture once, and then use texture regions.

Offline zFollette

Junior Member


Exp: 2 years


I like jokes


« Reply #6 - Posted 2014-01-11 23:05:29 »

Oh yeah, terrible idea to only bind one texture per face unless you specifically need to (Voxel based games). You should also look into spritesheets, that way you only have To bind a texture once, and then use texture regions.

I know how to use spritesheets with Java API, but not LWJGL, but I don't bind per-face, I bind per-buffer, so I have a vbo handle for every cube with grass textures, another one for wood, another for stone, etc...

Humor will keep you alive.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #7 - Posted 2014-01-11 23:12:19 »

No no no. Sorry, that's a terrible way of doing it. You at least need to only use on buffer object per chunk (If you don't have a chunk system, then you need to have one). Do you know how texture coordinates work in OpenGL?

Offline zFollette

Junior Member


Exp: 2 years


I like jokes


« Reply #8 - Posted 2014-01-11 23:14:34 »

No no no. Sorry, that's a terrible way of doing it. You at least need to only use on buffer object per chunk (If you don't have a chunk system, then you need to have one). Do you know how texture coordinates work in OpenGL?

I have a chunk system, sorry for the mis understanding, I have 10x10 chunks and I use vbo's for each chunk

Humor will keep you alive.
Offline Drenius
« Reply #9 - Posted 2014-01-11 23:17:21 »

Spritesheet: You place all your textures in one big texture, bind it and place the coords inside the big texture for each vertex in the tex_coord buffer.

This thread expands very fast.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #10 - Posted 2014-01-11 23:24:36 »

Make them cubic chunks (x^3). OpenGL texture coordinates range from 1 - 0, as you should know. So, you need to figure out how much space a single texture takes within these constraints. Take the number of textures on one side of your spritesheet, and divide 1 by that number. You should come up with some small number. For example, 1 / 16 textures on one side = 0.0625. So, every texture (as long as its a square) will be 0.0625 "texels" per one side. So, if you have 16 textures on one side of a spritesheet, and you're looking for the second texture on the top row, it goes like this:
X = 0.0625f
Y = 0.0f

Just bind the spritesheet for all the tiles and pass in the correct texture coordinates per tile.

Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #11 - Posted 2014-01-11 23:37:18 »

Make them cubic chunks (x^3). OpenGL texture coordinates range from 1 - 0, as you should know. So, you need to figure out how much space a single texture takes within these constraints. Take the number of textures on one side of your spritesheet, and divide 1 by that number. You should come up with some small number. For example, 1 / 16 textures on one side = 0.0625. So, every texture (as long as its a square) will be 0.0625 "texels" per one side. So, if you have 16 textures on one side of a spritesheet, and you're looking for the second texture on the top row, it goes like this:
X = 0.0625f
Y = 0.0f

Just bind the spritesheet for all the tiles and pass in the correct texture coordinates per tile.

Off Topic: Didn't you release a tool to get the texture coordinates off a sprite sheet?

Why are all OpenGL tutorials written in Brainf**k?
Offline theagentd
« Reply #12 - Posted 2014-01-11 23:38:38 »

Off Topic: Didn't you release a tool to get the texture coordinates off a sprite sheet?
Uhm, the texture coordinates are just
((float)x / width, (float)y / height)
. Why would you need a tool for calculating that?

Myomyomyo.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #13 - Posted 2014-01-11 23:42:54 »

Yes, I did but I never really finished it. Currently it only supports very specific tile sizes. I still use it though because I use that tile size, and its nice for some quick calculations.

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.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
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!