00001
00002
00003 #include "Texture.h"
00004
00005 #include "Image.h"
00006
00007 #include <string.h>
00008
00009
00010 namespace pge {
00011
00012
00013
00014
00015
00016
00017
00018 Texture::Texture(Image *image, const std::string &name) {
00019 m_name = name;
00020 m_descriptor = 0;
00021 m_width = image->getWidth();
00022 m_height = image->getHeight();
00023 m_image = image;
00024 m_alphaBlending = false;
00025 }
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 Texture::~Texture(void) {
00050 glDeleteTextures(1, &m_descriptor);
00051 if(m_image != NULL) {
00052 delete m_image;
00053 }
00054 m_image = NULL;
00055 }
00056
00057
00058
00059
00060
00061
00062
00063 GLuint Texture::getDescriptor(void) {
00064 return m_descriptor;
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 std::string Texture::getName(void) {
00074 return m_name;
00075 }
00076
00077
00078
00079
00080
00081
00082
00083 void Texture::setName(const std::string &name) {
00084 m_name = name;
00085 }
00086
00087
00088
00089
00090
00091
00092
00093 void Texture::createTexture2D(bool mipmap, GLuint minFilter, GLuint magFilter, GLuint wrapS, GLuint wrapT) {
00094 glGenTextures(1, &m_descriptor);
00095 glBindTexture(GL_TEXTURE_2D, m_descriptor);
00096 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
00097 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
00098
00099 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
00100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
00101
00102 if(m_image->getType() == Image::RGBA) {
00103 if(!mipmap) {
00104 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_image->getImage());
00105 } else {
00106 gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, m_image->getImage());
00107 }
00108 } else if(m_image->getType() == Image::RGB) {
00109 if(!mipmap) {
00110 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_width, m_height, 0, GL_RGB, GL_UNSIGNED_BYTE, m_image->getImage());
00111 } else {
00112 gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, m_width, m_height, GL_RGB, GL_UNSIGNED_BYTE, m_image->getImage());
00113 }
00114 } else {
00115
00116 }
00117 }
00118
00119
00120
00121
00122
00123
00124
00125 void Texture::bind(void) {
00126 glBindTexture(GL_TEXTURE_2D, m_descriptor);
00127 }
00128 }