arreglat no se que merdes del pitch
This commit is contained in:
2
Makefile
2
Makefile
@@ -9,8 +9,6 @@ OUTPUT_EXT :=
|
||||
ifeq ($(OS),Windows_NT)
|
||||
LDFLAGS += -lmingw32 -lws2_32
|
||||
OUTPUT_EXT := .exe
|
||||
else
|
||||
OUTPUT_EXT := .out
|
||||
endif
|
||||
|
||||
# Regla principal: compilar el ejecutable
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
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 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_Renderer *renderer = SDL_CreateRenderer(window, nullptr);
|
||||
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);
|
||||
|
||||
Uint32 *pixels;
|
||||
@@ -52,6 +53,7 @@ int main(int argc, char *argv[])
|
||||
// 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);
|
||||
@@ -59,13 +61,23 @@ int main(int argc, char *argv[])
|
||||
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)
|
||||
// El pitch se mide en bytes, entonces para acceder a cada fila:
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user