glVertex  5.5.2
glvertex_texformats.h
Go to the documentation of this file.
1 // (c) by Stefan Roettger, licensed under MIT license
2 
5 #ifndef GLVERTEX_TEXFORMATS_H
6 #define GLVERTEX_TEXFORMATS_H
7 
8 #include "glvertex_texture.h"
9 #include "glvertex_pnmformat.h"
10 #include "glvertex_rawformat.h"
11 
13 inline GLuint lglLoadTextureInto(std::string filename, int *twidth, int *theight, bool mipmapping = true)
14 {
15  GLuint texid = 0;
16 
17  unsigned char *img = NULL;
18  int tcomps = 0;
19 
20  img = lglReadPnmImage(filename, twidth, theight, &tcomps);
21  if (!img) img = lglLoadRawImage(filename, twidth, theight, &tcomps);
22 
23  if (img)
24  {
25  if (mipmapping)
26  {
27  if (tcomps == 1)
28  texid = lglCreateMipmap2D(twidth,theight, LGL_LUMINANCE,img);
29  else if (tcomps == 3)
30  texid = lglCreateMipmap2D(twidth,theight, LGL_RGB,img);
31  else if (tcomps == 4)
32  texid = lglCreateMipmap2D(twidth,theight, LGL_RGBA,img);
33  }
34  else
35  {
36  if (tcomps == 1)
37  texid = lglCreateTexmap2D(twidth,theight, LGL_LUMINANCE,img);
38  else if (tcomps == 3)
39  texid = lglCreateTexmap2D(twidth,theight, LGL_RGB,img);
40  else if (tcomps == 4)
41  texid = lglCreateTexmap2D(twidth,theight, LGL_RGBA,img);
42  }
43 
44  free(img);
45  }
46 
47  return(texid);
48 }
49 
51 inline GLuint lglLoadTexture(std::string filename, int *twidth, int *theight, bool mipmapping = true)
52 {
53  GLuint texid = lglLoadTextureInto(filename, twidth, theight, mipmapping);
54 
55  if (texid == 0) texid = lglLoadTextureInto((std::string("../") + filename).c_str(), twidth, theight, mipmapping);
56  if (texid == 0) texid = lglLoadTextureInto((std::string("data/") + filename).c_str(), twidth, theight, mipmapping);
57  if (texid == 0) texid = lglLoadTextureInto((std::string("../data/") + filename).c_str(), twidth, theight, mipmapping);
58  if (texid == 0) texid = lglLoadTextureInto((std::string("/usr/local/share/") + filename).c_str(), twidth, theight, mipmapping);
59 
60  return(texid);
61 }
62 
64 inline GLuint lglLoadTexture(std::string filename, bool mipmapping = true)
65 {
66  int twidth, theight;
67  return(lglLoadTexture(filename, &twidth, &theight, mipmapping));
68 }
69 
70 #endif
glvertex_rawformat.h
lglCreateTexmap2D
GLuint lglCreateTexmap2D(int *width, int *height, lgl_texmap_type type, unsigned char *data)
create a 2D texture map
Definition: glvertex_texture.h:299
glvertex_pnmformat.h
lglLoadTextureInto
GLuint lglLoadTextureInto(std::string filename, int *twidth, int *theight, bool mipmapping=true)
load image into texture object from file name
Definition: glvertex_texformats.h:13
glvertex_texture.h
lglCreateMipmap2D
GLuint lglCreateMipmap2D(int *width, int *height, lgl_texmap_type type, unsigned char *data)
create a 2D texture mip-map
Definition: glvertex_texture.h:386
lglLoadTexture
GLuint lglLoadTexture(std::string filename, int *twidth, int *theight, bool mipmapping=true)
load image into texture object from file name (and from default installation paths)
Definition: glvertex_texformats.h:51