Skip to content

Commit 1a57d32

Browse files
committed
Fixed RGB ordering when loading a bitmap. More tests in main.c.
1 parent 8aa5893 commit 1a57d32

File tree

7 files changed

+37
-18
lines changed

7 files changed

+37
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
bin
22
.idea
33
.vs
4+
main.aps
45
CMakeLists.txt
56
NOTES.md

config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#define WINDOW_TITLE "Punity"
2-
#define CANVAS_WIDTH 64
3-
#define CANVAS_HEIGHT 64
4-
#define CANVAS_SCALE 6
2+
#define CANVAS_WIDTH 128
3+
#define CANVAS_HEIGHT 128
4+
#define CANVAS_SCALE 3
55

66
#define STACK_CAPACITY megabytes(16)
77
#define STORAGE_CAPACITY megabytes(16)

main.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "punity.c"
22

3+
static Bitmap splash;
34
static Font font;
45
static Sound sound1;
56
static Sound sound2;
@@ -14,57 +15,62 @@ init()
1415
CORE->palette.colors[1] = color_make(0x00, 0x00, 0x00, 0xff);
1516
CORE->palette.colors[2] = color_make(0xff, 0xff, 0xff, 0xff);
1617
CORE->palette.colors[3] = color_make(0x63, 0x9b, 0xff, 0xff);
18+
1719
CORE->palette.colors_count = 4;
1820
canvas_clear(1);
1921

22+
bitmap_load_resource(&splash, "splash.png");
23+
2024
bitmap_load_resource(&font.bitmap, "font.png");
2125
font.char_width = 4;
2226
font.char_height = 7;
2327

2428
sound_load_resource(&sound1, "sound1.ogg");
2529
sound_load_resource(&sound2, "sound2.ogg");
26-
sound2.rate = 48000;
30+
// sound2.rate = 48000;
2731

2832
CORE->font = &font;
2933
}
3034

3135
void
3236
step()
3337
{
34-
if (CORE->key_deltas[KEY_SPACE] && CORE->key_states[KEY_SPACE] == 1) {
35-
// sound_play(&sound1);
38+
if (key_pressed(KEY_SPACE)) {
3639
sound_play(&sound2);
3740
}
3841

39-
if (CORE->key_states[KEY_RIGHT]) {
42+
if (key_down(KEY_RIGHT)) {
4043
CORE->translate_x++;
4144
}
4245

43-
if (CORE->key_states[KEY_LEFT]) {
46+
if (key_down(KEY_LEFT)) {
4447
CORE->translate_x--;
4548
}
4649

47-
if (CORE->key_states[KEY_DOWN]) {
50+
if (key_down(KEY_DOWN)) {
4851
CORE->translate_y++;
4952
}
5053

51-
if (CORE->key_states[KEY_UP]) {
54+
if (key_down(KEY_UP)) {
5255
CORE->translate_y--;
5356
}
5457

55-
if (CORE->key_states[KEY_ESCAPE]) {
58+
if (key_pressed(KEY_ESCAPE)) {
5659
CORE->running = 0;
5760
}
5861

62+
5963
canvas_clear(0);
60-
// Rect r = rect_make_size(0, 0, 16, 16);
61-
// bitmap_draw(0, 0, 0, 0, &splash, &r, 0, 0);
64+
65+
bitmap_draw(0, 0, 0, 0, &splash, 0, 0, 0);
6266

6367
text_draw(0, 0, "\n\nHELLO\nWORLD", 3);
6468

6569
rect_draw(rect_make_size(32, 32, 8, 8), 2);
6670

6771
static char buf[256];
68-
sprintf(buf, "%03f %05d", CORE->perf_blit_gdi.delta, (i32)CORE->frame);
72+
sprintf(buf, "%03f %05d", CORE->perf_step.delta, (i32)CORE->frame);
6973
text_draw(0, 0, buf, 2);
74+
75+
CORE->canvas->pixels[0] = COLOR_WHITE;
7076
}

main.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
icon.ico ICON "res\\icon.ico"
2+
splash.png RESOURCE "res\\splash.png"
23
font.png RESOURCE "res\\font.png"
34
sound1.ogg RESOURCE "res\\sound2.ogg"
45
sound2.ogg RESOURCE "res\\sound2-16kHz.ogg"

punity.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,10 @@ bitmap_init(Bitmap *bitmap, i32 width, i32 height, void *pixels, int bpp)
423423
goto next;
424424
}
425425

426-
pixel = *pixels_it;
426+
pixel = *pixels_it;
427+
// TODO: This is just for Windows, need to be done a bit better.
428+
pixel.b = pixels_it->r;
429+
pixel.r = pixels_it->b;
427430
pixel.a = 0xFF;
428431
for (ix = 1; ix < palette->colors_count; ix++) {
429432
if (palette->colors[ix].rgba == pixel.rgba)
@@ -435,7 +438,7 @@ bitmap_init(Bitmap *bitmap, i32 width, i32 height, void *pixels, int bpp)
435438
ASSERT(palette->colors_count != 0xFF);
436439
if (palette->colors_count != 0xFF) {
437440
ix = palette->colors_count;
438-
palette->colors[ix] = *pixels_it;
441+
palette->colors[ix] = pixel;
439442
palette->colors_count++;
440443
// printf("[palette] + #%0.2x %0.2x%0.2x%0.2x%0.2x\n",
441444
// ix, pixel.r, pixel.g, pixel.b, pixel.a);

punity.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,13 @@ bool clip_check();
276276
// This is useful if you want to lighten or darken the colors.
277277
// `ramp` is u8[256] array of indexes starting at darkest color as 1.
278278
// Index of 0 means the color is not being shifted.
279-
void palette_shift(Palette *A, Palette *B, u8 *ramp, i32 amount);
279+
// TODO: void palette_shift(Palette *A, Palette *B, u8 *ramp, i32 amount);
280280

281281

282282
// Draws a filled rectangle to the canvas.
283283
void rect_draw(Rect rect, u8 color);
284284
// Draws a frame of a rectangle to the canvas.
285-
void frame_draw(Rect rect, u8 color);
285+
// TODO: void frame_draw(Rect rect, u8 color);
286286

287287
enum {
288288
DrawFlags_FlipH = 0x01,
@@ -416,6 +416,14 @@ void step();
416416
// Keys
417417
//
418418

419+
// Returns true if key held down.
420+
//
421+
#define key_down(key) (CORE->key_states[key])
422+
423+
// Returns true if key started to be held down in this frame.
424+
//
425+
#define key_pressed(key) (CORE->key_deltas[key] && key_down(key))
426+
419427
#define KEY_MOD_SHIFT 0x0001
420428
#define KEY_MOD_CONTROL 0x0002
421429
#define KEY_MOD_ALT 0x0004

res/splash.png

-38 Bytes
Loading

0 commit comments

Comments
 (0)