X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg%2Fvg.h;h=9ff59ddd2fa741b4fb9102f578598f8ffc5fbead;hb=ab7f9c0826344344193502caaaa72c4abe48248c;hp=6b4cd233a5365a1ecbdfa66b4a4374773c515e6d;hpb=56d6d59869fcdd9d23b0135e3262d9d29c218e05;p=fishladder.git diff --git a/vg/vg.h b/vg/vg.h index 6b4cd23..9ff59dd 100644 --- a/vg/vg.h +++ b/vg/vg.h @@ -11,17 +11,26 @@ #include "gl/glfw3.h" #define STB_DS_IMPLEMENTATION +#define STB_IMAGE_IMPLEMENTATION #include "stb/stb_ds.h" +#include "stb/stb_image.h" -#include "cglm/include/cglm/cglm.h" +#include "vg/vg_platform.h" void vg_register_exit( void( *funcptr )(void), const char *name ); void vg_exiterr( const char *strErr ); -#include "vg/vg_platform.h" +m3x3f vg_pv; + +#include "vg/vg_m.h" #include "vg/vg_io.h" + +#ifndef VG_TOOLS + #include "vg/vg_audio.h" #include "vg/vg_shader.h" +#include "vg/vg_lines.h" +#include "vg/vg_tex.h" #include "steam/steamworks_thin.h" @@ -35,8 +44,8 @@ GLFWwindow* vg_window; int vg_window_x = 1280; int vg_window_y = 720; -float vg_mouse_x; -float vg_mouse_y; +v2f vg_mouse; +v3f vg_mouse_ws; float vg_time; float vg_time_last; @@ -126,7 +135,7 @@ static inline int vg_get_button_up( const char *button ) static inline int key_is_keyboard( int const id ) { - static_assert( GLFW_MOUSE_BUTTON_LAST < GLFW_KEY_SPACE, "GLFW: Mouse has too many buttons" ); + vg_static_assert( GLFW_MOUSE_BUTTON_LAST < GLFW_KEY_SPACE, "GLFW: Mouse has too many buttons" ); return id > GLFW_MOUSE_BUTTON_LAST; } @@ -234,8 +243,8 @@ void vg_exiterr( const char *strErr ) void vg_mouse_callback( GLFWwindow* ptrW, double xpos, double ypos ) { - vg_mouse_x = xpos; - vg_mouse_y = ypos; + vg_mouse[0] = xpos; + vg_mouse[1] = ypos; } void vg_scroll_callback( GLFWwindow* ptrW, double xoffset, double yoffset ) @@ -249,6 +258,7 @@ void vg_framebuffer_resize_callback( GLFWwindow *ptrW, int w, int h ) vg_window_y = h; } +static void vg_register(void) VG_GAMELOOP; static void vg_start(void) VG_GAMELOOP; static void vg_update(void) VG_GAMELOOP; static void vg_render(void) VG_GAMELOOP; @@ -327,16 +337,22 @@ static void vg_init( int argc, char *argv[], const char *window_name ) vg_gamepad_ready = 1; vg_gamepad_id = id; - return; + break; } } vg_audio_init(); vg_register_exit( &vg_audio_free, "vg_audio_free" ); + vg_lines_init(); + vg_register_exit( &vg_lines_free, "vg_lines_free" ); + + vg_register(); + vg_register_exit( &vg_free, "vg_free" ); - vg_start(); if( vg_shaders_compile() ) { + vg_start(); + // Main gameloop while( !glfwWindowShouldClose( vg_window ) ) { @@ -351,12 +367,11 @@ static void vg_init( int argc, char *argv[], const char *window_name ) vg_time_delta = vg_min( vg_time - vg_time_last, 0.1f ); vg_update_inputs(); - vg_update(); + vg_render(); - // Update mashed projections etc + vg_lines_drawall(); - vg_render(); vg_ui(); glfwSwapBuffers( vg_window ); @@ -365,9 +380,28 @@ static void vg_init( int argc, char *argv[], const char *window_name ) } } - vg_free(); vg_exit(); } +// Screen projections +// ============================================================================================ + +void vg_projection_update(void) +{ + // Do transform local->world + vg_mouse_ws[0] = vg_mouse[0]; + vg_mouse_ws[1] = vg_mouse[1]; + vg_mouse_ws[2] = 1.0f; + + vg_mouse_ws[0] = (2.0f * vg_mouse_ws[0]) / ((float)vg_window_x) - 1.0f; + vg_mouse_ws[1] = -((2.0f * vg_mouse_ws[1]) / ((float)vg_window_y) - 1.0f); + + m3x3f inverse; + m3x3_inv( vg_pv, inverse ); + m3x3_mulv( inverse, vg_mouse_ws, vg_mouse_ws ); +} + +#endif + u32 NvOptimusEnablement = 0x00000001; int AmdPowerXpressRequestHighPerformance = 1;