DeferredRenderer 1.0

Texture Class Reference

Wrapper for a GL texture. More...

#include <Texture.h>

List of all members.

Public Member Functions

 Texture ()
 default ctor
 Texture (const std::string &_name)
 ctor w/name
 ~Texture ()
 dtor
void generateEmpty (int _width, int _height)
 generate empty RGBA
void generateEmptyf (int _width, int _height)
 generate empty RGAB (32bit float)
void generateDepth (int _width, int _height)
 generate empty depth
void generateFromFile (char *_filePath)
 generate texture from filepath
void bind ()
 bind this texture
std::string getName ()
 get the texture by name

Public Attributes

GLuint id
 handle for this texture

Private Attributes

int m_width
 texture dimensions
int m_height
std::string m_name
 the texture name

Detailed Description

Wrapper for a GL texture.

Definition at line 14 of file Texture.h.


Constructor & Destructor Documentation

Texture::Texture ( ) [inline]

default ctor

Definition at line 21 of file Texture.h.

{}
Texture::Texture ( const std::string &  _name)

ctor w/name

Definition at line 4 of file Texture.cpp.

:id(0),m_width(0),m_height(0),m_name(_name){}
Texture::~Texture ( )

dtor

Definition at line 5 of file Texture.cpp.

{}

Member Function Documentation

void Texture::bind ( ) [inline]

bind this texture

Definition at line 40 of file Texture.h.

{glBindTexture(GL_TEXTURE_2D, id);}
void Texture::generateDepth ( int  _width,
int  _height 
)

generate empty depth

Definition at line 47 of file Texture.cpp.

References m_height, and m_width.

{
    m_height = _height;
    m_width = _width;

    glGenTextures(1, &id);
    glBindTexture(GL_TEXTURE_2D, id);

    // Set the texture's stretching properties
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE  );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE  );
    glGenerateMipmap(GL_TEXTURE_2D);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32,  m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
}
void Texture::generateEmpty ( int  _width,
int  _height 
)

generate empty RGBA

Definition at line 7 of file Texture.cpp.

References m_height, and m_width.

{
    m_height = _height;
    m_width = _width;

    glGenTextures(1, &id);
    glBindTexture(GL_TEXTURE_2D, id);

    // Set the texture's stretching properties
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
    glGenerateMipmap(GL_TEXTURE_2D);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,  m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
}

Here is the caller graph for this function:

void Texture::generateEmptyf ( int  _width,
int  _height 
)

generate empty RGAB (32bit float)

Definition at line 26 of file Texture.cpp.

References m_height, and m_width.

{
    m_height = _height;
    m_width = _width;

    glGenTextures(1, &id);
    glBindTexture(GL_TEXTURE_2D, id);

    // Set the texture's stretching properties
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, m_width, m_height, 0, GL_RGBA, GL_FLOAT, 0);

    glBindTexture(GL_TEXTURE_2D, 0);
}

Here is the caller graph for this function:

void Texture::generateFromFile ( char *  _filePath)

generate texture from filepath

Definition at line 65 of file Texture.cpp.

{
    QImage *image = new QImage();
    bool loaded=image->load(_filePath);
    if(loaded == true)
    {
        int width=image->width();
        int height=image->height();
        unsigned char *data = new unsigned char[width*height*3];
        unsigned int index=0;
        QRgb colour;
        for( int y=0; y<height; ++y)
        {
            for( int x=0; x<width; ++x)
            {
                colour=image->pixel(x,y);

                data[index++]=qRed(colour);
                data[index++]=qGreen(colour);
                data[index++]=qBlue(colour);
            }
        }

        glGenTextures(1,&id);
        glBindTexture(GL_TEXTURE_2D,id);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);

        glTexImage2D(GL_TEXTURE_2D,0,3,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,data);
        glGenerateMipmap(GL_TEXTURE_2D);
    }
}
std::string Texture::getName ( ) [inline]

get the texture by name

Definition at line 43 of file Texture.h.

References m_name.

{return m_name;}

Here is the caller graph for this function:


Member Data Documentation

GLuint Texture::id

handle for this texture

Definition at line 18 of file Texture.h.

int Texture::m_height [private]

Definition at line 47 of file Texture.h.

std::string Texture::m_name [private]

the texture name

Definition at line 49 of file Texture.h.

int Texture::m_width [private]

texture dimensions

Definition at line 47 of file Texture.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines