CGPdocs

opengl_texture_image_structure

Initializing a texture copies an image_structure to GPU memory and keeps its id and size; on a quad, uv runs from (0,0) to (1,1) and the default shader reads (u, 1-v), so the first row of the file shows at the top.
Initializing a texture copies an image_structure to GPU memory and keeps its id and size; on a quad, uv runs from (0,0) to (1,1) and the default shader reads (u, 1-v), so the first row of the file shows at the top. Tap to enlarge.
With uv beyond [0,1], GL_REPEAT tiles the image, GL_MIRRORED_REPEAT flips every other copy, and GL_CLAMP_TO_EDGE (the default) stretches the edge texels.
With uv beyond [0,1], GL_REPEAT tiles the image, GL_MIRRORED_REPEAT flips every other copy, and GL_CLAMP_TO_EDGE (the default) stretches the edge texels. Tap to enlarge.

Fields and methods

Members of the struct opengl_texture_image_structure. Most of what you do with a CGP type goes through the free functions listed below.

Fields

GLuint id = 0OpenGL id of the texture, 0 when no texture is allocated.
int width = 0Width of the texture in pixels.
int height = 0Height of the texture in pixels.
GLint format = 0Internal format of the texture, such as GL_RGB8, GL_RGBA8, GL_RGB32F or GL_DEPTH_COMPONENT.
GLenum texture_type = 0Texture target, GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP, used by bind and unbind.

Methods

Binds the texture to its target on the currently active texture unit, asserting that id is not 0. src
Binds texture 0 to the target of this texture on the currently active texture unit. src
Deletes the texture on the GPU and resets all fields to their default values, asserting that id is not 0. src
Sets the wrap modes in s and t (GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT, ...) on the target of the texture (texture_type) after binding it. src
Loads a PNG or JPG file with image_load_file and creates a GL_TEXTURE_2D from it, with clamp-to-edge wrapping and mipmaps by default. src
void initialize_texture_2d_on_gpu(image_structure const& im, GLint wrap_s = GL_CLAMP_TO_EDGE, GLint wrap_t = GL_CLAMP_TO_EDGE, bool is_mipmap = true, GLint texture_mag_filter = GL_LINEAR, GLint texture_min_filter = GL_LINEAR_MIPMAP_LINEAR)Creates a new GL_TEXTURE_2D in GL_RGB8 or GL_RGBA8 from the image, with clamp-to-edge wrapping and mipmaps by default, without deleting a previously allocated texture.3 overloads src
void initialize_texture_2d_on_gpu(grid_2D<vec3> const& im, GLint wrap_s = GL_CLAMP_TO_EDGE, GLint wrap_t = GL_CLAMP_TO_EDGE, bool is_mipmap = true, GLint texture_mag_filter = GL_LINEAR, GLint texture_min_filter = GL_LINEAR_MIPMAP_LINEAR)Creates a new GL_TEXTURE_2D in GL_RGB32F from a grid of float RGB colors, with clamp-to-edge wrapping and mipmaps by default, without deleting a previously allocated texture. src
void initialize_texture_2d_on_gpu(int width_arg, int height_arg, GLint format_arg = GL_RGB8, GLenum texture_type_arg = GL_TEXTURE_2D, GLint wrap_s = GL_CLAMP_TO_EDGE, GLint wrap_t = GL_CLAMP_TO_EDGE, GLint texture_mag_filter = GL_LINEAR, GLint texture_min_filter = GL_LINEAR)Allocates an uninitialized texture of the given size, format and target without mipmap, typically used as a render target. src
Creates a GL_TEXTURE_CUBE_MAP from six square images of the same size and color type (faces -x, +x, -y, +y, -z, +z), with clamp-to-edge wrapping, linear filtering and no mipmap. src
void update(grid_2D<vec3> const& im)Overwrites the texture pixels with the grid content using glTexSubImage2D, read with the component type of the current format, and regenerates the mipmaps.2 overloads src
void update(image_structure const& im)Overwrites the texture pixels with the image content using glTexSubImage2D, read with the component type of the current format, and regenerates the mipmaps. src

Functions taking a opengl_texture_image_structure

None.

Functions returning a opengl_texture_image_structure

None.

Operators

None.

CGP - Computer Graphics Programming.