Thursday, May 26, 2011

glTexCoordPointer example c/c++ java

Name

glTexCoordPointer - define an array of texture coordinates

C Specification

void glTexCoordPointer(GLint size,
    GLenum type,
    GLsizei stride,
    const GLvoid * pointer)

Parameters

size
Specifies the number of coordinates per array element. Must be 2, 3 or 4. The initial value is 4.
type
Specifies the data type of each texture coordinate. Symbolic constants GL_BYTE, GL_SHORT, and GL_FIXED are accepted. However, the initial value is GL_FLOAT. The common profile accepts the symbolic constant GL_FLOAT as well.(glTexCoordPointer)
stride
Specifies the byte offset between consecutive array elements. If stride is 0, the array elements are understood to be tightly packed. The initial value is 0.
pointer
Specifies a pointer to the first coordinate of the first element in the array. The initial value is 0.

Description

glTexCoordPointer specifies the location and data of an array of texture coordinates to use when rendering. size specifies the number of coordinates per element, and must be 2, 3, or 4. type specifies the data type of each texture coordinate and stride specifies the byte stride from one array element to the next allowing vertices and attributes to be packed into a single array or stored in separate arrays. (Single-array storage may be more efficient on some implementations.)
When a texture coordinate array is specified, size, type, stride, and pointer are saved as client-side state. (glTexCoordPointer)
If the texture coordinate array is enabled, it is used when glDrawArrays, or glDrawElements is called. To enable and disable the texture coordinate array for the client-side active texture unit, call glEnableClientState and glDisableClientState with the argument GL_TEXTURE_COORD_ARRAY. The texture coordinate array is initially disabled for all client-side active texture units and isn't accessed when glDrawArrays or glDrawElements is called.
Use glDrawArrays to construct a sequence of primitives (all of the same type) from prespecified vertex and vertex attribute arrays. Use glDrawElements to construct a sequence of primitives by indexing vertices and vertex attributes.

Notes

glTexCoordPointer is typically implemented on the client side.
glTexCoordPointer updates the texture coordinate array state of the client-side active texture unit, specified with glClientActiveTexture.

Errors

GL_INVALID_VALUE is generated if size is not 2, 3, or 4.
GL_INVALID_ENUM is generated if type is not an accepted value.
GL_INVALID_VALUE is generated if stride is negative.

Copyright

Copyright © 2003 Silicon Graphics, Inc.
This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.

See Also

glClientActiveTexture, glColorPointer, glDrawArrays, glDrawElements, glEnable, glMultiTexCoord, glNormalPointer, glVertexPointer

Example of glTexCoordPointer

static const GLfloat squareTexCoord[] = {
        0, 1,
        1, 1,
        0, 0,
        1, 0,
 };


glBindTexture(GL_TEXTURE_2D, m_Tex.TexID);
glVertexPointer(2, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, squareTexCoord);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);