cl_dll/mainmenu.cpp
// Simple helper function to load an image into a OpenGL texture with common settings
Simple helper function to load an image into a OpenGL texture with common settings
Simple helper function to load an image into a OpenGL texture with common settings
bool LoadTextureFromFile(const char* filename, GLuint* out_texture, int* out_width, int* out_height)
{
	int image_width = 0;
	int image_height = 0;
	int frame = 0;
	unsigned char* image_data = stbi_xload_file(filename, &image_width, &image_height, &frame, nullptr);
	if (image_data == NULL)
		return false;
	GLuint image_texture;
	glGenTextures(1, &image_texture);
	glBindTexture(GL_TEXTURE_2D, image_texture);
	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_CLAMP_TO_EDGE); 
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
#if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__)
	glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
#endif
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_width, image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
	stbi_image_free(image_data);
	*out_texture = image_texture;
	*out_width = image_width;
	*out_height = image_height;
	return true;
}
bool LoadTextureFromFile ( const char * filename , GLuint * out_texture , int * out_width , int * out_height ) { int image_width = 0 ; int image_height = 0 ; int frame = 0 ; unsigned char * image_data = stbi_xload_file ( filename , & image_width , & image_height , & frame , nullptr ) ; if ( image_data == NULL ) return false ; GLuint image_texture ; glGenTextures ( 1 , & image_texture ) ; glBindTexture ( GL_TEXTURE_2D , image_texture ) ; 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_CLAMP_TO_EDGE ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ) ; #if defined ( GL_UNPACK_ROW_LENGTH ) && ! defined ( __EMSCRIPTEN__ ) glPixelStorei ( GL_UNPACK_ROW_LENGTH , 0 ) ; #endif glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , image_width , image_height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , image_data ) ; stbi_image_free ( image_data ) ; * out_texture = image_texture ; * out_width = image_width ; * out_height = image_height ; return true ; }
Simple helper function to load an image into a OpenGL texture with common settings
Simple helper function to load an image into a OpenGL texture with common settings
// Load from file // Create a OpenGL texture identifier // Setup filtering parameters for display // This is required on WebGL for non power-of-two textures // Same // Upload pixels into texture