DeferredRenderer 1.0

Texture.cpp

Go to the documentation of this file.
00001 #include "Texture.h"
00002 #include "QImage"
00003 
00004 Texture::Texture(const std::string &_name):id(0),m_width(0),m_height(0),m_name(_name){}
00005 Texture::~Texture(){}
00006 
00007 void Texture::generateEmpty(int _width, int _height)
00008 {
00009     m_height = _height;
00010     m_width = _width;
00011 
00012     glGenTextures(1, &id);
00013     glBindTexture(GL_TEXTURE_2D, id);
00014 
00015     // Set the texture's stretching properties
00016     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00017     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00018 
00019     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
00020     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
00021     glGenerateMipmap(GL_TEXTURE_2D);
00022 
00023     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,  m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
00024 }
00025 
00026 void Texture::generateEmptyf(int _width, int _height)
00027 {
00028     m_height = _height;
00029     m_width = _width;
00030 
00031     glGenTextures(1, &id);
00032     glBindTexture(GL_TEXTURE_2D, id);
00033 
00034     // Set the texture's stretching properties
00035     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00036     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
00037 
00038     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
00039     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
00040 
00041     glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
00042     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, m_width, m_height, 0, GL_RGBA, GL_FLOAT, 0);
00043 
00044     glBindTexture(GL_TEXTURE_2D, 0);
00045 }
00046 
00047 void Texture::generateDepth(int _width, int _height)
00048 {
00049     m_height = _height;
00050     m_width = _width;
00051 
00052     glGenTextures(1, &id);
00053     glBindTexture(GL_TEXTURE_2D, id);
00054 
00055     // Set the texture's stretching properties
00056     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00057     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00058 
00059     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE  );
00060     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE  );
00061     glGenerateMipmap(GL_TEXTURE_2D);
00062     glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32,  m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
00063 }
00064 
00065 void Texture::generateFromFile(char* _filePath)
00066 {
00067     QImage *image = new QImage();
00068     bool loaded=image->load(_filePath);
00069     if(loaded == true)
00070     {
00071         int width=image->width();
00072         int height=image->height();
00073         unsigned char *data = new unsigned char[width*height*3];
00074         unsigned int index=0;
00075         QRgb colour;
00076         for( int y=0; y<height; ++y)
00077         {
00078             for( int x=0; x<width; ++x)
00079             {
00080                 colour=image->pixel(x,y);
00081 
00082                 data[index++]=qRed(colour);
00083                 data[index++]=qGreen(colour);
00084                 data[index++]=qBlue(colour);
00085             }
00086         }
00087 
00088         glGenTextures(1,&id);
00089         glBindTexture(GL_TEXTURE_2D,id);
00090 
00091         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00092         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
00093 
00094         glTexImage2D(GL_TEXTURE_2D,0,3,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,data);
00095         glGenerateMipmap(GL_TEXTURE_2D);
00096     }
00097 }
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines