libg3d Reference Manual | ||||
---|---|---|---|---|
#include <g3d/texture.h> #define G3D_FLAG_IMG_GREYSCALE enum G3DTexEnv; G3DImage; G3DImage* g3d_texture_load_cached (G3DContext *context, G3DModel *model, const gchar *filename); G3DImage* g3d_texture_load_from_stream (G3DContext *context, G3DModel *model, G3DStream *stream); G3DImage* g3d_texture_load (G3DContext *context, const gchar *filename); void g3d_texture_free (G3DImage *texture); gboolean g3d_texture_prepare (G3DImage *texture); gboolean g3d_texture_flip_y (G3DImage *texture); G3DImage* g3d_texture_merge_alpha (G3DImage *image, G3DImage *aimage);
A texture is an image used in materials. Here are some helper functions, mostly for cached loading of a G3DImage.
#define G3D_FLAG_IMG_GREYSCALE (1L << 1)
The image just uses the red channel for grey value
typedef enum { G3D_TEXENV_UNSPECIFIED = 0, G3D_TEXENV_BLEND, G3D_TEXENV_DECAL, G3D_TEXENV_MODULATE, G3D_TEXENV_REPLACE } G3DTexEnv;
Specify how the texture should interact with other material properties.
typedef struct { gchar *name; guint32 width; guint32 height; guint8 depth; guint32 flags; guint8 *pixeldata; guint32 tex_id; G3DTexEnv tex_env; G3DFloat tex_scale_u; G3DFloat tex_scale_v; } G3DImage;
Object containing a two-dimensional pixel image.
gchar * |
name of image |
guint32 |
width of image in pixels |
guint32 |
height of image in pixels |
guint8 |
depth of image in bits |
guint32 |
flags |
guint8 * |
the binary image data |
guint32 |
the OpenGL texture id, should be unique model-wide |
G3DTexEnv |
texture environment flags |
G3DFloat |
factor scaling texture width, should be 1.0 for most cases |
G3DFloat |
factor scaling texture height, should be 1.0 for most cases |
G3DImage* g3d_texture_load_cached (G3DContext *context, G3DModel *model, const gchar *filename);
Loads a texture image from file and attaches it to a hash table in the model. On a second try to load this texture it is returned from cache.
|
a valid context |
|
a valid model |
|
the file name of the texture to load |
Returns : |
the texture image |
G3DImage* g3d_texture_load_from_stream (G3DContext *context, G3DModel *model, G3DStream *stream);
Load a texture image from a stream. The file type is determined by the
extension of the stream URI, so it should be valid. If model
is not NULL
the texture image is cached (or retrieved from cache if available).
|
a valid context |
|
a valid model or NULL |
|
an open stream |
Returns : |
the texture image or NULL in case of an error. |
G3DImage* g3d_texture_load (G3DContext *context, const gchar *filename);
Load a texture from a file. The type of file is determined by the file extension.
|
a valid context |
|
the file name of the texture |
Returns : |
the texture image or NULL in case of an error. |
void g3d_texture_free (G3DImage *texture);
Frees all memory used by this texture image.
|
a texture image |
gboolean g3d_texture_prepare (G3DImage *texture);
Resizes the image to dimensions which are a power of 2 to be usable as an OpenGL texture. (FIXME: unimplemented)
|
a texture image |
Returns : |
TRUE on success, FALSE else |
gboolean g3d_texture_flip_y (G3DImage *texture);
Mirror the image along the x axis - all y coordinates are inverted.
|
a texture image |
Returns : |
TRUE on success, FALSE on error. |
G3DImage* g3d_texture_merge_alpha (G3DImage *image, G3DImage *aimage);
Merges alpha information from aimage
into output image. If image
is NULL a
new image is created, else image
is returned with alpha from aimage
.
|
a texture image or NULL |
|
an image with alpha information |
Returns : |
a texture image or NULL in case of an error. |