OpenGL Implementation

Basic Steps

For this section, the author will be referring to the use of Java’s OpenGL (JOGL) wrapper library functions in the first part of the assignment. With regards to the first part of the assignment, it involved the modeling and animation jumping mushroom figure 18.

Texture mapping in general can be summarized into four easy steps.

Figure 18: The scene from the jumping mushroom assignment.

1 Load the Texture

The first step is to load the texture and store its values to an array. This is the line of code that the author used to create the texture.

File f = new File(“Texture/mytexture.jpg”);
BufferedImage img = ImageIO.read(f); // read file into BufferedImage
/*The parameter for this method is as follows, (default_profile, img, mipmap) GLProfile.getDefault() selects the systems 
default OpenGL profile which represents the best profile for running the platform, img is the texture image,  and a
 boolean value to enable mipmapping */
Texture texture = AWTTextureIO.newTexture(GLProfile.getDefault(), img, true);

2 Set Texture Parameter

Indicate how the texture is going to be applied into the pixel, in particular pay attention to the last parameter in the function.

 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

This is the parameter that controls how the texture is going to be applied in the pixel. There are three methods of applying texture to the pixel:

  1. GL_DECAL
  2. GL_MODULATE
  3. GL_BLEND

To begin with, to use the textures colour as the final colour when texturing a object, Gl_DECAL should be selected. To combine the effects of lighting with texturing then select GL_MODULATE. Finally select GL_BLEND if you want a constant colour to be blended into the object based on the texture value. Figure 19 illustrates the different effect of these types on the scene.

Figure 19: Top-left, the scene using GL_DECAL Top-right, the scene using GL_MODULATE, bottom-center, the scene using GL_BLEND

/* Set Filtering, The parameter for this method setTexParameter*(gl, type of filtering i.e. magnification or minification, type of magnification or minification)*/

 texture.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER,  GL2.GL_LINEAR );
or
texture.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER,  GL2.GL_LINEAR );

 To explain magnification and minification, take a look at figure 20. Magnification is the scaling up of a texel to match the polygons pixel while Minification is the scaling down of the texel.

Figure 20: Illustrates Minification and Magnification taken from the Red Book, http://fly.cc.fer.hr/~unreal/theredbook/chapter09.html

  • GL_NEAREST or GL_LINEAR

The types of Minification:

  • GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, or GL_LINEAR_MIPMAP_LINEAR

Observe that there are generally two types of each maginification and minification, these are NEAREST and LINEAR. The difference in quality is illustrated in Figure 20 and Figure 21 respectively. Notice that the scene using GL_NEAREST appears rough compare to GL_LINEAR. There is a trade-off between the use of this two function, ‘GL_NEAREST requires less computation than GL_LINEAR and therefore might execute more quickly, but GL_LINEAR provides smoother results’ [4].

Figure 20: The use of GL_NEAREST to filter the texture

Figure 21: The use of GL_LINEAR to filter the texture

/* Set Wrapping, The parameter for this method setTexParameter()*/

  texture.setTexParameteri(gl, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
 tex.setTexParameteri(gl, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);

3 Enable Texture

To enable the texture simply write:

 texture.enable(gl)

4 Draw the scene by supplying texture co-ordinates the objects coordinates

To assign texture co-ordinates, use the function, gl.glTexCoord2dv(), gl.glNormal3dv() and gl.glVertex3dv() i.e.:
gl.glTexCoord2dv(1, 0);
gl.glNormal3dv(1, 0);
gl.glVertex3dv(1, 0);

Next Cube Mapping in JOGL…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

  • Declarion of own work

    I declare that this work is my own Author Roldan Fritz Tagaro, contact me for more information at: acb08rt@shef.ac.uk
%d bloggers like this: