Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  [LWJGL] Multiple textures on a VBO  (Read 805 times)
0 Members and 1 Guest are viewing this topic.
Offline orange451

JGO Coder


Medals: 8
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Posted 2013-11-26 20:53:31 »

Hello all!
Currently, when I want to have multiple textures for a VBO, I made a model compiler which compiles my models vertices (and UV coords) to a texture "atlas" of sorts. However, this causes the texture to be quite large if I want to have say 30  512x512 textures. On machines with low amounts of ram, the computer runs out of space to store this giant texture.

I have tried googling ways to have multiple textures on a VBO, but I only seem to come across texture splatting, which is not what I want to do.

Imagine a cube; I want each face of the cube (2 triangles per face) to have their own texture.


I saw an example which had this code:
Quote
glVertexPointer(3, GL_FLOAT, 64, BUFFER_OFFSET(0));
glNormalPointer(GL_FLOAT, 64, BUFFER_OFFSET(12));
glClientActiveTexture(GL_TEXTURE0);
glTexCoordPointer(2, GL_FLOAT, 64, BUFFER_OFFSET(24));
glClientActiveTexture(GL_TEXTURE1);
glTexCoordPointer(2, GL_FLOAT, 64, BUFFER_OFFSET(32));
glClientActiveTexture(GL_TEXTURE2);
glTexCoordPointer(2, GL_FLOAT, 64, BUFFER_OFFSET(40));
As I am not on my own machine however, I do not know if this method is what I am looking for.

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline Danny02
« Reply #1 - Posted 2013-11-26 21:20:18 »

just split up the model.
Offline pitbuller
« Reply #2 - Posted 2013-11-26 22:11:37 »

Single 4096x4096 32-bit texture take only 64Mb memory and you can fit 64 512x512 texture regions  there.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline orange451

JGO Coder


Medals: 8
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #3 - Posted 2013-11-26 22:15:34 »

Another problem with the texture atlasing method I have been using, is that I can not fully use linear mipmapping; I can only use "GL_NEAREST_MIPMAP_LINEAR".

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline theagentd
« Reply #4 - Posted 2013-11-26 23:29:11 »

The simplest solution by far is to use a 2D texture array. All other solutions will have problems with texture filtering unless you actually use 30 separate textures and 30 draw calls. Just load each texture into their own layer and give each face its own layer index. Mipmap generation and filtering work internally just as if you had an actual array of 2D textures (int[] textureHandles so to speak), so no bleeding over edges due to filtering. Might have to use shaders for that though, but I'm pretty sure it should work without them if you really want to.

Myomyomyo.
Offline orange451

JGO Coder


Medals: 8
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #5 - Posted 2013-11-27 01:20:36 »

The simplest solution by far is to use a 2D texture array. All other solutions will have problems with texture filtering unless you actually use 30 separate textures and 30 draw calls. Just load each texture into their own layer and give each face its own layer index. Mipmap generation and filtering work internally just as if you had an actual array of 2D textures (int[] textureHandles so to speak), so no bleeding over edges due to filtering. Might have to use shaders for that though, but I'm pretty sure it should work without them if you really want to.

I was thinking the same thing, but I haven't a clue how to actually switch between the textures while drawing the VBO.

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #6 - Posted 2013-11-27 01:52:42 »

Well, you can't for obvious reasons. Maybe look into glBufferSubData? I've never actually used it, but after browsing the internet for a while, that's probably my best guess.

Also, why not use vertex array objects? They are more suited towards models because they are sent to the CPU, whereas vertex buffer objects need to pass through the bus to get to the GPU first. Therefore, constantly updated models that require lots of changing vertices would do better with array objects.

I hope I was correct about all that, I actually sounded smart for once Wink

Offline orange451

JGO Coder


Medals: 8
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #7 - Posted 2013-11-27 01:57:57 »

Well, you can't for obvious reasons. Maybe look into glBufferSubData? I've never actually used it, but after browsing the internet for a while, that's probably my best guess.

Also, why not use vertex array objects? They are more suited towards models because they are sent to the CPU, whereas vertex buffer objects need to pass through the bus to get to the GPU first. Therefore, constantly updated models that require lots of changing vertices would do better with array objects.

I hope I was correct about all that, I actually sounded smart for once Wink

The vertices are never changing Wink
It's for the game map. It gets sent once at the beginning of the game, and doesn't change at all throughout it.

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #8 - Posted 2013-11-27 02:04:11 »

Ah, never mind, don't mind me Wink

Offline theagentd
« Reply #9 - Posted 2013-11-27 02:33:23 »

The simplest solution by far is to use a 2D texture array. All other solutions will have problems with texture filtering unless you actually use 30 separate textures and 30 draw calls. Just load each texture into their own layer and give each face its own layer index. Mipmap generation and filtering work internally just as if you had an actual array of 2D textures (int[] textureHandles so to speak), so no bleeding over edges due to filtering. Might have to use shaders for that though, but I'm pretty sure it should work without them if you really want to.

I was thinking the same thing, but I haven't a clue how to actually switch between the textures while drawing the VBO.
It'll read the layer specified by the 3rd texture coordinate dimension. I believe you could do this with the fixed functionality pipeline if you use 3D texture coordinates where the first two work just as usual and the third is an (unnormalized) layer index. (0.5, 0.5, 3) would be mapped to the center of layer 3 (zero-indexed, so 0, 1, 2, 3 = the fourth layer so to speak). In other words, just add which layer to read from in your VBO's texture coordinates for each vertex.

EDIT: To bitch a bit about your wording (sorry =P): You don't "draw" a VBO. A VBO is just a memory buffer that contains arbitrary vertex data. The VBO is simply read based on your vertex attribute setup (gl****Pointer() calls) to construct vertices.

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Danny02
« Reply #10 - Posted 2013-11-27 11:31:41 »

@opiop65 don't mix up vertex arrays and vertex array objects they are totally different things. VAOs are OpenGL objects like(texture, buffer ...) which safe the state of the used VBO. They are a OpenGL 3 feature, read it up if you like.
Offline orange451

JGO Coder


Medals: 8
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #11 - Posted 2013-11-27 13:03:15 »

To be honest, at this point, I think it would just be easier to change my model importer so that it creates a new VBO for each texture.

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #12 - Posted 2013-11-27 13:41:12 »

@Danny02 Oh I know the difference, its just I forgot to say buffer after vertex array that first time.

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.

CogWheelz (15 views)
2014-08-01 22:53:16

CogWheelz (15 views)
2014-08-01 22:51:43

CopyableCougar4 (18 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

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

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

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

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

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22
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!