OpenGL glteximage2d Texture Generation function Note points

Source: Internet
Author: User

OpenGL glteximage2d Texture Generation function Note points


Glteximage2d detailed


function prototypes are: void Glteximage2d (Glenum target, glint level, glint Internalformat, Glsizei width, glsizei height, glint border, GL Enum format, Glenum type, const glvoid* pixels);

For an official introduction to this function, see Https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glTexImage2D.xml


Here's what you need to note about this function:

1. the glbindtexture function must be called before calling the glteximage2d function

From the prototype of the function, we can see that the glteximage2d function does not specify the resulting texture and which texture ID corresponds, if the glteximage2d function is not called before calling the Glbindtexture function, the created texture is not known for who created it, and the texture created is not found for the corresponding owner.

Therefore, you must first call Glbindtexture (gl_texture_2d, Mtextureid) when you call the Glteximage2d function to create the texture, and the texture ID that corresponds to the textures created by the glteximage2d function.

Before calling glteximage2d the function, you must call Glbindtexture (gl_texture_2d, Mtextureid) to specify the texture ID to manipulate, and hereby reiterate.

The type of 2.internalformat and format must be consistent.

3. the width and height of the loaded picture must be a power of N to 2 . Otherwise, the texture cannot be displayed correctly, and if there is a boundary, it must be an integer power of 2 to +2.

Note that the gltexsubimage2d function also requires that the width and height of the picture must be a power of 2 n times.

4. You can use the glpixelstorei function to specify the memory alignment of the loaded picture.

Glbindtexture (gl_texture_2d, _texture);

OpenGL ES has a limitation on the size of the texture, that is, the length and width must be a power of 2 for the whole number of times.

Before calling this function, you must call Glbindtexture (gl_texture_2d, Mtextureid) to specify the texture ID to manipulate, here is _texture.

Glpixelstorei (gl_unpack_alignment, 1);//Picture 1 byte alignment so loading the most secure OpenGL defaults to 4-byte alignment 4-byte alignment processing is fast. As to why 4-byte alignment is fast, look at the principle of microcomputer, the simple explanation of the alignment can use the shift operation.

Glteximage2d (gl_texture_2d, 0, Gl_rgba, width, height, 0, Gl_rgba, gl_unsigned_byte, pixels);

Glpixelstorei (Gl_unpack_alignment, 4);//The image alignment is changed to 4-byte alignment after the texture is generated.

5. Set the texture filter method

unsigned int mtextureid;

Glgentextures (1, &mtextureid);

Glbindtexture (gl_texture_2d, Mtextureid);

Gltexparameteri (gl_texture_2d,gl_texture_mag_filter,gl_linear);//This is the texture filter parameter setting

Gltexparameteri (gl_texture_2d,gl_texture_min_filter,gl_linear);

width, height and other parameters must meet the requirements, here do not repeat. Pdata refers to the pixel data

Glteximage2d (gl_texture_2d, 0, Gl_rgb, width,height, 0, Gl_rgb, Gl_unsigned_byte, PData);

the 6.OpenGL glubuild2dmipmaps() function supports image files of any resolution but OpenGL ES does not support The Glubuild2dmipmaps function.



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.