GLboolean glIsTexture(GLuint textureName); |
void glBindTexture(GLenum target, GLuint textureName); |
glBindTexture() does three things. When using textureName of an unsigned integer other than zero for the first time, a new texture object is created and assigned that name. When binding to a previously created texture object, that texture object becomes active. When binding to a textureName value of zero, OpenGL stops using texture objects and returns to the unnamed default texture. When a texture object is initially bound (that is, created), it assumes the dimensionality of target, which is either GL_TEXTURE_1D or GL_TEXTURE_2D. Immediately upon its initial binding, the state of texture object is equivalent to the state of the default GL_TEXTURE_1D or GL_TEXTURE_2D (depending upon its dimensionality) at the initialization of OpenGL. In this initial state, texture properties such as minification and magnification filters, wrapping modes, border color, and texture priority are set to their default values. |
void glTexParamater{if}(GLenum target, GLenum pname, TYPE param); void glTexParamater{if}v(GLenum target, GLenum pname, TYPE *param); |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
Parameter | Values |
---|---|
GL_TEXTURE_WRAP_S | GL_CLAMP, GL_REPEAT |
GL_TEXTURE_WRAP_T | GL_CLAMP, GL_REPEAT |
GL_TEXTURE_MAG_FILTER | GL_NEAREST, GL_LINEAR |
GL_TEXTURE_MIN_FILTER | GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR |
GL_TEXTURE_BORDER_COLOR | any four values in [0.0, 1.0] |
GL_TEXTURE_PRIORITY | [0.0, 1.0] for the current texture object |
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
Table 9-3. glPixelStore() Parameters
Parameter Name | Type | Initial Value | Valid Range |
---|---|---|---|
GL_UNPACK_SWAP_BYTES, GL_PACK_SWAP_BYTES | GLboolean | FALSE | TRUE/FALSE |
GL_UNPACK_LSB_FIRST, GL_PACK_LSB_FIRST | GLboolean | FALSE | TRUE/FALSE |
GL_UNPACK_ROW_LENGTH, GL_PACK_ROW_LENGTH | GLint | 0 | any nonnegative integer |
GL_UNPACK_SKIP_ROWS, GL_PACK_SKIP_ROWS | GLint | 0 | any nonnegative integer |
GL_UNPACK_SKIP_PIXELS, GL_PACK_SKIP_PIXELS | GLint | 0 | any nonnegative integer |
GL_UNPACK_ALIGNMENT, GL_PACK_ALIGNMENT | GLint | 4 | 1, 2, 4, 8 |
void glTexCoord {1234}{sifd}(TYPE
coords); void glTexCoord{1234}{sifd}v(TYPE *coords); |
Sets the current texture coordinates (s, t, r, q). Subsequent calls to glVertex*() result in those vertices being assigned the current texture coordinates. With glTexCoord1*(), the s coordinate is set to the specified value, t and r are set to 0, and q is set to 1. Using glTexCoord2*() allows you to specify s and t; r and q are set to 0 and 1, respectively. With glTexCoord3*(), q is set to 1 and the other coordinates are set as specified. You can specify all coordinates with glTexCoord4*(). Use the appropriate suffix (s, i, f, or d) and the corresponding value for TYPE (GLshort, GLint, GLfloat, or GLdouble) to specify the coordinates' data type. You can supply the coordinates individually, or you can use the vector version of the command to supply them in a single array. Texture coordinates are multiplied by the 4×4 texture matrix before any texture mapping occurs. (See “The Texture Matrix Stack.”) Note that integer texture coordinates are interpreted directly rather than being mapped to the range [-1,1] as normal coordinates are. |
glMatrixMode(GL_TEXTURE); glPushMatrix(); glRotatef(10, 0, 0, 1); draw_something_with_texture_coords(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); |
void glTexGen{ifd}(GLenum coord, GLenum pname, TYPE param); void glTexGen{ifd}v(GLenum coord, GLenum pname, TYPE *param); |
Specifies the functions for automatically generating texture coordinates. The first parameter, coord, must be GL_S, GL_T, GL_R, or GL_Q to indicate whether texture coordinate s, t, r, or q is to be generated. The pname parameter is GL_TEXTURE_GEN_MODE, GL_OBJECT_PLANE, or GL_EYE_PLANE. If it's GL_TEXTURE_GEN_MODE, param is an integer (or, in the vector version of the command, points to an integer) that's either GL_OBJECT_LINEAR, GL_EYE_LINEAR, or GL_SPHERE_MAP. These symbolic constants determine which function is used to generate the texture coordinate. With either of the other possible values for pname, param is a pointer to an array of values (for the vector version) specifying parameters for the texture-generation function. |
#include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> #include <stdlib.h> GLubyte mipmapImage32[32][32][4]; GLubyte mipmapImage16[16][16][4]; GLubyte mipmapImage8[8][8][4]; GLubyte mipmapImage4[4][4][4]; GLubyte mipmapImage2[2][2][4]; GLubyte mipmapImage1[1][1][4]; static GLuint texName; void makeImages(void) { int i, j; for (i = 0; i < 32; i++) { for (j = 0; j < 32; j++) { mipmapImage32[i][j][0] = 255; mipmapImage32[i][j][1] = 255; mipmapImage32[i][j][2] = 0; mipmapImage32[i][j][3] = 255; } } for (i = 0; i < 16; i++) { for (j = 0; j < 16; j++) { mipmapImage16[i][j][0] = 255; mipmapImage16[i][j][1] = 0; mipmapImage16[i][j][2] = 255; mipmapImage16[i][j][3] = 255; } } for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { mipmapImage8[i][j][0] = 255; mipmapImage8[i][j][1] = 0; mipmapImage8[i][j][2] = 0; mipmapImage8[i][j][3] = 255; } } for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { mipmapImage4[i][j][0] = 0; mipmapImage4[i][j][1] = 255; mipmapImage4[i][j][2] = 0; mipmapImage4[i][j][3] = 255; } } for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { mipmapImage2[i][j][0] = 0; mipmapImage2[i][j][1] = 0; mipmapImage2[i][j][2] = 255; mipmapImage2[i][j][3] = 255; } } mipmapImage1[0][0][0] = 255; mipmapImage1[0][0][1] = 255; mipmapImage1[0][0][2] = 255; mipmapImage1[0][0][3] = 255; } void init(void) { glEnable(GL_DEPTH_TEST); glShadeModel(GL_FLAT); glTranslatef(0.0, 0.0, -3.6); makeImages(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &texName); glBindTexture(GL_TEXTURE_2D, texName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage32); glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage16); glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage8); glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage4); glTexImage2D(GL_TEXTURE_2D, 4, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage2); glTexImage2D(GL_TEXTURE_2D, 5, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage1); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glEnable(GL_TEXTURE_2D); } void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, texName); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); glTexCoord2f(0.0, 8.0); glVertex3f(-2.0, 1.0, 0.0); glTexCoord2f(8.0, 8.0); glVertex3f(2000.0, 1.0, -6000.0); glTexCoord2f(8.0, 0.0); glVertex3f(2000.0, -1.0, -6000.0); glEnd(); glFlush(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 1.0, 30000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void keyboard (unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; default: break; } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutInitWindowPosition(50, 50); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; } |
![]() |
From glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); to glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); |
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 512, 256, GL_RGB, GL_UNSIGNED_BYTE, mytexture); |
int gluBuild1DMipmaps( GLenum target, GLint internalFormat, GLint width, GLenum format, GLenum type, void *texels ); int gluBuild2DMipmaps( GLenum target, GLint internalFormat, GLint width, GLint height, GLenum format, GLenum type, void *texels ); int gluBuild3DMipmaps( GLenum target, GLint internalFormat, GLint width, GLint height, GLint depth, GLenum format, GLenum type, void *texels ); |