OpenGL Textures

satya - Thursday, July 09, 2009 3:11:41 PM

Here are some earlier notes on the subject

Here are some earlier notes on the subject

satya - Thursday, July 09, 2009 3:12:12 PM

read this iphone article to see if this works

read this iphone article to see if this works

satya - Thursday, July 09, 2009 3:15:19 PM

Here is an article from microsoft

Here is an article from microsoft

satya - Thursday, July 09, 2009 3:43:53 PM

Texture mapping from the redbook

Texture mapping from the redbook

satya - Thursday, July 09, 2009 4:34:56 PM

opengl texture mapping coordinates

Search for: opengl texture mapping coordinates

satya - Thursday, July 09, 2009 4:40:45 PM

Read this pdf file

Read this pdf file

satya - Thursday, July 09, 2009 4:48:23 PM

from ed angel: pdf

from ed angel: pdf

satya - Thursday, July 09, 2009 4:53:21 PM

a pdf from ohio state

a pdf from ohio state

satya - Thursday, July 09, 2009 4:54:29 PM

sorry here is the real link for angel: ppt

sorry here is the real link for angel: ppt

satya - Thursday, July 09, 2009 9:26:34 PM

glTexCoord

Search for: glTexCoord

satya - Thursday, July 09, 2009 9:26:46 PM

msdn guide

msdn guide

satya - Thursday, July 09, 2009 9:36:35 PM

opengl example texture a cube

Search for: opengl example texture a cube

satya - Thursday, July 09, 2009 9:49:44 PM

opengl multiple texture mappings

Search for: opengl multiple texture mappings

satya - Thursday, July 09, 2009 9:54:41 PM

opengl different textures for different objects

Search for: opengl different textures for different objects

satya - Thursday, July 09, 2009 9:59:08 PM

another tutorial from iphone

another tutorial from iphone

satya - Thursday, July 09, 2009 10:02:48 PM

this might give some info

this might give some info

satya - Friday, July 10, 2009 11:13:27 AM

What is a texture?

A texture is an image, typically two dimensional and rectangular. You load these from bitmaps. Then you stick these images on a surface of a figure that you draw.

satya - Friday, July 10, 2009 11:14:24 AM

Here is an example from msdn

satya - Friday, July 10, 2009 11:15:04 AM

From msdn mapping to a polygon

satya - Friday, July 10, 2009 11:27:44 AM

So how do you stick them?

Irrespective of the height and width of the texture image, they are normalized to (0,0) and (1,1). Then you take the figure (surface) and lay it on this image so that the figure is completely inside the boundaries of the image (after scaling to the 0 to 1 scale and assuming your figure is smaller than the image). Then calculate the texture coordinate for each vertex coordinate and specify it through textcoord api.

satya - Friday, July 10, 2009 11:30:13 AM

Here is an example from msdn if your figure is larger

satya - Friday, July 10, 2009 11:39:11 AM

what are relevent texture apis


int[] textures = new int[1];
gl.glGenTextures(1, textures, 0);

mTextureID = textures[0];
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
      GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D,
      GL10.GL_TEXTURE_MAG_FILTER,
      GL10.GL_LINEAR);

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
      GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
      GL10.GL_CLAMP_TO_EDGE);

gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
      GL10.GL_REPLACE);

GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
      GL10.GL_MODULATE);

gl.glActiveTexture(GL10.GL_TEXTURE0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
      GL10.GL_REPEAT);
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
      GL10.GL_REPEAT);

public void draw(GL10 gl) 
{
   gl.glFrontFace(GL10.GL_CCW);
   gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mFVertexBuffer);
   gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTexBuffer);
   gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, VERTS,
         GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
}

satya - Friday, July 10, 2009 11:41:24 AM

How can I apply multiple textures to multiple faces

How can I apply multiple textures to multiple faces

satya - Friday, July 10, 2009 11:41:37 AM

How can I apply same texture to multiple faces

How can I apply same texture to multiple faces

satya - Friday, July 10, 2009 11:45:09 AM

Pairing of vertex and texture coords

It looks like when you draw you have to specify the vertices and the tex coordinates at the same time. So for example if I were to draw a cube, I can draw it in one swoop with a single call to draw elements. I just don't know a way to apply multiple texture coords the same time.

I may have to draw multiple faces multiple times, each time with a different texture.

satya - Friday, July 10, 2009 11:47:23 AM

How do I texture a mesh with different textures in opengl

How do I texture a mesh

Search for: How do I texture a mesh

So the generalization is, if I have a mesh I am drawing with draw elements, and different surfaces need different textures how do I do that?

satya - Friday, July 10, 2009 11:47:46 AM

How do I texture a mesh with the same texture?

How do I texture a mesh with the same texture?

Search for: How do I texture a mesh with the same texture?

satya - Friday, July 10, 2009 12:50:00 PM

How can I stick a stamp using opengl textures

How can I stick a stamp using opengl textures

Search for: How can I stick a stamp using opengl textures

satya - Sat Sep 01 2012 17:49:31 GMT-0400 (Eastern Daylight Time)

