medfall

A super great game engine
Log | Files | Refs

commit b1c9bbc3137584cec626c2d026f47d1178362b59
parent e45603767349eba244d1405eb8a9bf9b80dbe22a
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Jul  2 00:02:59 +0300

Small window for the launcher, no sRGB, and start in the middle of the screen

Diffstat:
gl.cc | 36+++++++++++++++++++++++++++++++-----
gl.h | 7++++++-
launcher/main.cc | 2+-
main.cc | 2+-
4 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/gl.cc b/gl.cc @@ -99,7 +99,7 @@ static void glfw_error_callback( int code, const char * message ) { WARN( "GLFW error {}: {}", code, message ); } -GLFWwindow * gl_init() { +GLFWwindow * gl_init( WindowType window_type ) { glfwSetErrorCallback( glfw_error_callback ); if( !glfwInit() ) { @@ -108,7 +108,16 @@ GLFWwindow * gl_init() { glfwWindowHint( GLFW_RESIZABLE, 0 ); - const GLFWvidmode * mode = glfwGetVideoMode( glfwGetPrimaryMonitor() ); + int width = 800; + int height = 285; + + GLFWmonitor * monitor = glfwGetPrimaryMonitor(); + const GLFWvidmode * mode = glfwGetVideoMode( monitor ); + + if( window_type == WINDOW_GAME ) { + width = mode->width; + height = mode->height; + } glfwWindowHint( GLFW_CLIENT_API, GLFW_OPENGL_API ); glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE ); @@ -117,12 +126,27 @@ GLFWwindow * gl_init() { glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 3 ); glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, 1 ); - GLFWwindow * window = glfwCreateWindow( mode->width, mode->height, "Medfall", NULL, NULL ); + GLFWwindow * window = glfwCreateWindow( width, height, "Medfall", NULL, NULL ); if( !window ) { FATAL( "glfwCreateWindow" ); } - window_size = v2u32( checked_cast< u32 >( mode->width ), checked_cast< u32 >( mode->height ) ); + if( window_type == WINDOW_LAUNCHER ) { + int frame_top, frame_bottom, frame_left, frame_right; + glfwGetWindowFrameSize( window, &frame_left, &frame_top, &frame_right, &frame_bottom ); + + int monitor_top, monitor_left; + glfwGetMonitorPos( monitor, &monitor_left, &monitor_top ); + + int total_width = width + frame_left + frame_right; + int total_height = height + frame_top + frame_bottom; + + glfwSetWindowPos( window, + monitor_left + mode->width / 2 - total_width / 2, + monitor_top + mode->height / 2 - total_height / 2 ); + } + + window_size = v2u32( checked_cast< u32 >( width ), checked_cast< u32 >( height ) ); glfwMakeContextCurrent( window ); @@ -182,7 +206,9 @@ GLFWwindow * gl_init() { glEnable( GL_CULL_FACE ); glCullFace( GL_FRONT ); // TODO - glEnable( GL_FRAMEBUFFER_SRGB ); + if( window_type == WINDOW_GAME ) { + glEnable( GL_FRAMEBUFFER_SRGB ); + } return window; } diff --git a/gl.h b/gl.h @@ -4,7 +4,12 @@ struct GLFWwindow; -GLFWwindow * gl_init(); +enum WindowType { + WINDOW_GAME, + WINDOW_LAUNCHER, +}; + +GLFWwindow * gl_init( WindowType window_type ); void gl_term(); v2u32 get_window_size(); diff --git a/launcher/main.cc b/launcher/main.cc @@ -545,7 +545,7 @@ int main() { memarena_init( &arena, memory, sizeof( memory ) ); workqueue_init( &download_queue, &arena, DOWNLOAD_THREADS ); - GLFWwindow * window = gl_init(); + GLFWwindow * window = gl_init( WINDOW_LAUNCHER ); ImGui_ImplGlfwGL3_Init( window, true ); diff --git a/main.cc b/main.cc @@ -43,7 +43,7 @@ int main( int argc, char ** argv ) { logger_thread_name( "main" ); profiler_init(); - GLFWwindow * window = gl_init(); + GLFWwindow * window = gl_init( WINDOW_GAME ); shaders_init(); text_renderer_init(); workqueue_init( &state.background_tasks, &mem.persistent_arena, 2 );