-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfe7f93
commit 9b76cb6
Showing
6 changed files
with
79 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef TEXTURE_HPP | ||
#define TEXTURE_HPP | ||
|
||
#include "utils.hpp" | ||
#include <GL/glew.h> | ||
#include <IL/il.h> | ||
#include <IL/ilu.h> | ||
|
||
void loadTeture(const char* filepath, GLuint& textureInt); | ||
|
||
|
||
#endif // TEXTURE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "texture.hpp" | ||
|
||
void loadTexture(std::string filepath, GLuint& textureInt) { | ||
ILuint imageID; | ||
ilGenImages(1, &imageID); | ||
ilBindImage(imageID); | ||
ILboolean success = ilLoadImage(filepath.c_str()); | ||
if (success == IL_FALSE) { | ||
ILenum error = ilGetError(); | ||
std::cerr << "Error loading image: " << iluErrorString(error) << std::endl; | ||
ilDeleteImages(1, &imageID); | ||
return; | ||
} | ||
success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); | ||
if (success == IL_FALSE) { | ||
ILenum error = ilGetError(); | ||
std::cerr << "Error converting image: " << iluErrorString(error) << std::endl; | ||
ilDeleteImages(1, &imageID); | ||
return; | ||
} | ||
ILint width = ilGetInteger(IL_IMAGE_WIDTH); | ||
ILint height = ilGetInteger(IL_IMAGE_HEIGHT); | ||
ILint bpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL); | ||
ILubyte* data = ilGetData(); | ||
GLuint textureID; | ||
glGenTextures(1, &textureID); | ||
glBindTexture(GL_TEXTURE_2D, textureID); | ||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); | ||
glGenerateMipmap(GL_TEXTURE_2D); | ||
ilDeleteImages(1, &imageID); | ||
glBindTexture(GL_TEXTURE_2D, 0); | ||
textureInt = textureID; | ||
|
||
} |