2 * Try to see other parts of the user's video memory by creating textures
3 * with uninitialized contents. Display those textures in the window.
4 * Insprired by stories of WebGL security issues.
6 * The OpenGL driver should probably initialize all memory allocations
7 * to zero (textures, renderbuffers, buffer objects, etc).
13 #define GL_GLEXT_PROTOTYPES
19 #include "glut_wrap.h"
22 static int WinWidth
= 1024, WinHeight
= 512;
23 static GLboolean Anim
= GL_FALSE
;
25 static GLuint
*Textures
;
26 static GLuint TexWidth
= 1024, TexHeight
= 512;
27 static GLuint NumTextures
= 50, CurTexture
;
33 static int prevTime
= 0;
34 int curTime
= glutGet(GLUT_ELAPSED_TIME
);
40 if (curTime
- prevTime
> 250) {
42 CurTexture
= (CurTexture
+ 1) % NumTextures
;
54 Textures
= (GLuint
*) malloc(NumTextures
* sizeof(GLuint
));
56 glGenTextures(NumTextures
, Textures
);
57 for (i
= 0; i
< NumTextures
; i
++) {
58 glBindTexture(GL_TEXTURE_2D
, Textures
[i
]);
59 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
60 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
61 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, TexWidth
, TexHeight
, 0,
62 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
68 PrintString(const char *s
)
71 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
82 sprintf(s
, "Texture %u", CurTexture
);
84 glClear(GL_COLOR_BUFFER_BIT
);
86 glEnable(GL_TEXTURE_2D
);
87 glBindTexture(GL_TEXTURE_2D
, CurTexture
);
90 glTexCoord2f(0, 0); glVertex2f(0, 0);
91 glTexCoord2f(1, 0); glVertex2f(WinWidth
, 0);
92 glTexCoord2f(1, 1); glVertex2f(WinWidth
, WinHeight
);
93 glTexCoord2f(0, 1); glVertex2f(0, WinHeight
);
96 glDisable(GL_TEXTURE_2D
);
98 glWindowPos2iARB(10, 10);
106 Reshape(int width
, int height
)
110 glViewport(0, 0, width
, height
);
111 glMatrixMode(GL_PROJECTION
);
113 glOrtho(0, WinWidth
, 0, WinHeight
, -1, 1);
114 glMatrixMode(GL_MODELVIEW
);
120 Key(unsigned char key
, int x
, int y
)
132 glutDestroyWindow(Win
);
141 SpecialKey(int key
, int x
, int y
)
151 if (CurTexture
+ 1 < NumTextures
)
162 printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER
));
163 if (glutExtensionSupported("GL_ARB_robustness"))
164 printf("GL_ARB_robustness supported\n");
166 printf("GL_ARB_robustness not supported\n");
169 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
172 printf(" a: toggle animation\n");
173 printf(" Left/Right: back / next frame\n");
174 printf(" Esc: exit\n");
179 main(int argc
, char *argv
[])
181 glutInit(&argc
, argv
);
184 NumTextures
= atoi(argv
[1]);
185 if (NumTextures
< 1) {
186 printf("Invalid argument (number of textures)\n");
190 printf("Creating %u textures\n", NumTextures
);
192 glutInitWindowSize(WinWidth
, WinHeight
);
193 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
194 Win
= glutCreateWindow(argv
[0]);
196 glutReshapeFunc(Reshape
);
197 glutKeyboardFunc(Key
);
198 glutSpecialFunc(SpecialKey
);
199 glutDisplayFunc(Draw
);