summaryrefslogtreecommitdiffstats
path: root/sdl/gltools.c
diff options
context:
space:
mode:
Diffstat (limited to 'sdl/gltools.c')
-rw-r--r--sdl/gltools.c38
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 */