Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
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 4449 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 »


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 »


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:




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.


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.

Jesse (8 views)
2015-07-29 04:35:27

Riven (33 views)
2015-07-27 16:38:00

Riven (16 views)
2015-07-27 15:35:20

Riven (20 views)
2015-07-27 12:26:13

Riven (10 views)
2015-07-27 12:23:39

BurntPizza (28 views)
2015-07-25 00:14:37

BurntPizza (39 views)
2015-07-24 22:06:39

BurntPizza (22 views)
2015-07-24 06:06:53

NoxInc (25 views)
2015-07-22 22:16:53

NoxInc (17 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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!