DemoGL::Reference::Functions::DEMOGL_TextureCreateFromBuffer

DEMOGL_TextureCreateFromBuffer

DEMOGL_TextureCreateFromBuffer creates a new texture in the texture store of DemoGL from the data in the buffer passed.

GLuint
DEMOGL_TextureCreateFromBuffer(
	const int iWidth,
	const int iHeight,
	const int iDepth,
	const byte *pbyBuffer,
	const char *pszIdentName,
	const int iBorder,
	const GLint iWrapS, 
	const GLint iWrapT,
	const GLint iMinFilter,
	const GLint iMagFilter,
	const bool bMipMaps,	
	const GLint iTexUploadHint,
	const int iDimensions
);
	
Parameters.
iWidth
Specifies the width of the texture, which pixeldata is stored in the buffer pointed by pbyBuffer in pixels. Must be 2n + 2(iBorder) for some integer n.
iHeight
Specifies the height of the texture, which pixeldata is stored in the buffer pointed by pbyBuffer in pixels. Must be 2n + 2(iBorder) for some integer n.
iDepth
Specifies the depth of the texture, which pixeldata is stored in the buffer pointed by pbyBuffer in pixels. This is the 3rd dimension of the texture. For 2D textures, specify 0. 3D texture support is implemented in DemoGL allthough not directly usable due to the lack of OpenGL 1.2 functionality in the Windows implementation of OpenGL.
pbyBuffer
Pointer to the buffer with the color fragments of the buffer. Only buffers with 32bpp color fragments are supported. Per pixel there should be 1 byte for each color fragment R, G, B and A, in that order. The data in the buffer will be copied into the texture's own pixeldata store, so after calling DEMOGL_TextureCreateFromBuffer, the buffer can be freed.
pszIdentName
Pointer to a zero-terminated string which represents the name of the texture so other effects which will load the same texture by specifying the same name will receive a reference to this texture instead. Normally textures are globally referenced by the filename of the file with the texturedata, for textures created from a buffer there is no file, so you can specify any string as IdentName.
iBorder
Specifies the width of the textureborder in OpenGL for this texture, normally 0 or 1.
iWrapS
Sets the wrap parameter for texture coordinate s to either GL_CLAMP or GL_REPEAT. GL_CLAMP causes s coordinates to be clamped to the range [0,1] and is useful for preventing wrapping artifacts when mapping a single image onto an object. GL_REPEAT causes the integer part of the s coordinate to be ignored; OpenGL uses only the fractional part, thereby creating a repeating pattern. Border texture elements are accessed only if wrapping is set to GL_CLAMP. Initially, GL_TEXTURE_WRAP_S is set to GL_REPEAT.
iWrapT
As iWrapS but now for texture coordinate t.
iMinFilter
Sets the texture minifying function. Can be one of the following values:

Value Meaning
GL_NEAREST Returns the value of the texture element that is nearest (in Manhattan distance) to the center of the pixel being textured.
GL_LINEAR Returns the weighted average of the four texture elements that are closest to the center of the pixel being textured. These can include border texture elements, depending on the values of iWrapS, iWrapT, and on the exact mapping. GL_NEAREST is generally faster than GL_LINEAR, but it can produce textured images with sharper edges because the transition between texture elements is not as smooth.
GL_NEAREST_MIPMAP_NEAREST Chooses the mipmap that most closely matches the size of the pixel being textured and uses the GL_NEAREST criterion (the texture element nearest to the center of the pixel) to produce a texture value.
GL_LINEAR_MIPMAP_NEAREST Chooses the mipmap that most closely matches the size of the pixel being textured and uses the GL_LINEAR criterion (a weighted average of the four texture elements that are closest to the center of the pixel) to produce a texture value.
GL_NEAREST_MIPMAP_LINEAR Chooses the two mipmaps that most closely match the size of the pixel being textured and uses the GL_NEAREST criterion (the texture element nearest to the center of the pixel) to produce a texture value from each mipmap. The final texture value is a weighted average of those two values.
GL_LINEAR_MIPMAP_LINEAR Chooses the two mipmaps that most closely match the size of the pixel being textured and uses the GL_LINEAR criterion (a weighted average of the four texture elements that are closest to the center of the pixel) to produce a texture value from each mipmap. The final texture value is a weighted average of those two values.

iMagFilter
Sets the texture magnification function. The texture magnification function is used when the pixel being textured maps to an area less than or equal to one texture element. It sets the texture magnification function to either GL_NEAREST or GL_LINEAR.
bMipMaps
Specifies if DemoGL should create mipmaps from the supplied texture data (true) or not (false).
iTexUploadHint
Specifies the upload hint which should be used when DemoGL uploads the texture data to OpenGL. This hint is ment for the situation when the user has selected 16bit textures ONLY. In this situation normally DemoGL selects GL_RGBA4 as texturehint for the upload process to OpenGL, so you'll get better alphachannel support. If this isn't necessary in a situation, because the texture doesn't use the alphavalues, you can specify an overruling hint for DemoGL to pass on to OpenGL in 16bit. A good hint for nonalpha textures is GL_RGB5_A1. In situations where the user has selected 32bit textures (recommended, since the driver will transform these to 16bit if necessary and will dither, which gives better results) this hint is ignored and GL_RGBA8 is used. If DemoGL should use the default hint for this texture whenever it has to, set iTexUploadHint to DGL_TEXHINT_USEDEFAULT.
iDimensions
Specifies the amount of dimensions of the texture, needed for the upload process of the texture data to OpenGL. Can be one of the following values: DGL_TEXTUREDIMENSION_1D for 1D textures (only iWidth is used), DGL_TEXTUREDIMENSION_2D for 2D textures (only iWidth and iHeight are used) or DGL_TEXTUREDIMENSION_3D for 3D textures, which is currently not implemented in full in DemoGL.

Return values.
If the function succeeds, it returns the TextureID, or texture name, usable with functions in OpenGL like glBindTexture.
If the function failes, 0 is returned.

Remarks.
Support for 3D textures is not fully implemented in DemoGL due to the lack of OpenGL 1.2 support in the Windows OpenGL implementation. Data passed in the buffer should be uncompressed RGBA data. When you load a texture with a filename the same as pszIdentName DemoGL will increase the reference counter to the loaded texture.

Example.

Requirements.
DemoGL v1.3 (build 0112 or higher)

See also.
DEMOGL_TextureDelete, DEMOGL_TextureLoad, DEMOGL_TextureUnUpload, DEMOGL_TextureUpload

Last changed on 20-jan-2001

©1999-2001 Solutions Design