Advertisement
Guest User

My texture class

a guest
Feb 22nd, 2012
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. // Texture class
  2. class Texture {
  3. public:
  4.     GLuint handle;
  5.     Texture();
  6.     virtual ~Texture();
  7.  
  8.     void loadData (int w, int h, int chan, GLenum format, void* data);
  9.     void enable();
  10. };
  11.  
  12. Texture::Texture() {
  13.     handle = 0;
  14. }
  15.  
  16. void Texture::loadData(int w, int h, int chan, GLenum format, void* data)
  17. {
  18.     glGenTextures(1, &handle);
  19.     enable();
  20.  
  21.     // Bilinear filtering
  22.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
  23.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  24.  
  25.     // Clamp: texture ends at edges
  26.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  27.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  28.  
  29.     // Create the texture
  30.     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  31.     glTexImage2D(GL_TEXTURE_2D, 0, chan, w, h, 0, format, GL_UNSIGNED_BYTE, data);
  32.    
  33.  
  34.     //gluBuild2DMipmaps(GL_TEXTURE_2D, 3, w, h, format, GL_UNSIGNED_BYTE, data);
  35. }
  36.  
  37. void Texture::enable()
  38. {
  39.     glBindTexture(GL_TEXTURE_2D, handle);
  40. }
  41.  
  42. Texture::~Texture() {
  43.     if (handle != 0)
  44.         glDeleteTextures(1, &handle);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement