~spiral/fantasy_console

ref: 2edc810f07c26769186d373fbe7817c0ee3f381b fantasy_console/lib/raylib_main.c -rw-r--r-- 2.3 KiB
2edc810fspiral fix: don't load a new texture every time we update the screen 3 months ago
                                                                                
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "raylib.h"

#define max(a, b) ((a)>(b)? (a) : (b))
#define min(a, b) ((a)<(b)? (a) : (b))

const int gameScreenWidth = 256;
const int gameScreenHeight = 224;

unsigned char IMAGE_CODE_DATA[229376];

Texture texture;

void raylib_init(void) {
    const int windowWidth = 800;
    const int windowHeight = 450;

    // Enable config flags for resizable window and vertical synchro
    SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
    InitWindow(windowWidth, windowHeight, "raylib [core] example - window scale letterbox");
    SetWindowMinSize(gameScreenWidth, gameScreenHeight);

    SetTargetFPS(60);                   // Set our game to run at 60 frames-per-second

    // initialize display
    Image image = { 0 };
    image.width = 256;
    image.height = 224;
    image.format = 7;
    image.data = IMAGE_CODE_DATA;
    image.mipmaps = 1;

    texture = LoadTextureFromImage(image);

    raylib_update_image();
}

void raylib_teardown(void) {
    CloseWindow();
}

void raylib_update_image(void) {
    // this immediately updates the texture after we load it, but oh well...
    UpdateTexture(texture, IMAGE_CODE_DATA);

    // Update
    //----------------------------------------------------------------------------------
    // Compute required framebuffer scaling
    float scale = min((float)GetScreenWidth()/gameScreenWidth, (float)GetScreenHeight()/gameScreenHeight);

    BeginDrawing();
        ClearBackground(BLACK);     // Clear screen background

        // Draw render texture to screen, properly scaled
        DrawTexturePro(
            texture,
            (Rectangle){
                0.0f,
                0.0f,
                (float)texture.width,
                (float)-texture.height
            },
            (Rectangle){
                (GetScreenWidth() - ((float)gameScreenWidth*scale))*0.5f,
                (GetScreenHeight() - ((float)gameScreenHeight*scale))*0.5f,
                (float)gameScreenWidth*scale, (float)gameScreenHeight*scale
            },
            (Vector2){ 0, 0 },
            0.0f,
            WHITE
        );
    EndDrawing();
    //--------------------------------------------------------------------------------------
}

int weh(void) {
    Image image = LoadImage("example_image.png");
    ExportImageAsCode(image, "lib/image_code.c");
    return 0;
}