From: Andy Spencer Date: Sun, 2 May 2010 06:24:09 +0000 (+0000) Subject: Adding OpenGL info query example X-Git-Tag: v0.4~12 X-Git-Url: http://pileus.org/git/?p=grits;a=commitdiff_plain;h=2da20b1f7feeb2b4ae280e10a445b5b55f3926bf;hp=08b979cf4e173ae461ce0e823ba08a732f4b7cbf Adding OpenGL info query example --- diff --git a/examples/info/.gitignore b/examples/info/.gitignore new file mode 100644 index 0000000..c226b5c --- /dev/null +++ b/examples/info/.gitignore @@ -0,0 +1,2 @@ +info +info.exe diff --git a/examples/info/info.c b/examples/info/info.c new file mode 100644 index 0000000..cd4fe71 --- /dev/null +++ b/examples/info/info.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2009-2010 Andy Spencer + * + * 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 . + */ + +#include +#include +#include +#include +#include + +#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 index 0000000..ced3f35 --- /dev/null +++ b/examples/info/mkfile @@ -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