Primer commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.o
|
||||||
9
Makefile
Normal file
9
Makefile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
name = paleta
|
||||||
|
executable = $(name).o
|
||||||
|
source = $(name).cpp
|
||||||
|
|
||||||
|
linux:
|
||||||
|
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -o "$(executable)"
|
||||||
|
|
||||||
|
macos:
|
||||||
|
clang++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o $(executable)
|
||||||
49
paleta.cpp
Normal file
49
paleta.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
struct ARGB
|
||||||
|
{
|
||||||
|
Uint8 b, g, r, a;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
SDL_Init(SDL_INIT_EVERYTHING);
|
||||||
|
|
||||||
|
SDL_Window *w = SDL_CreateWindow("pixels", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
|
||||||
|
SDL_Renderer *r = SDL_CreateRenderer(w, -1, 0);
|
||||||
|
SDL_RenderSetLogicalSize(r, 320, 240);
|
||||||
|
SDL_Texture *t = SDL_CreateTexture(r, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 240);
|
||||||
|
|
||||||
|
ARGB *pixels;
|
||||||
|
int pitch;
|
||||||
|
|
||||||
|
SDL_Event sdlEvent;
|
||||||
|
bool exit = false;
|
||||||
|
while (!exit)
|
||||||
|
{
|
||||||
|
while (SDL_PollEvent(&sdlEvent))
|
||||||
|
{
|
||||||
|
if (sdlEvent.type == SDL_QUIT)
|
||||||
|
{
|
||||||
|
exit = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_LockTexture(t, nullptr, (void **)&pixels, &pitch);
|
||||||
|
|
||||||
|
for (int i = 0; i < 76800; ++i)
|
||||||
|
{
|
||||||
|
pixels[i].b = rand() % 256;
|
||||||
|
pixels[i].g = rand() % 256;
|
||||||
|
pixels[i].r = rand() % 256;
|
||||||
|
pixels[i].a = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_UnlockTexture(t);
|
||||||
|
|
||||||
|
SDL_RenderCopy(r, t, nullptr, nullptr);
|
||||||
|
|
||||||
|
SDL_RenderPresent(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user