Skip to content

Instantly share code, notes, and snippets.

@3dgoose
Created March 1, 2026 12:43
Show Gist options
  • Select an option

  • Save 3dgoose/2f6e719e51a4dfc818a2ddc829c9affb to your computer and use it in GitHub Desktop.

Select an option

Save 3dgoose/2f6e719e51a4dfc818a2ddc829c9affb to your computer and use it in GitHub Desktop.
GPU stress test
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_SPHERES 500
SDL_Window* window;
SDL_GLContext glCtx;
SDL_Event e;
typedef struct {
float x, y, z;
float angle;
float r, g, b;
} Sphere;
Sphere spheres[NUM_SPHERES];
GLuint textureID;
// Initialise sphères avec positions et couleurs aléatoires
void initSpheres() {
for (int i = 0; i < NUM_SPHERES; i++) {
spheres[i].x = (float)(rand() % 160 - 80);
spheres[i].y = (float)(rand() % 120 - 60);
spheres[i].z = (float)(rand() % 120 - 60);
spheres[i].angle = (float)(rand() % 360);
spheres[i].r = (float)(rand() % 100) / 100.0f;
spheres[i].g = (float)(rand() % 100) / 100.0f;
spheres[i].b = (float)(rand() % 100) / 100.0f;
}
}
// Chargement d’une texture simple avec SDL_image
GLuint loadTexture(const char* path) {
SDL_Surface* img = IMG_Load(path);
if (!img) {
printf("Failed to load texture: %s\n", path);
return 0;
}
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
GLenum format = (img->format->BytesPerPixel == 4) ? GL_RGBA : GL_RGB;
glTexImage2D(GL_TEXTURE_2D, 0, format, img->w, img->h, 0, format, GL_UNSIGNED_BYTE, img->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
SDL_FreeSurface(img);
return tex;
}
// Configure 4 lumières dynamiques
void setupLighting() {
GLfloat lightAmbient[] = {0.2f, 0.2f, 0.2f, 1.0f};
GLfloat lightDiffuse[] = {0.8f, 0.8f, 0.8f, 1.0f};
GLfloat lightSpecular[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat lightPositions[4][4] = {
{50, 50, 50, 1}, {-50, 50, 50, 1}, {50, -50, 50, 1}, {-50, -50, 50, 1}
};
glEnable(GL_LIGHTING);
for (int i = 0; i < 4; i++) {
glEnable(GL_LIGHT0 + i);
glLightfv(GL_LIGHT0 + i, GL_AMBIENT, lightAmbient);
glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, lightDiffuse);
glLightfv(GL_LIGHT0 + i, GL_SPECULAR, lightSpecular);
glLightfv(GL_LIGHT0 + i, GL_POSITION, lightPositions[i]);
}
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
}
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG);
window = SDL_CreateWindow("Ultimate GPU Torture Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL);
glCtx = SDL_GL_CreateContext(window);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, 1280.0/720.0, 0.1, 300.0);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.05f, 0.05f, 0.05f, 1.0f);
initSpheres();
setupLighting();
textureID = loadTexture("checker.jpg"); // any texture
glEnable(GL_TEXTURE_2D);
GLUquadric* quad = gluNewQuadric();
gluQuadricNormals(quad, GLU_SMOOTH);
gluQuadricTexture(quad, GL_TRUE);
int running = 1;
float globalAngle = 0.0f;
while(running) {
while(SDL_PollEvent(&e)) {
if(e.type == SDL_QUIT)
running = 0;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -150.0f);
glBindTexture(GL_TEXTURE_2D, textureID);
for (int i = 0; i < NUM_SPHERES; i++) {
glPushMatrix();
glTranslatef(spheres[i].x, spheres[i].y, spheres[i].z);
glRotatef(globalAngle + spheres[i].angle, 0.0f, 6.0f, 0.0f);
glColor3f(spheres[i].r, spheres[i].g, spheres[i].b);
gluSphere(quad, 5.0, 256, 256);
glPopMatrix();
}
globalAngle += 0.5f;
SDL_GL_SwapWindow(window);
}
gluDeleteQuadric(quad);
glDeleteTextures(1, &textureID);
SDL_GL_DeleteContext(glCtx);
SDL_DestroyWindow(window);
SDL_Quit();
IMG_Quit();
return 0;
}
@3dgoose
Copy link
Author

3dgoose commented Mar 1, 2026

checker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment