#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
int spamVideoMemory(int texSize)
{
const unsigned int memoryPerTexture = texSize * texSize;
void const *textureContents = malloc(memoryPerTexture);
unsigned int totalMemoryAllocated = 0;
for(;;)
{
GLuint textureId;
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexImage2D(GL_TEXTURE_2D, 0, 1, texSize, texSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, textureContents);
switch (glGetError())
{
case GL_NO_ERROR:
{
totalMemoryAllocated += memoryPerTexture;
const int megs = totalMemoryAllocated / (1024 * 1024);
printf("\rWoot, I've just allocated %d megabytes of texture data!", megs);
break;
}
case GL_OUT_OF_MEMORY:
printf("\nAppearently, that's the limit.\n");
return 0;
default:
printf("\nWTF?\n");
return 1;
}
}
}
int main( int argc, char *argv[] )
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutCreateWindow("Won't be visible anyway.");
int texSize = 1024;
if (argc >= 2)
texSize = atoi(argv[1]);
return spamVideoMemory(texSize);
}