aaara si, makes, cmakes i gitignores com toca
This commit is contained in:
64
source/demo2_pixels_noise.cpp
Normal file
64
source/demo2_pixels_noise.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
struct ARGB
|
||||
{
|
||||
Uint8 b, g, r, a;
|
||||
|
||||
// Constructor
|
||||
ARGB(Uint8 blue = 0, Uint8 green = 0, Uint8 red = 0, Uint8 alpha = 255)
|
||||
: b(blue), g(green), r(red), a(alpha) {}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
constexpr int WIDTH = 320;
|
||||
constexpr int HEIGHT = 240;
|
||||
constexpr int ZOOM = 2;
|
||||
|
||||
srand(static_cast<unsigned>(time(nullptr)));
|
||||
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
|
||||
|
||||
SDL_Window *window = SDL_CreateWindow("pixels_white_noise", WIDTH * ZOOM, HEIGHT * ZOOM, SDL_WINDOW_OPENGL);
|
||||
SDL_Renderer *renderer = SDL_CreateRenderer(window, nullptr);
|
||||
SDL_SetRenderLogicalPresentation(renderer, WIDTH, HEIGHT, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
|
||||
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, WIDTH, HEIGHT);
|
||||
|
||||
ARGB *pixels;
|
||||
int pitch;
|
||||
|
||||
SDL_Event sdlEvent;
|
||||
bool exit = false;
|
||||
while (!exit)
|
||||
{
|
||||
while (SDL_PollEvent(&sdlEvent))
|
||||
{
|
||||
if (sdlEvent.type == SDL_EVENT_QUIT)
|
||||
{
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_LockTexture(texture, nullptr, (void **)&pixels, &pitch);
|
||||
|
||||
for (int i = 0; i < 76800; ++i)
|
||||
{
|
||||
pixels[i] = ARGB(rand() % 256, rand() % 256, rand() % 256, 255);
|
||||
}
|
||||
|
||||
SDL_UnlockTexture(texture);
|
||||
SDL_RenderTexture(renderer, texture, nullptr, nullptr);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user