mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-11-02 20:51:23 -07:00
Merged branch 'dev_native' into lm_sla_supports_auto
Added igl library files
This commit is contained in:
commit
7681d00ee5
2865 changed files with 142806 additions and 22325 deletions
68
src/igl/copyleft/opengl2/texture_from_tga.cpp
Normal file
68
src/igl/copyleft/opengl2/texture_from_tga.cpp
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
// This file is part of libigl, a simple c++ geometry processing library.
|
||||
//
|
||||
// Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License
|
||||
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
// obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#include "texture_from_tga.h"
|
||||
#include "tga.h"
|
||||
#include <cstring>
|
||||
|
||||
IGL_INLINE bool igl::opengl::texture_from_tga(const std::string tga_file, GLuint & id)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
// read pixels to tga file
|
||||
FILE * imgFile;
|
||||
// "-" as input file name is code for read from stdin
|
||||
imgFile = fopen(tga_file.c_str(),"r");
|
||||
if(NULL==imgFile)
|
||||
{
|
||||
printf("IOError: %s could not be opened...",tga_file.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// gliReadTGA annoyingly uses char * instead of const char *
|
||||
size_t len = tga_file.length();
|
||||
char* tga_file_char = new char [ len + 1 ];
|
||||
strcpy( tga_file_char, tga_file.c_str() );
|
||||
// read image
|
||||
gliGenericImage* img = gliReadTGA(imgFile, tga_file_char, 0, 0);
|
||||
// clean up filename buffer
|
||||
delete[] tga_file_char;
|
||||
fclose( imgFile );
|
||||
|
||||
// set up texture mapping parameters and generate texture id
|
||||
glGenTextures(1,&id);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
// Texture parameters
|
||||
float empty[] = {1.0f,1.0f,1.0f,0.0f};
|
||||
glTexParameterfv(GL_TEXTURE_2D,GL_TEXTURE_BORDER_COLOR,empty);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
// GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
GL_LINEAR);
|
||||
|
||||
// OpenGL by default tries to read data in multiples of 4, if our data is
|
||||
// only RGB or BGR and the width is not divible by 4 then we need to alert
|
||||
// opengl
|
||||
if((img->width % 4) != 0 &&
|
||||
(img->format == GL_RGB ||
|
||||
img->format == GL_BGR))
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
}
|
||||
|
||||
// Load texture
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->width,
|
||||
img->height, 0, img->format, GL_UNSIGNED_BYTE,
|
||||
img->pixels);
|
||||
return id;
|
||||
}
|
||||
|
||||
#ifdef IGL_STATIC_LIBRARY
|
||||
// Explicit template instantiation
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue