Tutorial 6 : Texture Filters & Events

Tutorial Download Section

In the previous tutorial, we have seen how to creates and use textures.
This tutorial is the second part of textures for controlling how texture are rendered on the screen.
 

Texture filters are used to control how the texture is rendered to the screen.

Textures are created from a picture which have a fix size, ie fix pixel dimension (for example 64 pixel x 64 pixel).
In general, when a texture is rendered on a shape, the texture should be either shrinked or enlarged compared to the original picture dimension. For this operation, at each pixel of the screen where the textured shape is rendered, a texture read is performed for finding the pixel's color depending on its texture coordinate.

In the following, we will see how the texture is scaled.
 

Suppose a picture of size 3 pixels x 3 pixels, which a zoom result to this :


Zoom on the 3x3 picture

Texture 'pixels' are called texels. A texel is associated with a color and correspond to a region on the UV system (texture coordinate system). Texels are represented in the following pictures.
The texture associated of this picture can be represented by the picture shown below.


Texture texels

In most cases, the uv coordinate read on the texture does not correspond to a texel center. It is generaly between two texels.
To determine the uv color, there are different ways :


GL_NEAREST & GL_LINEAR

Here is the result of these two methods :


Zoom on the original picture (4x4 pixels)


GL_NEAREST vs GL_LINEAR

Filters control how the texture is enlarged and shrinked. They are defined with :
    gl.glTexParameteri(target, property, value)
target is GL_TEXTURE_2D
property can be GL_TEXTURE_MAG_FILTER (texture magnified, enlarged) or GL_TEXTURE_MIN_FILTER (texture minimized, shrinked).
value can be one of those constants :

GL_TEXTURE_MAG_FILTER
& GL_TEXTURE_MIN_FILTER

GL_TEXTURE_MIN_FILTER

GL_NEAREST
GL_LINEAR
GL_NEAREST_MIPMAP_NEAREST
GL_NEAREST_MIPMAP_LINEAR
GL_LINEAR_MIPMAP_NEAREST
GL_LINEAR_MIPMAP_LINEAR

Here is the result for 3 differents magnification/minification filter associations :

GL_NEAREST GL_LINEAR GL_LINEAR
GL_NEAREST GL_LINEAR GL_LINEAR_MIPMAP_NEAREST
GL_TEXTURE_MAG_FILTER
GL_TEXTURE_MIN_FILTER

Discussions :

 

Visit this page, written by Raphael 'Kafou' Lerbour, for more screenshots/details.
There are some interesting stuff not detailed here.
 

Instead of applying a constant rotation on the cube, we use events to get the mouse deplacemement.
With the mouse displacement, we apply either a rotation or a translation depending on mouse button used :
 Left button        x/y rotation
 Right button       z translation (z zooming)
 Left+Right button  x/y translation
 

Remember to download the GraphicEngine-1.1.2 to run this tutorial !


If you've got any remarks on this tutorial, please let me know to improve it.
Thanks for your feedback.
 

Previous Tutorial

Back

Next turorial

Copyright © 2004-2012 Jérôme Jouvie - All rights reserved. http://jerome.jouvie.free.fr/