-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
58 lines (45 loc) · 1.56 KB
/
test.c
File metadata and controls
58 lines (45 loc) · 1.56 KB
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
50
51
52
53
54
55
56
57
58
#include "bread.h"
#include "graphics/render.h"
#include "math/vector.h"
#include "util/list.h"
#include "window.h"
#define BUFFER_WIDTH 300
#define BUFFER_HEIGHT 200
BScreenBuffer sbuffer;
int offset = 0;
int time = 0;
void keydown(BWindowID) { offset++; }
void pixel_shader(BPixelShaderContext context, BScreenBuffer *buffer) {
int x = context.pixel.x;
int y = context.pixel.y;
BScreenBufferSetPixel(buffer, x, y, BRGB(x, y + (-time & 0xFF), (x + offset) ^ y));
}
void update(BWindowID wid) {
BDrawTriangle((BVector2f){-0.5f, -0.5f}, (BVector2f){0.5f, 0.5f},
(BVector2f){-0.5f, 0.5f}, &sbuffer, pixel_shader);
BDrawTriangle((BVector2f){-0.5f, -0.5f}, (BVector2f){0.5f, -0.5f},
(BVector2f){0.5f, 0.5f}, &sbuffer, pixel_shader);
BWindowDrawScreenBuffer(wid, &sbuffer);
time++;
}
int APIENTRY WinMain(HINSTANCE instance, HINSTANCE, LPSTR cmdLine,
int cmdShow) {
BWindowID wid;
BWindowClassID wcid;
int param;
// Engine initalize.
BInit();
// Create and show window.
wcid = BRegisterWindowClass(instance, "TEST-WIN", -1, NULL, NULL, NULL);
BGetWindowClassByID(wcid)->wcb_keydown = keydown;
wid = BCreateWindow(wcid, NULL, -1, instance, -1, -1, BUFFER_WIDTH + 16,
BUFFER_HEIGHT + 39, NULL, NULL);
BShowWindow(wid, cmdShow);
// Create screen buffer.
BScreenBufferCreate(&sbuffer, BUFFER_WIDTH, BUFFER_HEIGHT);
// Message loop.
param = BMessageLoop(wid, update);
// Free memory and quit.
BQuit();
return param;
}