Guha's Texture Example Code
- This is in "Old" OpenGL
- But I will produce some in "New" OpenGL by next Monday.
- Code
- It also involves an image file
- getbmp
- Is a routine that reads in a .bmp file format
- Is not outside the scope of the class, but is not very interesting.
- Just parsing data according to a given format
- Some binary level io and file manipulation.
- loadTextures
- void glGenTextures(GLsizei n, GLuint * textures);
- As with other Gen commands generats names for textures.
- glDeleteTextures
- glLsTexture
- void glBindTexture(GLenum target, GLuint texture);
- Create or use a named texture, as before
- Called once to set things up.
- Called once each time a texture is used.
- Target:
- GL_TEXTURE_2D
- GL_TEXTURE_CUBE_MAP
- Name: returned from glGenTextures
- void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data);
- Maps data to a currently bound texture
- target:
- GL_TEXTURE_2D
- GL_TEXTURE_CUBE_MAP_POSITIVE_X
- GL_TEXTURE_CUBE_MAP_NEGATIVE_X
- GL_TEXTURE_CUBE_MAP_POSITIVE_Y
- GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
- GL_TEXTURE_CUBE_MAP_POSITIVE_Z
- GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
- level: O or higher, n>0 for mipmaps (later)
- internal format:
- GL_ALPHA
- GL_LUMINANCE
- GL_LUMINANCE_ALPHA
- GL_RGB
- GL_RGBA
- width, height
- border: must be 0
- format: must match internal format, same values accepted
- type:
- GL_UNSIGNED_BYTE
- GL_UNSIGNED_SHORT_5_6_5
- GL_UNSIGNED_SHORT_4_4_4_4
- and GL_UNSIGNED_SHORT_5_5_5_1
- data: a pointer to the data.
- void glTexParameteri( GLenum target, GLenum pname, GLint param);
- target: as in glTexImage2D
- pname:
- GL_TEXTURE_MIN_FILTER
- GL_TEXTURE_MAG_FILTER
- GL_TEXTURE_WRAP_S
- or GL_TEXTURE_WRAP_T
- value: wat to set it to.
- void glTexEnvf( GLenum target, GLenum pname, GLfloat param);
- target: GL_TEXTURE_ENV or GL_POINT_SPRITE_OES
- pname:
- GL_TEXTURE_ENV_MODE
- GL_COMBINE_RGB
- GL_COMBINE_ALPHA
- GL_SRC0_RGB
- GL_SRC1_RGB
- GL_SRC2_RGB
- GL_SRC0_ALPHA
- GL_SRC1_ALPHA
- GL_SRC2_ALPHA
- GL_OPERAND0_RGB
- GL_OPERAND1_RGB
- GL_OPERAND2_RGB
- GL_OPERAND0_ALPHA
- GL_OPERAND1_ALPHA
- GL_OPERAND2_ALPHA
- GL_RGB_SCALE
- GL_ALPHA_SCALE
- or GL_COORD_REPLACE_OES.
- Param:
- GL_ADD
- GL_ADD_SIGNED
- GL_DOT3_RGB
- GL_DOT3_RGBA
- GL_INTERPOLATE
- GL_MODULATE
- GL_DECAL
- GL_BLEND
- GL_REPLACE
- GL_SUBTRACT
- GL_COMBINE
- GL_TEXTURE
- GL_CONSTANT
- GL_PRIMARY_COLOR
- GL_PREVIOUS
- GL_SRC_COLOR
- GL_ONE_MINUS_SRC_COLOR
- GL_SRC_ALPHA
- GL_ONE_MINUS_SRC_ALPHA
- a single boolean value for the point sprite texture coordinate replacement, or 1.0, 2.0
- or 4.0 when specifying the GL_RGB_SCALE or GL_ALPHA_SCALE.
- void glTexCoord2f( GLfloat s, GLfloat t)
- s and t coordinates in a texture