• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KGLLib

KGLLib::Texture

KGLLib::Texture Class Reference

#include <texture.h>

Inheritance diagram for KGLLib::Texture:

Inheritance graph
[legend]

List of all members.


Detailed Description

2D texture class

Creation

There are several ways how a Texture can be created.

You can convert QImage or QPixmap into a texture. QImage is more efficient here because QPixmap will be first converted into QImage and then into texture.

You can also specify a filename where the texture image should be loaded from. The image file has to be supported by Qt.

Finally, you can create an empty texture, specifying only its size (width and height). In that case you should usually upload the texture contents yourself.

If the creation fails for some reason, the resulting texture cannot be used and isValid() will return false.

Basic usage

To use a texture, first you need to enable texturing and bind the texture. Both of those operations can be achieved by calling enable(). This enables texturing with specific texture type (in this case, 2d textures) and also binds this texture, making it ready to use. Once you are done using the texture, you can call disable() to unbind it and disable texturing.
 // Load texture from image file
 Texture* tex = new Texture("logo.jpg");

 // Enable texturing with this texture
 tex->enable();
 // Render textured geometry
 glBegin(GL_TRIANGLES);
 ...
 glEnd();
 // Disable texturing
 tex->disable();

See also:
TextureBase, Mesh

Definition at line 212 of file texture.h.


Public Member Functions

QImage convertToGLFormat (const QImage &img) const
virtual GLenum glTarget () const
int height () const
void render (const QRectF &rect) const
virtual void setWrapMode (GLenum mode)
QSize size () const
 Texture (int width, int height, GLint internalformat=GL_RGBA, GLint format=0)
 Texture (const QString &filename, GLenum filter=GL_LINEAR_MIPMAP_LINEAR)
 Texture (const QPixmap &pix, GLenum filter=GL_LINEAR_MIPMAP_LINEAR)
 Texture (const QImage &img, GLenum filter=GL_LINEAR_MIPMAP_LINEAR)
int width () const
virtual ~Texture ()

Protected Member Functions

bool init (const QString &filename, GLenum filter)
bool init (const QImage &img, GLenum filter)
bool init (int width, int height, GLint internalformat=GL_RGBA, GLint format=0)

Protected Attributes

int mHeight
int mWidth

Constructor & Destructor Documentation

KGLLib::Texture::Texture ( const QImage &  img,
GLenum  filter = GL_LINEAR_MIPMAP_LINEAR 
) [explicit]

Creates texture from given QImage.

If the image is null image, then the resulting texture will be invalid.

Mipmaps are created automatically unless filter is GL_NEAREST or GL_LINEAR.

Definition at line 234 of file texture.cpp.

KGLLib::Texture::Texture ( const QPixmap &  pix,
GLenum  filter = GL_LINEAR_MIPMAP_LINEAR 
) [explicit]

Creates texture from QPixmap.

If the pixmap is null pixmap, then the resulting texture will be invalid.

Mipmaps are created automatically unless filter is GL_NEAREST or GL_LINEAR.

Definition at line 239 of file texture.cpp.

KGLLib::Texture::Texture ( const QString &  filename,
GLenum  filter = GL_LINEAR_MIPMAP_LINEAR 
) [explicit]

Creates texture from image loaded from the given file.

If the image cannot be loaded, then the resulting texture will be invalid.

Mipmaps are created automatically unless filter is GL_NEAREST or GL_LINEAR.

Definition at line 244 of file texture.cpp.

KGLLib::Texture::Texture ( int  width,
int  height,
GLint  internalformat = GL_RGBA,
GLint  format = 0 
)

Creates texture with the given size.

The texture contents will be undefined until they're specified by user.

internalformat and format parameters describe format of the texture. If format is 0 (default value), then it will be computed automatically based on the value of internalformat.

Definition at line 229 of file texture.cpp.

KGLLib::Texture::~Texture (  )  [virtual]

Definition at line 249 of file texture.cpp.


Member Function Documentation

QImage KGLLib::Texture::convertToGLFormat ( const QImage &  img  )  const

Definition at line 317 of file texture.cpp.

virtual GLenum KGLLib::Texture::glTarget (  )  const [inline, virtual]

TODO: maybe rename to glType().

Returns:
type of this texture (e.g. GL_TEXTURE_2D)

Implements KGLLib::TextureBase.

Definition at line 274 of file texture.h.

int KGLLib::Texture::height (  )  const [inline]

Return height of this texture.

See also:
width(), size()

Definition at line 258 of file texture.h.

bool KGLLib::Texture::init ( const QString &  filename,
GLenum  filter 
) [protected]

Definition at line 301 of file texture.cpp.

bool KGLLib::Texture::init ( const QImage &  img,
GLenum  filter 
) [protected]

Definition at line 279 of file texture.cpp.

bool KGLLib::Texture::init ( int  width,
int  height,
GLint  internalformat = GL_RGBA,
GLint  format = 0 
) [protected]

Definition at line 253 of file texture.cpp.

void KGLLib::Texture::render ( const QRectF &  rect  )  const

void KGLLib::Texture::setWrapMode ( GLenum  mode  )  [virtual]

Sets wrap mode for both horizontal as well as vertical coordinates of this texture.

See also:
Texture::setWrapMode(GLenum coordinate, GLenum mode)

Implements KGLLib::TextureBase.

Definition at line 311 of file texture.cpp.

QSize KGLLib::Texture::size (  )  const [inline]

Return size (width and height) of this texture.

See also:
width(), height()

Definition at line 264 of file texture.h.

int KGLLib::Texture::width (  )  const [inline]

Return width of this texture.

See also:
height(), size()

Definition at line 252 of file texture.h.


Member Data Documentation

int KGLLib::Texture::mHeight [protected]

Definition at line 286 of file texture.h.

int KGLLib::Texture::mWidth [protected]

Definition at line 285 of file texture.h.


The documentation for this class was generated from the following files:
  • texture.h
  • texture.cpp

KGLLib

Skip menu "KGLLib"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KGLLib
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal