1
0

Primer commit

This commit is contained in:
2024-02-05 13:51:34 +01:00
commit f6210b79c7
3 changed files with 59 additions and 0 deletions

49
paleta.cpp Normal file
View File

@@ -0,0 +1,49 @@
#include <SDL2/SDL.h>
struct ARGB
{
Uint8 b, g, r, a;
};
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window *w = SDL_CreateWindow("pixels", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
SDL_Renderer *r = SDL_CreateRenderer(w, -1, 0);
SDL_RenderSetLogicalSize(r, 320, 240);
SDL_Texture *t = SDL_CreateTexture(r, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 240);
ARGB *pixels;
int pitch;
SDL_Event sdlEvent;
bool exit = false;
while (!exit)
{
while (SDL_PollEvent(&sdlEvent))
{
if (sdlEvent.type == SDL_QUIT)
{
exit = true;
break;
}
}
SDL_LockTexture(t, nullptr, (void **)&pixels, &pitch);
for (int i = 0; i < 76800; ++i)
{
pixels[i].b = rand() % 256;
pixels[i].g = rand() % 256;
pixels[i].r = rand() % 256;
pixels[i].a = 255;
}
SDL_UnlockTexture(t);
SDL_RenderCopy(r, t, nullptr, nullptr);
SDL_RenderPresent(r);
}
}