38 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
#include "load_texture.h"
 | 
						|
 | 
						|
#include <iostream>
 | 
						|
#include <FreeImage.h>
 | 
						|
 | 
						|
namespace Texture {
 | 
						|
    GLuint LoadTexture(const char* filePath) {
 | 
						|
        FIBITMAP* bitmap = FreeImage_Load(FIF_TIFF, filePath, TIFF_DEFAULT);
 | 
						|
 | 
						|
        if(!bitmap) {
 | 
						|
            std::cerr << "Failed to load TIFF image: " << filePath << std::endl;
 | 
						|
        }
 | 
						|
 | 
						|
        FIBITMAP* bitmap32 = FreeImage_ConvertTo32Bits(bitmap);
 | 
						|
        FreeImage_Unload(bitmap);
 | 
						|
 | 
						|
        int width = FreeImage_GetWidth(bitmap32);
 | 
						|
        int height = FreeImage_GetHeight(bitmap32);
 | 
						|
        BYTE* pixels = FreeImage_GetBits(bitmap32);
 | 
						|
 | 
						|
        GLuint textureID;
 | 
						|
        glGenTextures(1, &textureID);
 | 
						|
        glBindTexture(GL_TEXTURE_2D, textureID);
 | 
						|
 | 
						|
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
 | 
						|
 | 
						|
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 | 
						|
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 | 
						|
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 | 
						|
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 | 
						|
 | 
						|
        glBindTexture(GL_TEXTURE_2D, 0);
 | 
						|
 | 
						|
        FreeImage_Unload(bitmap32);
 | 
						|
 | 
						|
        return textureID;
 | 
						|
    }
 | 
						|
} |