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!
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!
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.
Ok how would i do these things? ???
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:
gl.glEnable(GL.GL_TEXTURE_2D);
texture0.bind();
glDrawArrays(...);
texture1.bind();
glDrawArrays(...);
texture2.bind();
glDrawArrays(...);
glDisable(GL.GL_TEXTURE_2D);
or
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).
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
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.