Android OpenGL ES texture coordinate settings and texture rules

Source: Internet
Author: User
Tags repetition

Http://blog.csdn.net/cjkwin/article/details/6016224

When OpenGL maps a square, it defines the texture coordinates, a series of arrays. I believe that beginners of openggl es will have a headache and do not know what to write. Now I will share my research results with you!

When texture ing is started, you must provide other data for OpenGL ES, that is, the texture coordinates of each vertex in the vertex array. Texture coordinates define which part of the image will be mapped to a polygon. It works in a strange way.

The following figure shows the coordinates of the OpenGL texture system on the Android platform, with the origin in the lower left corner.

We now discuss how to use these texture coordinates. When we specify the vertex in the vertex array, we need to provide texture coordinates in another array, which is called the texture coordinate array. It is critical to define the sequence of coordinate arrays.

 

 

 

Float texcoords []
= New float [] {
// Front
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
};

The effect is as follows:

 

If we want to capture images without any texture, we can obtain the array according to the above method.

Float texcoords []
= New float [] {
// Front
0.5f, 0.5f,
1f, 0.5f,
0.5f, 1f,
1f, 1f
};

The effect is as follows:

 

 

Let's look at the original texture file.

You will find that the Y axis of the screenshot is reversed. In fact, this is the android image coordinate system and OpenGL
The es coordinate system is inconsistent. The simplest correction method is to use a tool to flip the original image, which saves a lot of performance and resources are valuable.

Triangle texture ing can be completed smoothly as long as we follow our ing rules.

Float texcoords []
= New float [] {
0.0f, 0.0f,
1.0f, 0.0f,
0.5f, 1.0f,
};

Effect:

 

We should know the meaning of the Rule definition of the texture coordinate array.

 

Tile and foil pull

Our texture coordinate system is on both axes from 0.0
To 1.0, what if the value exceeds this range? There are two options based on the view setting method.

Tile (also called repetition)
One option is tile texture. In OpenGL terminology, it is also called "repetition ". If we change all 1.0 of the first texture coordinate array to 2.0:
Static const glfloat texcoords [] = {
0.0, 2.0,
2.0, 2.0,
0.0, 0.0,
2.0, 0.0
};

You can set it through the gltexparameteri () function.

Gltexparameterf (gl_texture_2d,
Gl_texture_wrap_s, gl10.gl _ repeat );
Gltexparameterf (gl_texture_2d, gl_texture_wrap_t, gl10.gl _ repeat );

 

Clamping position
Another possible option is to allow OpenGL ES to simply limit over 1.0 to 1.0, and limit any value lower than 0.0 to 0.0. This will actually cause duplicate edge pixels.

You can set it through the gltexparameteri () function.

Gltexparameterf (gl_texture_2d,
Gl_texture_wrap_s, gl_clamp_to_edge );
Gltexparameterf (gl_texture_2d, gl_texture_wrap_t, gl_clamp_to_edge );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.