summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver McFadden <z3ro.geek@gmail.com>2007-09-23 23:07:59 +0000
committerOliver McFadden <z3ro.geek@gmail.com>2007-09-23 23:07:59 +0000
commit083f602435531169a9b1179aa6a74e32b9c26900 (patch)
tree9ddd59159cde64cd6a5f4dfa73810d4f1e9de490
parentc2ba9a3205a8519e503a3b02fb8480eb370a2ab7 (diff)
Added a simple default texture test.
-rw-r--r--src/Makefile.am2
-rw-r--r--src/Makefile.in7
-rw-r--r--src/gl_texture.c88
-rw-r--r--src/gl_texture.h28
-rw-r--r--src/test.c15
-rw-r--r--src/test.h1
6 files changed, 139 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 3a6bec5..93a0bd2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -45,6 +45,8 @@ revenge_SOURCES = \
gl_scissor_test.h \
gl_shade_model.c \
gl_shade_model.h \
+ gl_texture.c \
+ gl_texture.h \
main.c \
main.h \
memory.c \
diff --git a/src/Makefile.in b/src/Makefile.in
index 90b628c..632d54f 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -53,8 +53,8 @@ am_revenge_OBJECTS = detect.$(OBJEXT) dump.$(OBJEXT) \
gl_null.$(OBJEXT) gl_point_size.$(OBJEXT) \
gl_primitives.$(OBJEXT) gl_render_mode.$(OBJEXT) \
gl_scissor_test.$(OBJEXT) gl_shade_model.$(OBJEXT) \
- main.$(OBJEXT) memory.$(OBJEXT) register.$(OBJEXT) \
- test.$(OBJEXT)
+ gl_texture.$(OBJEXT) main.$(OBJEXT) memory.$(OBJEXT) \
+ register.$(OBJEXT) test.$(OBJEXT)
revenge_OBJECTS = $(am_revenge_OBJECTS)
revenge_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I. -I$(top_builddir)@am__isrc@
@@ -197,6 +197,8 @@ revenge_SOURCES = \
gl_scissor_test.h \
gl_shade_model.c \
gl_shade_model.h \
+ gl_texture.c \
+ gl_texture.h \
main.c \
main.h \
memory.c \
@@ -293,6 +295,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gl_render_mode.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gl_scissor_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gl_shade_model.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gl_texture.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memory.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/register.Po@am__quote@
diff --git a/src/gl_texture.c b/src/gl_texture.c
new file mode 100644
index 0000000..62a4f3d
--- /dev/null
+++ b/src/gl_texture.c
@@ -0,0 +1,88 @@
+/*
+ * $Id$
+ * Copyright (C) 2007 Oliver McFadden <z3ro.geek@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <GL/gl.h>
+#include <GL/glext.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <test.h>
+
+#define TEXTURE_WIDTH 16
+#define TEXTURE_HEIGHT 16
+
+GLuint *
+random_texture (int width, int height)
+{
+ GLuint *texture = NULL;
+ int i;
+
+ if (!(texture = (GLuint *) malloc (width * height * sizeof (GLuint))))
+ {
+ fprintf (stderr, "%s: %s\n", program_invocation_short_name,
+ strerror (errno));
+ return NULL;
+ }
+
+ for (i = 0; i < width * height; i++)
+ {
+ texture[i] = random ();
+ }
+
+ return texture;
+}
+
+void
+gl_texture (void)
+{
+ GLuint *texture = NULL;;
+ GLuint texName;
+
+ if (!(texture = random_texture (TEXTURE_WIDTH, TEXTURE_HEIGHT)))
+ {
+ return;
+ }
+
+ test_prologue (NULL);
+
+ glEnable (GL_TEXTURE_2D);
+
+ glGenTextures (1, &texName);
+ glBindTexture (GL_TEXTURE_2D, texName);
+
+ glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ /* GL_NEAREST_MIPMAP_LINEAR */ GL_NEAREST);
+ glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+ glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, texture);
+
+ tex_tri ();
+
+ glDisable (GL_TEXTURE_2D);
+
+ test_epilogue (false);
+
+ free (texture);
+}
diff --git a/src/gl_texture.h b/src/gl_texture.h
new file mode 100644
index 0000000..5936376
--- /dev/null
+++ b/src/gl_texture.h
@@ -0,0 +1,28 @@
+/*
+ * $Id$
+ * Copyright (C) 2007 Oliver McFadden <z3ro.geek@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __GL_TEXTURE_H__
+#define __GL_TEXTURE_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void gl_texture (void);
+
+#endif
diff --git a/src/test.c b/src/test.c
index bcf73ad..40c3a37 100644
--- a/src/test.c
+++ b/src/test.c
@@ -52,6 +52,7 @@
#include <gl_render_mode.h>
#include <gl_scissor_test.h>
#include <gl_shade_model.h>
+#include <gl_texture.h>
void
tri (void)
@@ -63,6 +64,19 @@ tri (void)
glEnd ();
}
+void
+tex_tri (void)
+{
+ glBegin (GL_TRIANGLES);
+ glTexCoord2f (1.0, 0.0);
+ glVertex3f (1.0, 0.0, 0.0);
+ glTexCoord2f (0.0, 1.0);
+ glVertex3f (0.0, 1.0, 0.0);
+ glTexCoord2f (0.0, 0.0);
+ glVertex3f (0.0, 0.0, 1.0);
+ glEnd ();
+}
+
static void
test_quiescent (void)
{
@@ -146,6 +160,7 @@ static struct test_t tests[] = {
{_(gl_render_mode_select)},
{_(gl_scissor_test)},
{_(gl_shade_model)},
+ {_(gl_texture)},
};
#undef _
diff --git a/src/test.h b/src/test.h
index a0ef936..cc8da2d 100644
--- a/src/test.h
+++ b/src/test.h
@@ -31,6 +31,7 @@ struct test_t
};
void tri (void);
+void tex_tri (void);
void test_prologue (char *buf);
void test_epilogue (bool buf);
void test (void);