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 =; // 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.


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:


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 );
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,


The types of Minification:


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:


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…


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


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:
%d bloggers like this: