More refactoring
Get fullscreen mostly working in GLFW3
This commit is contained in:
parent
c4aa8e28bb
commit
4d8be3bc36
3 changed files with 49 additions and 15 deletions
|
@ -98,6 +98,9 @@ static Backend_Surface *glyph_destination_surface;
|
|||
|
||||
static spritebatch_t glyph_batcher;
|
||||
|
||||
static int actual_screen_width;
|
||||
static int actual_screen_height;
|
||||
|
||||
#ifdef USE_OPENGLES2
|
||||
static const GLchar *vertex_shader_plain = " \
|
||||
#version 100\n \
|
||||
|
@ -515,7 +518,10 @@ static void GlyphBatch_DestroyTexture(SPRITEBATCH_U64 texture_id, void *udata)
|
|||
|
||||
Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
|
||||
{
|
||||
if (WindowBackend_OpenGL_CreateWindow(window_title, screen_width, screen_height, fullscreen))
|
||||
actual_screen_width = screen_width;
|
||||
actual_screen_height = screen_height;
|
||||
|
||||
if (WindowBackend_OpenGL_CreateWindow(window_title, &actual_screen_width, &actual_screen_height, fullscreen))
|
||||
{
|
||||
printf("GL_VENDOR = %s\n", glGetString(GL_VENDOR));
|
||||
printf("GL_RENDERER = %s\n", glGetString(GL_RENDERER));
|
||||
|
@ -656,7 +662,30 @@ void Backend_DrawScreen(void)
|
|||
// Target actual screen, and not our framebuffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
glViewport(0, 0, framebuffer.width, framebuffer.height);
|
||||
// Do some viewport trickery, to fit the framebuffer in the center of the screen
|
||||
GLint x;
|
||||
GLint y;
|
||||
GLsizei width;
|
||||
GLsizei height;
|
||||
|
||||
if (actual_screen_width > actual_screen_height)
|
||||
{
|
||||
y = 0;
|
||||
height = actual_screen_height;
|
||||
|
||||
width = framebuffer.width * ((float)actual_screen_height / (float)framebuffer.height);
|
||||
x = (actual_screen_width - width) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = 0;
|
||||
width = actual_screen_width;
|
||||
|
||||
height = framebuffer.height * ((float)actual_screen_width / (float)framebuffer.width);
|
||||
y = (actual_screen_height - height) / 2;
|
||||
}
|
||||
|
||||
glViewport(x, y, width, height);
|
||||
|
||||
// Draw framebuffer to screen
|
||||
glBindTexture(GL_TEXTURE_2D, framebuffer.texture_id);
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
#include "../WindowsWrapper.h"
|
||||
|
||||
BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int screen_width, int screen_height, BOOL fullscreen);
|
||||
BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen);
|
||||
void WindowBackend_OpenGL_DestroyWindow(void);
|
||||
void WindowBackend_OpenGL_Display(void);
|
||||
|
|
|
@ -22,7 +22,7 @@ void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods
|
|||
void WindowFocusCallback(GLFWwindow *window, int focused);
|
||||
void WindowSizeCallback(GLFWwindow *window, int width, int height);
|
||||
|
||||
BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
|
||||
BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen)
|
||||
{
|
||||
#ifdef USE_OPENGLES2
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
|
@ -36,7 +36,22 @@ BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int screen_widt
|
|||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||
#endif
|
||||
|
||||
window = glfwCreateWindow(screen_width, screen_height, window_title, NULL, NULL);
|
||||
GLFWmonitor *monitor = NULL;
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
monitor = glfwGetPrimaryMonitor();
|
||||
|
||||
if (monitor != NULL)
|
||||
{
|
||||
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
||||
|
||||
*screen_width = mode->width;
|
||||
*screen_height = mode->height;
|
||||
}
|
||||
}
|
||||
|
||||
window = glfwCreateWindow(*screen_width, *screen_height, window_title, monitor, NULL);
|
||||
|
||||
if (window != NULL)
|
||||
{/*
|
||||
|
@ -50,16 +65,6 @@ BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int screen_widt
|
|||
#endif
|
||||
*/
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
||||
if (monitor)
|
||||
{
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
|
||||
}
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
#ifndef USE_OPENGLES2
|
||||
|
|
Loading…
Add table
Reference in a new issue