]> Pileus Git - grits/blob - examples/info/info.c
Adding OpenGL info query example
[grits] / examples / info / info.c
1 /*
2  * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <GL/gl.h>
21 #include <GL/glu.h>
22 #include <GL/glut.h>
23
24 #define COUNT(arr) (sizeof(arr)/sizeof(arr[0]))
25
26 int main(int argc, char **argv)
27 {
28         glutInit(&argc, argv);
29         glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
30         glutInitWindowSize(250,250);
31         glutInitWindowPosition(100,100);
32         glutCreateWindow("Hello World!");
33
34
35         /* Query max size */
36         GLint size;
37         glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size);
38         printf("\nGL_MAX_TEXTURE_SIZE = %d\n", size);
39
40
41         /* Test extensions */
42         const char *exts[] = {
43                 "GL_ARB_texture_rectangle",
44                 "GL_ARB_does_not_exist",
45         };
46         printf("\nChecking some extensions...\n");
47         const char *avail  = (char*)glGetString(GL_EXTENSIONS);
48         for (int i = 0; i < COUNT(exts); i++)
49                 printf("\t%s: %s\n", exts[i],
50                         strstr(avail,exts[i]) ? "OK" : "Error");
51
52
53         /* Test sample image */
54         GLint sizes[][2] = {
55                 {3400, 1600},
56                 {1024, 1024},
57                 {4096, 4096},
58                 {8192, 8192},
59         };
60         printf("\nTrying some sizes...\n");
61         for (int i = 0; i < COUNT(sizes); i++) {
62                 GLint width  = sizes[i][0];
63                 GLint height = sizes[i][1];
64                 printf("\t%dx%d: ", width, height);
65                 glTexImage2D(GL_PROXY_TEXTURE_2D, 0, 4, width, height, 0,
66                                 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
67                 glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH,  &width);
68                 glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
69                 printf("%s\n", width && height ? "OK" : "Error");
70         }
71
72
73         /* Wait */
74         printf("\nPress any key to exit..\n");
75         getchar();
76 }