Top | ![]() |
![]() |
![]() |
![]() |
#define | LW_TEX_COORD_X() |
#define | LW_TEX_COORD_XY() |
#define | LW_TEX_COORD_Y() |
#define | LW_TEX_COORD_YX() |
LwTexture * | lw_texture_new_from_data () |
LwTexture * | lw_texture_new_from_file () |
LwTexture * | lw_texture_new_from_pixbuf () |
LwTexture * | lw_texture_new_from_resource () |
void | lw_texture_disable () |
void | lw_texture_enable () |
guint | lw_texture_get_filter () |
guint | lw_texture_get_height () |
guint | lw_texture_get_name () |
guint | lw_texture_get_target () |
guint | lw_texture_get_width () |
guint | lw_texture_get_wrap () |
void | lw_texture_set_filter () |
void | lw_texture_set_wrap () |
void | lw_texture_bind () |
gboolean | lw_texture_bind_to () |
gint | lw_texture_get_max_texture_units () |
void | lw_texture_unbind () |
LwTexture is an easy way to work with OpenGL textures.
There are three ways to create a LwTexture. The easiest way is
to load an image file (lw_texture_new_from_file()
), but you can also
use an existing GdkPixbuf (lw_texture_new_from_pixbuf()
). The last
option is to create a texture directly out of in-memory image data
(lw_texture_new_from_data()
). In each case you should free the LwTexture
if you don't need it anymore by using g_object_unref()
.
LwTexture only supports 2D textures at the moment.
Use lw_texture_enable()
to bind the texture. This does everything that is
needed to use the texture. If you are finished with drawing, use lw_texture_disable()
.
Example 6. Using a LwTexture
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
GError *error = NULL; LwTexture *tex = lw_texture_new_from_file("/path/to/texture.image", &error); if(error != NULL) { g_warning("Could not load the texture: %s", error->message); g_error_free(error); return; } lw_texture_enable(tex); // Draw your textured object here, for example a quad glBegin(GL_QUADS); glTexCoord2f(...); glVertex3f(...); ... glEnd(); lw_texture_disable(tex); |
#define LW_TEX_COORD_X(m, px) ((m).xx * (px) + (m).x0)
Transforms the X coordinate by a 2D texture matrix.
#define LW_TEX_COORD_XY(m, px, py) ((m).xx * (px) + (m).xy * (py) + (m).x0)
Transforms the X coordinate by a 2D texture matrix.
Use this macro if the LwTextureMatrix rotates the texture coordinates, otherwise use LW_TEX_COORD_X.
#define LW_TEX_COORD_Y(m, py) ((m).yy * (py) + (m).y0)
Transforms the Y coordinate by a 2D texture matrix.
#define LW_TEX_COORD_YX(m, px, py) ((m).yx * (px) + (m).yy * (py) + (m).y0)
Transforms the Y coordinate by a 2D texture matrix.
Use this macro if the LwTextureMatrix rotates the texture coordinates, otherwise use LW_TEX_COORD_Y.
LwTexture * lw_texture_new_from_data (const guchar *data
,guint width
,guint height
,guint format
,guint type
);
Creates a new texture out of in-memory image data. Internally glTexImage2D
is used to create the texture. You can find a more detailed description of
format
and type
on the documentation page of glTexImage2D.
You have to free the image data
by yourself. You can free it directly after
calling this function, LwTexture does not need it anymore.
LwTexture *
lw_texture_new_from_file (const gchar *path
);
Creates a new texture by loading an image from a file. This function supports
all file formats supported by gdk-pixbuf. If NULL
is returned, then error
will
be set. Internally the image file will be loaded into a GdkPixbuf first before
creating the LwTexture.
A new LwTexture, or NULL
in case of an error. You should use
g_object_unref()
to free the LwTexture.
Since: 0.5
LwTexture *
lw_texture_new_from_pixbuf (GdkPixbuf *pixbuf
);
Creates a new texture by using the image data of the GdkPixbuf.
You have to free the pixbuf
by yourself. You can free it directly after
calling this function, LwTexture does not need it anymore.
LwTexture *
lw_texture_new_from_resource (const gchar *path
);
Creates a new texture by loading an image from a gresource. This function supports
all file formats supported by gdk-pixbuf. If NULL
is returned, then error
will
be set. Internally the image file will be loaded into a GdkPixbuf first before
creating the LwTexture.
A new LwTexture, or NULL
in case of an error. You should use
g_object_unref()
to free the LwTexture.
Since: 0.5
guint
lw_texture_get_target (LwTexture *self
);
Returns the texture's target. At the moment only GL_TEXTURE_2D is supported, so this function always returns GL_TEXTURE_2D.
void lw_texture_set_filter (LwTexture *self
,guint filter
);
Sets the texture's minifying and magnification function. Possible values are GL_NEAREST and GL_LINEAR. GL_NEAREST is generally faster than GL_LINEAR, but it produces sharper edges. LwTexture uses GL_NEAREST by default.
To get a more detailed description of all possible filters, take a look at the documentation page of glTexParameter. This functions sets the GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER at the same time, so only filters supported by both are vaild arguments.
void lw_texture_set_wrap (LwTexture *self
,guint wrap
);
Sets the wrap parameter for texture coordinate s and t. The wrap parameter is set to GL_CLAMP_TO_EDGE by default.
This functions calls glTexParameter for GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T. You can find a complete list of all supported parameters at the documentation page of glTexParameter.
void
lw_texture_bind (LwTexture *self
);
Uses lw_texture_bind_to()
to bind this texture to the texture unit 0. If you just need one texture
this is the function to use. If you want to use multiple textures with a fragment shader, take a look
at lw_program_set_texture()
or lw_texture_bind_to()
.
Since: 0.5
gboolean lw_texture_bind_to (LwTexture *self
,guint unit
);
Binds the texture self
to the specified texture unit. If you just need one texture, the
lw_texture_bind()
function might be simpler to use. You usually do not have to use this
function directly if you use lw_program_set_texture()
.
Before binding the specified texture to its target using glBindTexture, it switches to the specified texture unit using glActiveTexture.
Since: 0.5
void
lw_texture_unbind (LwTexture *self
);
Unbinds the texture by binding 0 to the texture's target. This operation
switches to the texture unit specified by lw_texture_bind()
or lw_texture_bind_to()
using glActiveTexture.
This function unbinds every texture currently bound to the same target and texture unit of self
,
even if self
is not the active texture.
Since: 0.5
struct LwTexture { LwTextureMatrix matrix; };
A structure for easier OpenGL texture handling.
“height”
property“height” guint
The height of the texture
Flags: Read / Write / Construct Only
Default value: 0
“target”
property“target” guint
The texture's target
Flags: Read / Write / Construct Only
Default value: 3553
“width”
property“width” guint
The width of the texture
Flags: Read / Write / Construct Only
Default value: 0