-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
49 lines (41 loc) · 1.26 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <raylib.h>
#include <cstdint>
int main()
{
const int screenWidth = 800;
const int screenHeight = 450;
const int imgWidth = 400;
const int imgHeight = 400;
InitWindow(screenWidth, screenHeight, "Pixel Manipulation");
SetTargetFPS(60);
Image img = GenImageColor(imgHeight, imgHeight, WHITE);
ImageFormat(&img, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
auto pixels = (Color*)img.data;
Texture tex = LoadTextureFromImage(img);
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// your update logic goes here
for(int row = 0; row < imgHeight; row++)
{
for(int col = 0; col < imgWidth; col++)
{
pixels[row * imgWidth + col] = (Color) {
(uint8_t)(GetRandomValue(0, 255)),
(uint8_t)(GetRandomValue(0, 255)),
(uint8_t)(GetRandomValue(0, 255)),
255
};
}
}
UpdateTexture(tex, pixels);
// drawing logic goes here
BeginDrawing();
ClearBackground(BLACK);
DrawTexture(tex, 200, 25, WHITE);
EndDrawing();
}
UnloadTexture(tex);
CloseWindow();
return 0;
}