what is an OpenGL texture target GL_TEXTURE_2D

what is an OpenGL texture target GL_TEXTURE_2D

Search for: what is an OpenGL texture target GL_TEXTURE_2D

satya - Sat Sep 01 2012 17:50:01 GMT-0400 (Eastern Daylight Time)

Here is how they are defined in the context of its glBindTexture

Here is how they are defined in the context of its glBindTexture

satya - Sat Sep 01 2012 18:19:18 GMT-0400 (Eastern Daylight Time)

Genrating a Texture Name: glGenTextures

The OpenGL method glGenTextures is responsible for generating (more like reserving) unique IDs for textures so that those textures can be referenced later. Notice the code below


        int[] textures = new int[1];
        gl.glGenTextures(1, textures, 0);
        mTextureID = textures[0];

The first argument Is the number of textures we want and the second argument is the array for the API to write the integer IDs (names) that are returned. The third argument is the offset in the array to write to by the API. In our case we only want one texture name because we only have one bitmap that we want to load. If we want two textures then we could ask for 2 IDs. During this ID or name allocation no bitmap has been loaded. We need this ID upfront because we may want to direct OpenGL to set some parameters to control the behavior of this texture including the loading of the bitmap. In a sense this is like creating a texture object in order to start defining its properties.

satya - Sat Sep 01 2012 18:48:55 GMT-0400 (Eastern Daylight Time)

Meaning of gl_nearest etc from Red book

f you choose GL_NEAREST, the texel with coordinates nearest the center of the pixel is used for both magnification and minification. This can result in aliasing artifacts (sometimes severe). If you choose GL_LINEAR, a weighted linear average of the 2 � 2 array of texels that lie nearest to the center of the pixel is used, again for both magnification and minification. When the texture coordinates are near the edge of the texture map, the nearest 2 � 2 array of texels might include some that are outside the texture map. In these cases, the texel values used depend on whether GL_REPEAT or GL_CLAMP is in effect and whether you've assigned a border for the texture. (See "Using a Texture's Borders.") GL_NEAREST requires less computation than GL_LINEAR and therefore might execute more quickly, but GL_LINEAR provides smoother results.

satya - Sun Sep 02 2012 08:09:00 GMT-0400 (Eastern Daylight Time)

Clamping in OpenGL

Clamping in OpenGL

Search for: Clamping in OpenGL

satya - Sun Sep 02 2012 08:09:17 GMT-0400 (Eastern Daylight Time)

This is a reasonable article

This is a reasonable article

satya - Sun Sep 02 2012 08:17:31 GMT-0400 (Eastern Daylight Time)

First understand gl_repeat

when the texture coordinate is larger than 1, say 1.3, Just use the 0.3 as your new coordinate. The result of this is you end up redrawing the figure in that direction. You can apply this in both directions resulting in copying the texture in multiple directions.

Clamp Now

In contrast when you clamp when the texture coordinate is 1.3, it will set it to 1. Essentially saying repeat the last texel for the rest of the picture.

satya - Sun Sep 02 2012 08:22:48 GMT-0400 (Eastern Daylight Time)

Another nice place to understand OpenGL in the context of JOGL

Another nice place to understand OpenGL in the context of JOGL

satya - Sun Sep 02 2012 08:31:16 GMT-0400 (Eastern Daylight Time)

Here is how glTexEvn function works

Here is how glTexEvn function works

This parameter allows you to either use the texture colors only, or blend with the original color, or modulate with the original color

satya - Sun Sep 02 2012 08:32:45 GMT-0400 (Eastern Daylight Time)

Possible values are


GL_DECAL, 
GL_REPLACE, 
GL_MODULATE, 
or GL_BLEND

satya - Sun Sep 02 2012 08:35:01 GMT-0400 (Eastern Daylight Time)

GL_REPLACE

Ofcourse use the texture color

satya - Sun Sep 02 2012 08:37:38 GMT-0400 (Eastern Daylight Time)

GL_MODULATE

Modulate the texture color with the base color behavior of the pixel due to its current lighting affects: say should it be darker or paler etc. You typically multiply the texel color with the pixel color.

satya - Sun Sep 02 2012 08:42:15 GMT-0400 (Eastern Daylight Time)

GL_DECAL

the texture color is blended with pixel(fragment) color in a ratio decided by the texel's alpha. If the texel's alpha is full color, then it is essentially same as REPLACE

satya - Sun Sep 02 2012 08:49:05 GMT-0400 (Eastern Daylight Time)

How does GL_BLEND work

How does GL_BLEND work

Search for: How does GL_BLEND work

satya - Sun Sep 02 2012 09:04:07 GMT-0400 (Eastern Daylight Time)

A possibly good explanation of blend function

A possibly good explanation of blend function

satya - Sun Sep 02 2012 09:07:00 GMT-0400 (Eastern Daylight Time)

what i know so far to explain

blending could be in affect with or without textures. Blending takes the foreground colors (may be called destination colors!!) and blends them based on a function you specify with the background (using depth) colors and the resulting color will be the final color.

Now in the context of a texture, use the texel color as your foreground color and use the pixel as the background color and blend them using the blend function that is in play.

