Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Copyright 2011 Etay Meiri
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include <iostream>
- #include "OpenGLincludes.h"
- #include "Texture.h"
- #include "Utils.h"
- #include "stb_image.h"
- Texture::Texture(GLenum TextureTarget, const std::string& FileName)
- {
- m_textureTarget = TextureTarget;
- m_fileName = FileName;
- image_data = NULL;
- }
- bool Texture::Load()
- {
- image_data = stbi_load(m_fileName.c_str(), &image_width, &image_height, &image_pixel_components, 0);
- if (image_data == NULL){
- std::cout << "Error loading texture '" << m_fileName << std::endl;
- return false;
- }
- glGenTextures(1, &m_textureObj);
- glBindTexture(m_textureTarget, m_textureObj);
- glTexImage2D(m_textureTarget, 0, GL_RGB, image_width, image_height, 0, GL_RGB, GL_UNSIGNED_BYTE, image_data);
- glTexParameterf(m_textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameterf(m_textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- //stbi_image_free(image_data);
- return true;
- }
- void Texture::Bind(GLenum TextureUnit)
- {
- glActiveTexture(TextureUnit);
- glBindTexture(m_textureTarget, m_textureObj);
- }
Advertisement
Add Comment
Please, Sign In to add comment