The Melodist»Blog

Some Sample dxE Code (3/30/2017)

Hey everyone!

I thought I'd show a quick sample of dxE (my game-independent library) code. dxE has recently been almost completely rewritten in C, as I've abandoned my object-oriented approach. The only C++ code I have yet to replace is my use of GLM, which I'll be replacing soon with the HandmadeMath library.

The new rewrite of dxE currently supports:

-Multiple Windows
-Keyboard/Mouse Input
-Resources (Shaders, Textures, Fonts, Audio)
-Multi-threaded Resource Management (Parses requests, loads in resources as needed, allows for dynamic loading screens and loading during gameplay)
-Output (Audio, Rendering)
-Custom shader support; can use raw OpenGL alongside dxE if needed, but drawing primitives/textures/text doesn't require any custom shaders (default shaders provided)

I'm really just implementing features as I need them for my game, but I have quite a bit more planned.

Here's that sample:
 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
#include <dxE/dxE.h>

//generic keys; name after actions
//this allows for dynamic key-configuration changing
enum KeyType {
    KEY_EXIT,
    MAX_KEY
};

int main() {
    dxE_initialize();

    dxE_Window *window = dxE_new_window("dxE Sample",   //title of window
                                        800,            //width
                                        600,            //height
                                        MAX_KEY,        //number of keys to initialize
                                        DX_KEY_A        //key that is assigned to the index of KEY_EXIT
                                        );

    dxE_Timer *timer = dxE_new_timer(60.0); //60 FPS

    //while the window has not been quit
    while(!dxE_window_closed(window)) {
        if(dxE_timer_needs_reset(timer)) {
            //reset the timer first, so the program doesn't wait to finish
            //logic/rendering
            dxE_reset_timer(timer);
            dxE_update_window(window);

            if(dxE_key_pressed(window, KEY_EXIT)) {
                dxE_window_quit(window);
            }

            dxE_prepare_to_render(window);
            {
                dxE_draw_filled_rectangle(window,       //target
                                          0,            //x coord
                                          0,            //y coord
                                          800,          //width
                                          600,          //height
                                        //r  g  b  a
                                          1, 0, 0, 1,
                                          0             //rotation (in degrees)
                                          );
            }
            dxE_finish_render(window);
        }
    }

    dxE_free_timer(timer);
    dxE_free_window(window);

    dxE_clean_up();

    return 0;
}


Hope this was interesting; let me know if you want to see more or if you'd like to see some under-the-hood details.
-Delix
If you need any help moving your project over to HandmadeMath just let me know :)
Ryan Fleury,
@strangezak

Will do! Thanks. :)