DemoGL::Reference::Functions::DEMOGL_TextureCubeMapLoad

DEMOGL_TextureCubeMapLoad

DEMOGL_TextureCubeMapLoad creates a new cubemap texture in the texture store of DemoGL. The data for the six sides of the cubemap is loaded from files with filenames constructed using the name pointed by pszFilename.

GLuint
DEMOGL_TextureLoad(
	const char *pszFilename,
	const int iFileType,
	const GLint iMinFilter,
	const GLint iMagFilter,
	const bool bMipMaps,	
	const bool bCreateAlphaFromColor,	
	const int iBorder,
	const GLint iTexUploadHint
);
	
Parameters.
pszFilename
Pointer to a zero-terminated string which contains the common part of the filename, inclusive relative path, that contains the texturedata. DemoGL will use the name pointed by pszFilename to construct the correct filenames for all the six textures needed to build the cubemap. The extension of the files will be determined from iFileType. DemoGL will add the following strings to the name pointed by pszFilename. As an example in the table below, pszFilename points to the string "mycubemap_" and the textures are of the type DGL_FTYPE_JPGFILE. The table then shows the resulting filenames, thus you should name your texturefiles accordingly, if you want them to end up in the cubemap.

Cube side String added.
Positive X posx

This will result in:
mycubemap_posx.jpg

Negative X negx

This will result in:
mycubemap_negx.jpg

Positive Y posy

This will result in:
mycubemap_posy.jpg

Negative Y negy

This will result in:
mycubemap_negy.jpg

Positive Z posz

This will result in:
mycubemap_posz.jpg

Negative Z negz

This will result in:
mycubemap_negz.jpg

iFileType
Specifies the filetype used in the files to load using pszFilename. iFileType can be one of the following values:

FileType Description
DGL_FTYPE_JPGFILE Imagedata stored using the JPEG format.
DGL_FTYPE_TGAFILE Imagedata stored using the TGA format.
DGL_FTYPE_BMPFILE Imagedata stored using the BMP format.

The value of iFileType generates the extension of the files loaded by DEMOGL_TextureCubeMapLoad.

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). If The ICD supports the extension GL_SGIS_generate_mipmap, the mipmaps are generated using the videocard, otherwise the mipmaps are generated using the gluBuild*DMipmaps() routine.
bCreateAlphaFromColor
Specifies if DemoGL should fill in the Alpha byte in the RGBA value for each pixel using a luminance formula (true) or that it should fill in 0xFF as alpha value, if the texture loaded doesn't contain an alpha channel (false). The luminance formula used is: Alpha = (0.35 * Red) + (0.45 * Green) + (0.20 * Blue).
iBorder
Specifies the width of the textureborder in OpenGL for this texture, normally 0 or 1.
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.

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.
If the videocard doesn't support cubemaps, DEMOGL_TextureCubeMapLoad will fail. Be sure to support the correct common name with the parameter pszFilename. When you load a texture with the same value for pszFilename, DemoGL will increase the reference counter to the loaded texture instead of loading the texturedata again. The texture created is usable for dynamic updates. It's however more wise to use DEMOGL_TextureCubeMapCreateDynamic for creating a dynamic cubemap texture object without data and update the sides of that cubemap using DEMOGL_TextureCubeMapUpdateWithFBRegion. The texture created with DEMOGL_TextureCubeMapLoad can be used with the normal upload/unupload and delete functions for textures: DEMOGL_TextureDelete, DEMOGL_TextureUnUpload and DEMOGL_TextureUpload

Cubemapping is implemented in hardware using the DirectX concepts. This means that negative Z en positive Z are switched. See DemoGL Example 6 for example code on how to use DemoGL to render objects using cubemaps. It's recommended to read nVidia's documentation about cubemaps and OpenGL also on their developer site, especially CubeEnvMapping2.pdf.

DemoGL_glext.h contains all necessary constant definitions for cubemapping. When you use cubemaps in your code, be sure to include DemoGL_glext.h.

DemoGL doesn't support cubemaps stored in DDS files. DDS files are therefor not supported in this routine.

Example.
Below are snippets of the essential code needed to use a cubemap in your effectcode. The snippets below load cubemaps with the common name "test_" of the type JPG and use it on a mesh. This is a typical static cubemap. See DemoGL Example 6 for an example how to use dynamic cubemaps that are updated per frame to reflect a rotating object.
// include the DemoGL_glext.h file to include definitions for the ARB cubemap
// constants
#include "DemoGL_glext.h"

// ...
// Other code
// ...

// Load the cubemap textures "test_*.jpg" into 1 cubemap texture. F.e. in an
// Init() method
m_iTextureCube = DEMOGL_TextureCubeMapLoad("demotex\\test_",DGL_FTYPE_JPGFILE, 
		GL_LINEAR, GL_LINEAR, false, false, 0, GL_RGB5_A1);

// ...
// Other code
// ...

// Upload the texture to OpenGL, f.e. in a Prepare() method
DEMOGL_TextureUpload(m_iTextureCube);

// ...
// Other code
// ...

// Render the mesh using the cubemap, f.e. in a RenderFrame() method
// Enable cubemapping. This will overrule GL_TEXTURE_2D.
glEnable(GL_TEXTURE_CUBE_MAP_ARB);

// Bind to the cubemap texture loaded
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, m_iTextureCube);

// Set the reflection generation functions.
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);

// Enable texturecoordinate generation. Notice the 'R' coordinate
// function, which is needed.
glEnable(GL_TEXTURE_GEN_S); 
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

glColor4f(1.0f,1.0f,1.0f,1.0f);
// draw all faces of the mesh
for(i=0;i<m_pModel->m_iAmFaces;i++)
{
	// draw a face.
	glBegin(GL_TRIANGLES);
	for(j=0;j<3;j++)
	{
		glNormal3fv(&m_pModel->m_pFaces[i].m_vVertexNormals[j][0]);
		glVertex3fv(
			&m_pModel->m_pVertices[
				m_pModel->m_pFaces[i].m_iVertexIndices[j]][0]);
		glTexCoord2f(0.0f,0.0f);
	}
	glEnd();
}
// disable cubemap 
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
// Disable the texture generation functions.
glDisable(GL_TEXTURE_GEN_R);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_S);
	

Requirements.
DemoGL v1.31 (build 0528 or higher), Cubemap support in hardware (GeForce card series and ATi Radeon card series)

See also.
DEMOGL_TextureDelete, DEMOGL_TextureUnUpload, DEMOGL_TextureUpload, DEMOGL_TextureCubeMapCreateDynamic, DEMOGL_TextureCubeMapUpdateWithFBRegion

Last changed on 28-may-2001

©1999-2001 Solutions Design