Guest User

Texture.cpp

a guest
Jun 7th, 2014
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. /*
  2.  
  3. Copyright 2011 Etay Meiri
  4.  
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. #include <iostream>
  20. #include "OpenGLincludes.h"
  21. #include "Texture.h"
  22. #include "Utils.h"
  23.  
  24. #include "stb_image.h"
  25.  
  26.  
  27.  
  28. Texture::Texture(GLenum TextureTarget, const std::string& FileName)
  29. {
  30.     m_textureTarget = TextureTarget;
  31.     m_fileName = FileName;
  32.     image_data = NULL;
  33. }
  34.  
  35. bool Texture::Load()
  36. {
  37.  
  38.     image_data = stbi_load(m_fileName.c_str(), &image_width, &image_height, &image_pixel_components, 0);
  39.  
  40.     if (image_data == NULL){
  41.         std::cout << "Error loading texture '" << m_fileName << std::endl;
  42.         return false;
  43.     }
  44.  
  45.     glGenTextures(1, &m_textureObj);
  46.     glBindTexture(m_textureTarget, m_textureObj);
  47.     glTexImage2D(m_textureTarget, 0, GL_RGB, image_width, image_height, 0, GL_RGB, GL_UNSIGNED_BYTE, image_data);
  48.     glTexParameterf(m_textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  49.     glTexParameterf(m_textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  50.  
  51.     //stbi_image_free(image_data);
  52.     return true;
  53. }
  54.  
  55. void Texture::Bind(GLenum TextureUnit)
  56. {
  57.     glActiveTexture(TextureUnit);
  58.     glBindTexture(m_textureTarget, m_textureObj);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment