2021-09-26 19:55:43 +02:00
|
|
|
#include "SDL.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define WIDTH 640
|
|
|
|
#define HEIGHT 480
|
|
|
|
#define BPP 4
|
|
|
|
#define DEPTH 32
|
2022-04-15 11:11:49 +02:00
|
|
|
|
|
|
|
void setpixel(SDL_Surface* screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
|
2021-09-26 19:55:43 +02:00
|
|
|
{
|
2022-04-15 11:11:49 +02:00
|
|
|
Uint32* pixmem32;
|
|
|
|
Uint32 colour;
|
|
|
|
|
|
|
|
colour = SDL_MapRGB(screen->format, r, g, b);
|
|
|
|
|
|
|
|
pixmem32 = (Uint32*)screen->pixels + y + x;
|
2021-09-26 19:55:43 +02:00
|
|
|
*pixmem32 = colour;
|
|
|
|
}
|
2022-04-15 11:11:49 +02:00
|
|
|
|
2021-09-26 19:55:43 +02:00
|
|
|
void DrawScreen(SDL_Surface* screen, int h)
|
|
|
|
{
|
|
|
|
int x, y, ytimesw;
|
2022-04-15 11:11:49 +02:00
|
|
|
|
|
|
|
if (SDL_MUSTLOCK(screen)) {
|
|
|
|
if (SDL_LockSurface(screen) < 0)
|
|
|
|
return;
|
2021-09-26 19:55:43 +02:00
|
|
|
}
|
2022-04-15 11:11:49 +02:00
|
|
|
|
|
|
|
for (y = 0; y < screen->h; y++) {
|
|
|
|
ytimesw = y * screen->pitch / BPP;
|
|
|
|
for (x = 0; x < screen->w; x++) {
|
|
|
|
setpixel(screen, x, ytimesw, (x * x) / 256 + 3 * y + h, (y * y) / 256 + x + h, h);
|
2021-09-26 19:55:43 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-15 11:11:49 +02:00
|
|
|
if (SDL_MUSTLOCK(screen))
|
|
|
|
SDL_UnlockSurface(screen);
|
|
|
|
|
2021-09-26 19:55:43 +02:00
|
|
|
SDL_Flip(screen);
|
|
|
|
}
|
2022-04-15 11:11:49 +02:00
|
|
|
|
2021-09-26 19:55:43 +02:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2022-04-15 11:11:49 +02:00
|
|
|
SDL_Surface* screen;
|
2021-09-26 19:55:43 +02:00
|
|
|
SDL_Event event;
|
2022-04-15 11:11:49 +02:00
|
|
|
|
2021-09-26 19:55:43 +02:00
|
|
|
int keypress = 0;
|
2022-04-15 11:11:49 +02:00
|
|
|
int h = 0;
|
|
|
|
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN | SDL_HWSURFACE))) {
|
2021-09-26 19:55:43 +02:00
|
|
|
SDL_Quit();
|
|
|
|
return 1;
|
|
|
|
}
|
2022-04-15 11:11:49 +02:00
|
|
|
|
|
|
|
while (!keypress) {
|
|
|
|
DrawScreen(screen, h++);
|
|
|
|
while (SDL_PollEvent(&event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case SDL_QUIT:
|
|
|
|
keypress = 1;
|
|
|
|
break;
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
keypress = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-09-26 19:55:43 +02:00
|
|
|
}
|
2022-04-15 11:11:49 +02:00
|
|
|
|
2021-09-26 19:55:43 +02:00
|
|
|
SDL_Quit();
|
|
|
|
return 0;
|
|
|
|
}
|