]> Pileus Git - grits/commitdiff
Adding OpenGL info query example
authorAndy Spencer <andy753421@gmail.com>
Sun, 2 May 2010 06:24:09 +0000 (06:24 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 2 May 2010 06:24:09 +0000 (06:24 +0000)
examples/info/.gitignore [new file with mode: 0644]
examples/info/info.c [new file with mode: 0644]
examples/info/mkfile [new file with mode: 0644]

diff --git a/examples/info/.gitignore b/examples/info/.gitignore
new file mode 100644 (file)
index 0000000..c226b5c
--- /dev/null
@@ -0,0 +1,2 @@
+info
+info.exe
diff --git a/examples/info/info.c b/examples/info/info.c
new file mode 100644 (file)
index 0000000..cd4fe71
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2009-2010 Andy Spencer <andy753421@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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include <GL/glut.h>
+
+#define COUNT(arr) (sizeof(arr)/sizeof(arr[0]))
+
+int main(int argc, char **argv)
+{
+       glutInit(&argc, argv);
+       glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
+       glutInitWindowSize(250,250);
+       glutInitWindowPosition(100,100);
+       glutCreateWindow("Hello World!");
+
+
+       /* Query max size */
+       GLint size;
+       glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size);
+       printf("\nGL_MAX_TEXTURE_SIZE = %d\n", size);
+
+
+       /* Test extensions */
+       const char *exts[] = {
+               "GL_ARB_texture_rectangle",
+               "GL_ARB_does_not_exist",
+       };
+       printf("\nChecking some extensions...\n");
+       const char *avail  = (char*)glGetString(GL_EXTENSIONS);
+       for (int i = 0; i < COUNT(exts); i++)
+               printf("\t%s: %s\n", exts[i],
+                       strstr(avail,exts[i]) ? "OK" : "Error");
+
+
+       /* Test sample image */
+       GLint sizes[][2] = {
+               {3400, 1600},
+               {1024, 1024},
+               {4096, 4096},
+               {8192, 8192},
+       };
+       printf("\nTrying some sizes...\n");
+       for (int i = 0; i < COUNT(sizes); i++) {
+               GLint width  = sizes[i][0];
+               GLint height = sizes[i][1];
+               printf("\t%dx%d: ", width, height);
+               glTexImage2D(GL_PROXY_TEXTURE_2D, 0, 4, width, height, 0,
+                               GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+               glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH,  &width);
+               glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
+               printf("%s\n", width && height ? "OK" : "Error");
+       }
+
+
+       /* Wait */
+       printf("\nPress any key to exit..\n");
+       getchar();
+}
diff --git a/examples/info/mkfile b/examples/info/mkfile
new file mode 100644 (file)
index 0000000..ced3f35
--- /dev/null
@@ -0,0 +1,14 @@
+MKSHELL=/usr/lib/plan9/bin/rc
+PROGS=info info.exe
+default:V: all info-run
+
+info_libs=-lGL -lGLU -lglut
+
+info.exe: info.c
+       i686-pc-mingw32-gcc -o $target $prereq \
+               $CFLAGS -DFREEGLUT_STATIC -static \
+               -lfreeglut_static -lopengl32 -lwinmm -lgdi32
+info.exe-run: info.exe
+       wine $prereq
+
+<$HOME/lib/mkcommon