aaara si, makes, cmakes i gitignores com toca
This commit is contained in:
83
source/demo1_pixels_wave.cpp
Normal file
83
source/demo1_pixels_wave.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <SDL3/SDL.h>
|
||||
#include <cmath>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
|
||||
|
||||
constexpr int WIDTH = 160;
|
||||
constexpr int HEIGHT = 160;
|
||||
constexpr int SIZE = WIDTH * HEIGHT;
|
||||
constexpr int ZOOM = 4;
|
||||
|
||||
SDL_Window *window = SDL_CreateWindow("pixels", 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);
|
||||
|
||||
Uint32 *pixels;
|
||||
int pitch;
|
||||
int rad = 96;
|
||||
int dx = (WIDTH - (rad * 2)) / 2;
|
||||
int dy = (HEIGHT - (rad * 2)) / 2;
|
||||
|
||||
Uint8 surface[SIZE];
|
||||
Uint32 paleta[2];
|
||||
|
||||
paleta[0] = 0xFF000000;
|
||||
paleta[1] = 0xFFFFFFFF;
|
||||
|
||||
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);
|
||||
|
||||
// Limpia la surface
|
||||
for (int i = 0; i < SIZE; ++i)
|
||||
{
|
||||
surface[i] = 0;
|
||||
}
|
||||
|
||||
// Dibuja el efecto
|
||||
float time = SDL_GetTicks() / 1000.0f;
|
||||
for (int j = -rad; j <= rad; j += 3)
|
||||
for (int i = -rad; i <= rad; i += 2)
|
||||
{
|
||||
float dist = sqrt(i * i + j * j);
|
||||
float z = cos((dist / 40 - time) * M_PI * 2) * 6;
|
||||
const int X = rad + i + dx;
|
||||
const int Y = rad + j - z + dy;
|
||||
if (X < WIDTH && Y < HEIGHT && X >= 0 && Y >= 0)
|
||||
surface[X + Y * WIDTH] = 1;
|
||||
}
|
||||
|
||||
// Vuelca la surface a la textura
|
||||
for (int i = 0; i < SIZE; ++i)
|
||||
{
|
||||
pixels[i] = paleta[surface[i]];
|
||||
}
|
||||
|
||||
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