satya - Sun Sep 02 2012 09:25:37 GMT-0400 (Eastern Daylight Time)

why the target must be GL_TEXTURE_ENV?

why the target must be GL_TEXTURE_ENV?

Search for: why the target must be GL_TEXTURE_ENV?

satya - Sun Sep 02 2012 09:26:16 GMT-0400 (Eastern Daylight Time)

Apparently this may be an ES restriction

Apparently this may be an ES restriction

satya - Sun Sep 02 2012 09:26:44 GMT-0400 (Eastern Daylight Time)

In opengl there are other values


GL_TEXTURE_ENV, 
GL_TEXTURE_FILTER_CONTROL or 
GL_POINT_SPRITE

satya - Sun Sep 02 2012 11:28:29 GMT-0400 (Eastern Daylight Time)

what is a texture unit glActivetexture

what is a texture unit glActivetexture

Search for: what is a texture unit glActivetexture

satya - Sun Sep 02 2012 11:32:28 GMT-0400 (Eastern Daylight Time)

I may have to read this multitexturing article to understand how active texture works

I may have to read this multitexturing article to understand how active texture works

satya - Mon Sep 10 2012 09:44:12 GMT-0400 (Eastern Daylight Time)

So What is a texture unit?

OpenGL environment can have multiple number of texture units. You can discover how many texture units there are at run time. The base texture unit is always called GL_TEXTURE0. Each texture unit has its own

Texture environment
Texture matrix
Texture coordinates
filter modes
clamping behavior

You can have multiple texture units active at the same time or you can control which texture unit is active.

satya - Mon Sep 10 2012 09:45:18 GMT-0400 (Eastern Daylight Time)

Hierarchy


Texture Unit
Texture Target for a given unit
Texture name (or ID) bound to a texture target

satya - Mon Sep 10 2012 09:47:07 GMT-0400 (Eastern Daylight Time)

glUniform1i active texture

glUniform1i active texture

Search for: glUniform1i active texture

satya - Mon Sep 10 2012 09:55:43 GMT-0400 (Eastern Daylight Time)

Here is the sequence of items


//Set your actual texture to base texture
//This is also default, so you can omit if felt
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

//For the given texture unit, set the 
//texture target (2D) and the texture name (ID)
//This is needed
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID);

//For the texture sampler in GLSL set which
//texture unit to use. This is also the default.
//You can omit if needed.
//First arg: handler to the sampler uniform variable
//Second arg: An integer identifying the texture unit
//0 refers to teh GL_TEXTURE0 and 1 for GL_TEXTURE1 etc
GLES20.glUniform1i(mu2DSamplerTexture, 0);

satya - Mon Sep 10 2012 10:16:22 GMT-0400 (Eastern Daylight Time)

with out the comments


GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID);
GLES20.glUniform1i(mu2DSamplerTexture, 0);

satya - Mon Sep 10 2012 10:17:14 GMT-0400 (Eastern Daylight Time)

This is another good discussion on texture units

This is another good discussion on texture units

satya - Mon Sep 10 2012 10:18:25 GMT-0400 (Eastern Daylight Time)

Here is an IOS tutorial talking about textrues

Here is an IOS tutorial talking about textrues

satya - Sat Sep 22 2012 11:11:39 GMT-0400 (Eastern Daylight Time)

Can my texture coordinate be greater than 1?

Can my texture coordinate be greater than 1?

Search for: Can my texture coordinate be greater than 1?

satya - Sat Sep 22 2012 11:29:58 GMT-0400 (Eastern Daylight Time)

See this article from MSDN

See this article from MSDN

satya - Sat Sep 22 2012 11:50:55 GMT-0400 (Eastern Daylight Time)

From our book

An unstated detail is the size of the object and the paper. OpenGL uses a normalized approach to resolve this. OpenGL assumes that the paper is always a 1 x 1 square with its origin at (0,0) and the top right corner is at (1,1). Then OpenGL wants you to shrink your object surface so that it fits within these 1 x 1 boundaries. So the burden is on the programmer to figure out the vertices of the object surface in a 1 x 1 square. These coordinates of the object on a texture image are called texture coordinates.

When you want the texture image to take the entire space of the object surface you make sure that the object vertices all lie with in the (0,0) to (1,1) of texture coordinates. You can however, specify the texture coordinate of a particular vertex to be greater than "1" either in the "x" direction or the "y" direction. In this case you need to tell OpenGL how to map the space that is outside of (0,0) and (1,1). This is called the wrapping mode.

In one wrapping mode you can tell OpenGL to repeat the texture Image every time it crosses the boundary of 0 to 1. So If you say 1.4 as your vertex's texture coordinate, then your texel will the 40th percentile from the beginning. If your vertex is at 2.4, then your texel that gets painted at this vertex will be the 40th percentile texel again from the beginning (from 0). So you would have painted In the given direction the texture image twice and then a 4th of it by the time you get to the vertex that is at 2.4. This Is a very round about way of saying repeat the image until you run out of space. This is further explained below when we talk about wrapping modes in the context of the specific APIs.