arreglat no se que merdes del pitch

This commit is contained in:
2025-03-24 17:32:31 +01:00
parent 152554c39b
commit 8379c09e9c
2 changed files with 17 additions and 7 deletions

View File

@@ -9,8 +9,6 @@ OUTPUT_EXT :=
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
LDFLAGS += -lmingw32 -lws2_32 LDFLAGS += -lmingw32 -lws2_32
OUTPUT_EXT := .exe OUTPUT_EXT := .exe
else
OUTPUT_EXT := .out
endif endif
# Regla principal: compilar el ejecutable # Regla principal: compilar el ejecutable

View File

@@ -4,7 +4,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS); SDL_Init(SDL_INIT_VIDEO);
constexpr int WIDTH = 160; constexpr int WIDTH = 160;
constexpr int HEIGHT = 160; constexpr int HEIGHT = 160;
@@ -14,6 +14,7 @@ int main(int argc, char *argv[])
SDL_Window *window = SDL_CreateWindow("pixels", WIDTH * ZOOM, HEIGHT * ZOOM, SDL_WINDOW_OPENGL); SDL_Window *window = SDL_CreateWindow("pixels", WIDTH * ZOOM, HEIGHT * ZOOM, SDL_WINDOW_OPENGL);
SDL_Renderer *renderer = SDL_CreateRenderer(window, nullptr); SDL_Renderer *renderer = SDL_CreateRenderer(window, nullptr);
SDL_SetRenderLogicalPresentation(renderer, WIDTH, HEIGHT, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE); SDL_SetRenderLogicalPresentation(renderer, WIDTH, HEIGHT, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
// SDL_SetDefaultTextureScaleMode(renderer, SDL_SCALEMODE_NEAREST);
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, WIDTH, HEIGHT); SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, WIDTH, HEIGHT);
Uint32 *pixels; Uint32 *pixels;
@@ -52,6 +53,7 @@ int main(int argc, char *argv[])
// Dibuja el efecto // Dibuja el efecto
float time = SDL_GetTicks() / 1000.0f; float time = SDL_GetTicks() / 1000.0f;
for (int j = -rad; j <= rad; j += 3) for (int j = -rad; j <= rad; j += 3)
{
for (int i = -rad; i <= rad; i += 2) for (int i = -rad; i <= rad; i += 2)
{ {
float dist = sqrt(i * i + j * j); float dist = sqrt(i * i + j * j);
@@ -59,20 +61,30 @@ int main(int argc, char *argv[])
const int X = rad + i + dx; const int X = rad + i + dx;
const int Y = rad + j - z + dy; const int Y = rad + j - z + dy;
if (X < WIDTH && Y < HEIGHT && X >= 0 && Y >= 0) if (X < WIDTH && Y < HEIGHT && X >= 0 && Y >= 0)
{
surface[X + Y * WIDTH] = 1; surface[X + Y * WIDTH] = 1;
}
} }
}
// Vuelca la surface a la textura // El pitch se mide en bytes, entonces para acceder a cada fila:
for (int i = 0; i < SIZE; ++i) int pixel_pitch = pitch / sizeof(Uint32);
for (int y = 0; y < HEIGHT; ++y)
{ {
pixels[i] = paleta[surface[i]]; for (int x = 0; x < WIDTH; ++x)
{
const int INDEX_SURFACE = x + y * WIDTH;
const int INDEX_TEX = x + y * pixel_pitch;
pixels[INDEX_TEX] = paleta[surface[INDEX_SURFACE]];
}
} }
SDL_UnlockTexture(texture); SDL_UnlockTexture(texture);
SDL_RenderTexture(renderer, texture, nullptr, nullptr); SDL_RenderTexture(renderer, texture, nullptr, nullptr);
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
SDL_DestroyTexture(texture); SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window); SDL_DestroyWindow(window);