Browse Source

Improved windows resizing system...

...despite not being enabled on GLFW3
pull/107/head
raysan5 9 years ago
parent
commit
ebc2b9a286
2 changed files with 19 additions and 13 deletions
  1. +10
    -7
      src/core.c
  2. +9
    -6
      src/rlgl.c

+ 10
- 7
src/core.c View File

@ -1488,11 +1488,11 @@ static void InitDisplay(int width, int height)
TraceLog(INFO, "Viewport offsets: %i, %i", renderOffsetX, renderOffsetY); TraceLog(INFO, "Viewport offsets: %i, %i", renderOffsetX, renderOffsetY);
} }
glfwSetWindowSizeCallback(window, WindowSizeCallback);
glfwSetWindowSizeCallback(window, WindowSizeCallback); // NOTE: Resizing not allowed by default!
glfwSetCursorEnterCallback(window, CursorEnterCallback); glfwSetCursorEnterCallback(window, CursorEnterCallback);
glfwSetKeyCallback(window, KeyCallback); glfwSetKeyCallback(window, KeyCallback);
glfwSetMouseButtonCallback(window, MouseButtonCallback); glfwSetMouseButtonCallback(window, MouseButtonCallback);
glfwSetCursorPosCallback(window, MouseCursorPosCallback); // Track mouse position changes
glfwSetCursorPosCallback(window, MouseCursorPosCallback); // Track mouse position changes
glfwSetCharCallback(window, CharCallback); glfwSetCharCallback(window, CharCallback);
glfwSetScrollCallback(window, ScrollCallback); glfwSetScrollCallback(window, ScrollCallback);
glfwSetWindowIconifyCallback(window, WindowIconifyCallback); glfwSetWindowIconifyCallback(window, WindowIconifyCallback);
@ -1818,16 +1818,19 @@ static void CursorEnterCallback(GLFWwindow *window, int enter)
} }
// GLFW3 WindowSize Callback, runs when window is resized // GLFW3 WindowSize Callback, runs when window is resized
// NOTE: Window resizing not allowed by default
static void WindowSizeCallback(GLFWwindow *window, int width, int height) static void WindowSizeCallback(GLFWwindow *window, int width, int height)
{ {
// If window is resized, graphics device is re-initialized (but only ortho mode) // If window is resized, graphics device is re-initialized (but only ortho mode)
rlglInitGraphics(n">renderOffsetX, renderOffsetY, renderWidth, renderHeight);
rlglInitGraphics(mi">0, 0, width, height);
// Window size must be updated to be used on 3D mode to get new aspect ratio (Begin3dMode()) // Window size must be updated to be used on 3D mode to get new aspect ratio (Begin3dMode())
//screenWidth = width;
//screenHeight = height;
// TODO: Update render size?
screenWidth = width;
screenHeight = height;
renderWidth = width;
renderHeight = height;
// NOTE: Postprocessing texture is not scaled to new size
// Background must be also re-cleared // Background must be also re-cleared
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);

+ 9
- 6
src/rlgl.c View File

@ -188,6 +188,8 @@ typedef struct {
// Framebuffer Object type // Framebuffer Object type
typedef struct { typedef struct {
GLuint id; GLuint id;
int width;
int height;
GLuint colorTextureId; GLuint colorTextureId;
GLuint depthTextureId; GLuint depthTextureId;
} FBO; } FBO;
@ -1071,8 +1073,8 @@ void rlglInitPostpro(void)
quad.vertexCount = 6; quad.vertexCount = 6;
float w = (float)screenWidth;
float h = (float)screenHeight;
float w = (float)postproFbo.width;
float h = (float)postproFbo.height;
float quadPositions[6*3] = { w, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, h, 0.0f, 0.0f, h, 0.0f, w, h, 0.0f, w, 0.0f, 0.0f }; float quadPositions[6*3] = { w, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, h, 0.0f, 0.0f, h, 0.0f, w, h, 0.0f, w, 0.0f, 0.0f };
float quadTexcoords[6*2] = { 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f }; float quadTexcoords[6*2] = { 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f };
@ -1096,6 +1098,8 @@ FBO rlglLoadFBO(int width, int height)
{ {
FBO fbo; FBO fbo;
fbo.id = 0; fbo.id = 0;
fbo.width = width;
fbo.height = height;
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Create the texture that will serve as the color attachment for the framebuffer // Create the texture that will serve as the color attachment for the framebuffer
@ -2339,22 +2343,21 @@ void SetCustomShader(Shader shader)
} }
// Set postprocessing shader // Set postprocessing shader
// NOTE: Uses global variables screenWidth and screenHeight
void SetPostproShader(Shader shader) void SetPostproShader(Shader shader)
{ {
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
if (!enabledPostpro) if (!enabledPostpro)
{ {
enabledPostpro = true; enabledPostpro = true;
rlglInitPostpro();
rlglInitPostpro(); // Lazy initialization on postprocessing usage
} }
SetModelShader(&postproQuad, shader); SetModelShader(&postproQuad, shader);
Texture2D texture; Texture2D texture;
texture.id = postproFbo.colorTextureId; texture.id = postproFbo.colorTextureId;
texture.width = screenWidth;
texture.height = screenHeight;
texture.width = postproFbo.width;
texture.height = postproFbo.height;
postproQuad.material.texDiffuse = texture; postproQuad.material.texDiffuse = texture;

Loading…
Cancel
Save