Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (525)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
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  
  multiple textures with a vertex array  (Read 3963 times)
0 Members and 1 Guest are viewing this topic.
Offline deepthought
« Posted 2010-08-29 15:54:52 »

How can i use multiple textures with a vertex array? is it possible to specify which texture to use in the array, or should i just use 1 giant megatexture? or should i just use multiple vertex arrays, 1 for each texture?

Thanks in advance!

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline gouessej
« Reply #1 - Posted 2010-08-29 16:19:07 »

Hi

You can draw your vertex array by using several calls of glDrawArrays or glDrawElements, each call concerning one texture. The advantage is that you don't need to merge your textures, you can use bigger textures. The drawback is that it might be slower because you use several calls. You can use multi-texturing and change the active texture or use a single unit of texture and bind each texture you need.

You can draw your vertex array by using a single call of glDrawArrays or glDrawElements and merge your textures into a single one. The drawback is that you have to merge your textures, you may have to reduce its size. The advantage is that it is fast, you have a single call and you bind a single texture.

Take care because you cannot use the same texture coordinates, it depends on the option that you choose.

Maybe there is another solution.

Offline deepthought
« Reply #2 - Posted 2010-08-29 16:25:21 »

Ok how would i do these things? Huh

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2010-08-30 11:02:58 »

Hi!

You need to use glDrawArrays or glDrawElements, glActiveTexture and GL_MAX_TEXTURE_UNITS if you use multi-texturing, glBindTexture or Texture.bind().

You have 2 options:

1  
2  
3  
4  
5  
6  
7  
8  
gl.glEnable(GL.GL_TEXTURE_2D);
texture0.bind();
glDrawArrays(...);
texture1.bind();
glDrawArrays(...);
texture2.bind();
glDrawArrays(...);
glDisable(GL.GL_TEXTURE_2D);


or

1  
2  
3  
4  
gl.glEnable(GL.GL_TEXTURE_2D);
giantTexture.bind();
glDrawArrays(...);
glDisable(GL.GL_TEXTURE_2D);


In both case, don't forget to enable and disable the required extensions for each kind of array (vertex and texture coordinates).

Offline lhkbob

JGO Knight


Medals: 32



« Reply #4 - Posted 2010-08-30 15:09:22 »

Although gouesseg is technically correct in his advice, I think some background information would be useful here.

When you draw using vertex arrays, the rendered polygons can optionally be textured. The texturing requires two parts information: the texture coordinates, which are stored in vertex arrays, and the texture images that are to be used.

Multiple textures can be combined together automatically with a single draw call.  OpenGL supports multiple textures by having multiple texture "units". Each unit can have a texture image bound to it (e.g. texture.bind() or glBindTexture(target)) and each unit must be enabled/disabled when needed.  Because OpenGL started out with only 1 texture supported, all of the texture calls don't have a 'unit' parameter, so you control which texture is modified by using glActiveTexture() and pass in the value "GL_TEXTURE_0 + x" where x is more logical unit value.

That's how the texture state can be set up.  When using vertex arrays, you need to configure your texture coordinates for each unit that will be using a texture.  The ideas are very similar but use differently named OpenGL calls.  First you need to call glClientActiveTexture() to set the unit being modified for the vertex arrays. This works exactly like glActiveTexture() but for texture coordinates basically.  Once you've set your unit, you need to call glEnableClientState(GL_TEXTURE_COORD_ARRAY) and glTexCoordPointer() to finish setting up your vertex arrays.

Remember to disable the textures and vertex arrays on their proper units when you're done rendering with them.

HTH

Offline deepthought
« Reply #5 - Posted 2010-09-07 22:40:03 »

is there any way to pass a two-dimensional array into GL_texcoord pointer? the 1st dimension would be which vertex i'm supplying a coordinate for, the second dimension would be which unit i'm using.

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
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.

toopeicgaming1999 (70 views)
2014-11-26 15:22:04

toopeicgaming1999 (59 views)
2014-11-26 15:20:36

toopeicgaming1999 (14 views)
2014-11-26 15:20:08

SHC (27 views)
2014-11-25 12:00:59

SHC (25 views)
2014-11-25 11:53:45

Norakomi (31 views)
2014-11-25 11:26:43

Gibbo3771 (25 views)
2014-11-24 19:59:16

trollwarrior1 (38 views)
2014-11-22 12:13:56

xFryIx (77 views)
2014-11-13 12:34:49

digdugdiggy (55 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!