Multi-texturing is a powerfull thing. It allows you to draw more that one texture in one pass.
So, you can stack up textures on an object without drawing it many times and without blending (to mix textures). If the object is complicated, multi-texturing speed up the drawing.
But, if you want to use multi-texturing, your graphic card need to support the extension GL_ARB_multitexture. Some old graphic card don't support this extension but I think that all nowadays graphic cards support it.
This tutorial is based on a Tutorial written by Digiben from Game Tutorials. Picture comes from his tutorial.
The first thing to do is to check that multi-texturing is support by the graphic card.
To see which extensions are available, you can get the complete list of extension using glGetString and the OpenGl constant GL_EXTENSIONS like this :
String extensions = gl.glGetString(GL.GL_EXTENSIONS)
The string returned contains all the extensions separated by a space. So, to see if multi-texturing is supported, you just have to search if the string contains the multi-texturing extension.
But, what is the extension for multi-texturing ?
Multi-texturing extension is GL_ARB_multitexture.
This extension allow you to use these methods :
glActiveTextureARB
glClientActiveTextureARB
glMultiTexCoord**ARB
Here is the code to check that multi-texturing is supported :
GL_ARB_multitexture extension |
String extensions = gl.glGetString(GL.GL_EXTENSIONS); //Get all supported extensions |
There are many kind of extension :
ARB Extensions officially approved by the OpenGL Architectural Review Board
EXT Extensions agreed upon by multiple OpenGL vendors
HP Hewlett-Packard
IBM International Business Machines
INTEL Intel
NVIDIA NVIDIA Corporation
ATI ATI Technologies
MESA Brian Paul�s freeware portable OpenGL implementation
SGIS Silicon Graphics (experimental)
SUN Sun Microsystems
WIN Microsoft
To have informations and characteristics of OpenGL extensions, take a look to this links :
http://oss.sgi.com/projects/ogl-sample/registry/
To know more on the Architectural Review Board, take a look to this link from www.opengl.org :
http://www.opengl.org/about/arb/overview.html
This extension allow you to control more than one Texture Unit.
A texture unit can store texture coordinates, texture state, texture environment state, texture coordinates generation ... A different texture can also be assigned for each texture units.
These things are very powerfull, this allow you to draw multiple textures in one pass. Multi-pass consume lot of time in case of the object is complicated.
You can control which texture unit is used. A texture unit is referenced by the OpenGL constant GL_TEXTUREi_ARB.
i is an integer number from 0 to 31. So, the maximum of texture units is 32, but your graphic card certainly do not support so much units (my graphic card support 8 units).
To know the number of texture units available, use glGetIntegerv with GL_MAX_TEXTURE_UNITS_ARB :
Number of texture unit |
int[] maxTextureUnits = new int[1]; |
To activate (select) a texture unit, just use its associated constant with glActiveTextureARB like :
gl.glActiveTextureARB(GL.GL_TEXTUREi_ARB)
The current texture unit used is GL_TEXTUREi_ARB until you recall this method with another unit.
Using Multi-texturing
You will see that it is very simple to use this useful extension.
After you have selected a texture unit, the following is the same than before. Effectively, to bind a texture, activate texture mode ... method used are the same.
The only thing that change is for affecting the texture coordinate to a vertex. The method used for multitexturing is glMultiTexCoord**ARB :
gl.glMultiTexCoord**ARB(GL.GL_TEXTUREi_ARB, ...)
... is the texture coordinate
The shape that we draw is a cube with two textures on it. The texture of the second unit has an offset position compared with unit one's texture.
Cube using multi-texturing |
float x = ...; //x offset of the second texture |
Texture coordinate generation was seen in Tutorial 11.
With multi-texturing, you can also use texture generation.
The first texture I use is the wall of this tutorial. The second texture (texture[1] in the code bellow) is the following texture () :
Second texture for coordinate generation
Here is the result of the example :
Coordinate generation with multitexturing
Code of the example (this is not included in the code to simplify it) :
Texture coordinate generation with multi-texturing |
|
M : "enable/disable" multi-texturing
S : switch to a different scene
Remember to download the GraphicEngine-1.1.2 to run this tutorial !
Tutorial 22 src (225 ko) //Port to Jogl JSR-231 initially done by Magarrett Dias
If you've got any remarks on this tutorial, please let
me know to improve
it.
Thanks for your feedback.
Copyright © 2004-2012 Jérôme Jouvie - All rights reserved. | http://jerome.jouvie.free.fr/ |