Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

texture2d.cpp

Go to the documentation of this file.
00001 #include "texture2d.h"
00002 #include "../openglserver/openglserver.h"
00003 #include "../imageserver/image.h"
00004 
00005 using namespace kerosin;
00006 
00007 Texture2D::Texture2D(const boost::shared_ptr<TextureServer> &textureServer) : Texture(textureServer)
00008 {
00009 }
00010 
00011 Texture2D::~Texture2D()
00012 {
00013 }
00014 
00015 void Texture2D::Bind() const
00016 {
00017         if (mTexID != 0)
00018         {
00019                 glBindTexture(GL_TEXTURE_2D, mTexID);
00020         }
00021 }
00022 
00023 void Texture2D::Enable() const
00024 {
00025         glEnable(GL_TEXTURE_2D);
00026 }
00027 
00028 void Texture2D::Disable() const
00029 {
00030         glDisable(GL_TEXTURE_2D);
00031 }
00032 
00033 void Texture2D::Create(boost::shared_ptr<Image> &image)
00034 {
00035         mWidth          = image->Width();
00036         mHeight         = image->Height();
00037 
00038         Acquire();
00039         Bind();
00040 
00041         glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE );
00042         if(image->HasAlpha())
00043                 glTexImage2D(GL_TEXTURE_2D, 0,  GL_RGBA8, mWidth, mHeight, 0, image->Format(), image->Type(), image->Data());
00044         else
00045                 glTexImage2D(GL_TEXTURE_2D, 0,  GL_RGB8, mWidth, mHeight, 0, image->Format(), image->Type(), image->Data());
00046 
00047         glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00048         glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
00049 }
00050 
00051 void Texture2D::Clamp() const
00052 {
00053         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00054         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00055 }
00056 
00057 void Texture2D::ClampToEdge() const
00058 {
00059         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
00060         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
00061 }
00062 
00063 void Texture2D::Repeat() const
00064 {
00065         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
00066         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
00067 }

Generated on Thu Apr 6 15:25:40 2006 for rcssserver3d by  doxygen 1.4.4