glteximage2d
glteximage2d OpenGL is a function, the function is based on specified parameters, to generate a 2D texture (Texture). Similar function has glTexImage1D, glTexImage3D.
Foreign Name
glteximage2d
Nature
OpenGL functions
Similar
glTexImage1D
table of Contents
- 1 Introduction
- 2 Function
Brief introduction
This is an OpenGL function (described below with OpenGL ES2.0 for example).
Prototype:
GL_APICALL void GL_APIENTRY glTexImage2D(GLenum target, GLint level, GLenum internalformat,
GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels);
Parameter Description:
target specifies the target texture, this value must be GL_TEXTURE_2D.
level execution level of detail. 0 is the most basic image level, n represents the N level map refinement levels.
internalformat specified texture color components. Optional values are GL_ALPHA, GL_RGB, GL_RGBA, GL_LUMINANCE, GL_LUMINANCE_ALPHA several.
width of the specified texture image width, n must be a power of 2. Texture image must support at least 64 material element width
height specifies the height of the texture image, it must be a power of 2 m. Texture image must support at least the height of the material elements 64
border Specifies the width of the border. It must be zero.
Color format pixel data format, and need not have the same value internalformatt. Alternatively reference values internalformat.
type specify the data type of the pixel data. Values can be used are GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_5_5_5_1.
pixels specified point in the image data memory pointer
Features
Function of the function is based on specified parameters, to generate a 2D texture (Texture). Similar function has glTexImage1D, glTexImage3D.
It is noted that, internalformat values, OpenGL ES2.0 and OpenGL 1.0 are different. OpenGL1.0 version supports the value is 1, 2, may be forward compatible in part of the system, but not all forward-compatible with all of the support system, so when using the OpenGL ES 2.0 is best passed above those values as the actual parameters.
Before calling this function must be called glBindTexture (GL_TEXTURE_2D, mTextureID); to specify the operation to the texture ID, here mTextureID.
Application follows below:
unsigned int mTextureID;
glGenTextures(1, &mTextureID);
glBindTexture(GL_TEXTURE_2D, mTextureID );
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) ; // this parameter is set to the texture filter
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) ;
// width, height and other parameters necessary to meet the requirements, not repeat them here. It refers to pixel data pData
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width,height, 0, GL_RGB, GL_UNSIGNED_BYTE, pData );