1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include "texture_from_tga.h"
- #include "tga.h"
- #include "report_gl_error.h"
- #include <cstring>
- IGL_INLINE bool igl::opengl::texture_from_tga(const std::string tga_file, GLuint & id)
- {
- using namespace std;
-
- FILE * imgFile;
-
- imgFile = fopen(tga_file.c_str(),"r");
- if(NULL==imgFile)
- {
- printf("IOError: %s could not be opened...",tga_file.c_str());
- return false;
- }
-
- size_t len = tga_file.length();
- char* tga_file_char = new char [ len + 1 ];
- strcpy( tga_file_char, tga_file.c_str() );
-
- gliGenericImage* img = gliReadTGA(imgFile, tga_file_char, 0, 0);
-
- delete[] tga_file_char;
- fclose( imgFile );
-
- glGenTextures(1,&id);
- glBindTexture(GL_TEXTURE_2D, id);
-
- 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_MIN_FILTER,
- GL_LINEAR);
-
-
-
- if((img->width % 4) != 0 &&
- (img->format == GL_RGB ||
- img->format == GL_BGR))
- {
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- igl::opengl::report_gl_error();
- }
-
- 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
- #endif
|