diff options
| author | unknown <nfm@.(none)> | 2011-07-12 22:45:49 -0500 | 
|---|---|---|
| committer | unknown <nfm@.(none)> | 2011-07-12 22:45:49 -0500 | 
| commit | 6ad248c86e45933f9c61a7ce9f0546429d41c97e (patch) | |
| tree | 4f6b3e640ca5e3fb97cd8929749b57f1636855a3 /sdl/gltools.c | |
| parent | 4150b0db22bbf191eb27a90d6abd589cf4e64aa6 (diff) | |
| download | GLPyramid-6ad248c86e45933f9c61a7ce9f0546429d41c97e.tar.gz GLPyramid-6ad248c86e45933f9c61a7ce9f0546429d41c97e.tar.bz2 GLPyramid-6ad248c86e45933f9c61a7ce9f0546429d41c97e.zip  | |
add loading texture functions and tweak sdl init
Diffstat (limited to 'sdl/gltools.c')
| -rw-r--r-- | sdl/gltools.c | 38 | 
1 files changed, 37 insertions, 1 deletions
diff --git a/sdl/gltools.c b/sdl/gltools.c index afb0777..2449cfc 100644 --- a/sdl/gltools.c +++ b/sdl/gltools.c @@ -11,6 +11,42 @@  #include <string.h>  #include "gltools.h" +/* mipmapping enabled by default */ +GLuint gltLoadTGATexture(const char *fname) +{ +    GLuint handle; + +    /* variables used for texture loading */ +    GLbyte *pBytes; +    GLint iWidth, iHeight, iComponents; +    GLenum eFormat; + +    glGenTextures(1, &handle); +    glBindTexture(GL_TEXTURE_2D, handle); + +    /* load texture */ +    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); +    glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + +    pBytes = gltLoadTGA(fname, &iWidth, &iHeight, &iComponents, &eFormat); +    if (!pBytes) +        fprintf(stderr, "gltLoadTGA: failed to load texture!\n"); + +    glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, +                 GL_UNSIGNED_BYTE, pBytes); +    free(pBytes); + +    /* seems like mipmapping only applies to MIN_FILTER since mipmapping divides +     * current texture into smaller and smaller pieces +     */ +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); /* GL_LINEAR to disable mipmapping */ +    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); + +    return handle; +} +  void gltListExtensions(void)  {      const GLubyte *ext_str; @@ -145,7 +181,7 @@ GLint gltWriteTGA(const char *szFileName)      return 1;  } -GLbyte *gltLoadTGA(const char *szFileName, GLint *iWidth, GLint *iHeight,  +GLbyte *gltLoadTGA(const char *szFileName, GLint *iWidth, GLint *iHeight,                     GLint *iComponents, GLenum *eFormat)  {      FILE *pFile;              /* file pointer */  | 
