From 1b249ac1e15b59867c6f9af3ff628cffba0840ee Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 19 Jun 2019 15:43:35 +0200 Subject: [PATCH 1/2] Define some globals --- src/core.c | 10 +++++----- src/rlgl.h | 18 +++++++++--------- src/text.c | 2 +- src/utils.c | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/core.c b/src/core.c index da981fd0a..00647ed98 100644 --- a/src/core.c +++ b/src/core.c @@ -301,7 +301,7 @@ static int renderOffsetX = 0; // Offset X from render area (mu static int renderOffsetY = 0; // Offset Y from render area (must be divided by 2) static bool fullscreen = false; // Fullscreen mode (useful only for PLATFORM_DESKTOP) static bool alwaysRun = false; // Keep window update/draw running on minimized -static Matrix screenScaling; // Matrix to scale screen (framebuffer rendering) +static Matrix screenScaling = { 0 }; // Matrix to scale screen (framebuffer rendering) #if defined(PLATFORM_RPI) static EGL_DISPMANX_WINDOW_T nativeWindow; // Native window (graphic device) @@ -312,7 +312,7 @@ static EGLDisplay display; // Native display device (physic static EGLSurface surface; // Surface to draw on, framebuffers (connected to context) static EGLContext context; // Graphic context, mode in which drawing can be done static EGLConfig config; // Graphic config -static uint64_t baseTime; // Base time measure for hi-res timer +static uint64_t baseTime = 0; // Base time measure for hi-res timer static bool windowShouldClose = false; // Flag to set window for closing #endif @@ -342,7 +342,7 @@ static int exitKey = KEY_ESCAPE; // Default exit key (ESC) #if defined(PLATFORM_RPI) // NOTE: For keyboard we will use the standard input (but reconfigured...) static struct termios defaultKeyboardSettings; // Used to store default keyboard settings -static int defaultKeyboardMode; // Used to store default keyboard mode +static int defaultKeyboardMode = 0; // Used to store default keyboard mode #endif // Mouse states @@ -384,8 +384,8 @@ typedef struct{ char Tail; } KeyEventFifo; -static KeyEventFifo lastKeyPressedEvdev; // Buffer for holding keydown events as they arrive (Needed due to multitreading of event workers) -static char currentKeyStateEvdev[512] = { 0 }; // Registers current frame key state from event based driver (Needs to be seperate because the legacy console based method clears keys on every frame) +static KeyEventFifo lastKeyPressedEvdev = { 0 }; // Buffer for holding keydown events as they arrive (Needed due to multitreading of event workers) +static char currentKeyStateEvdev[512] = { 0 }; // Registers current frame key state from event based driver (Needs to be seperate because the legacy console based method clears keys on every frame) #endif #if defined(PLATFORM_WEB) diff --git a/src/rlgl.h b/src/rlgl.h index b2f1d0bcb..1bc07185e 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -782,14 +782,14 @@ static DrawCall *draws = NULL; static int drawsCounter = 0; // Default texture (1px white) useful for plain color polys (required by shader) -static unsigned int defaultTextureId; +static unsigned int defaultTextureId = 0; // Default shaders -static unsigned int defaultVShaderId; // Default vertex shader id (used by default shader program) -static unsigned int defaultFShaderId; // Default fragment shader Id (used by default shader program) +static unsigned int defaultVShaderId = 0; // Default vertex shader id (used by default shader program) +static unsigned int defaultFShaderId = 0; // Default fragment shader Id (used by default shader program) -static Shader defaultShader; // Basic shader, support vertex color and diffuse texture -static Shader currentShader; // Shader to be used on rendering (by default, defaultShader) +static Shader defaultShader = { 0 }; // Basic shader, support vertex color and diffuse texture +static Shader currentShader = { 0 }; // Shader to be used on rendering (by default, defaultShader) // Extension supported flag: VAO static bool vaoSupported = false; // VAO support (OpenGL ES2 could not support VAO extension) @@ -827,7 +827,7 @@ static PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArrays; #if defined(SUPPORT_VR_SIMULATOR) // VR global variables static VrStereoConfig vrConfig = { 0 }; // VR stereo configuration for simulator -static RenderTexture2D stereoFbo; // VR stereo rendering framebuffer +static RenderTexture2D stereoFbo = { 0 }; // VR stereo rendering framebuffer static bool vrSimulatorReady = false; // VR simulator ready flag static bool vrStereoRender = false; // VR stereo rendering enabled/disabled flag // NOTE: This flag is useful to render data over stereo image (i.e. FPS) @@ -835,11 +835,11 @@ static bool vrStereoRender = false; // VR stereo rendering enabled/disab #endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 -static int blendMode = 0; // Track current blending mode +static int blendMode = 0; // Track current blending mode // Default framebuffer size -static int screenWidth; // Default framebuffer width -static int screenHeight; // Default framebuffer height +static int screenWidth = 0; // Default framebuffer width +static int screenHeight= 0; // Default framebuffer height //---------------------------------------------------------------------------------- // Module specific Functions Declaration diff --git a/src/text.c b/src/text.c index 9a0bcb366..6b742fd25 100644 --- a/src/text.c +++ b/src/text.c @@ -74,7 +74,7 @@ // Global variables //---------------------------------------------------------------------------------- #if defined(SUPPORT_DEFAULT_FONT) -static Font defaultFont; // Default font provided by raylib +static Font defaultFont = { 0 }; // Default font provided by raylib // NOTE: defaultFont is loaded on InitWindow and disposed on CloseWindow [module: core] #endif diff --git a/src/utils.c b/src/utils.c index ee4be46d0..8aad9f44b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -62,7 +62,7 @@ static int logTypeExit = LOG_ERROR; static TraceLogCallback logCallback = NULL; #if defined(PLATFORM_ANDROID) -AAssetManager *assetManager; +AAssetManager *assetManager = NULL; #endif //---------------------------------------------------------------------------------- From 65a21ab416ec5f149968bae52257b3ed86a57c2e Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 19 Jun 2019 16:01:47 +0200 Subject: [PATCH 2/2] Renamed screenWidth & screenHeight --- src/rlgl.h | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/rlgl.h b/src/rlgl.h index 1bc07185e..a77212eba 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -835,11 +835,11 @@ static bool vrStereoRender = false; // VR stereo rendering enabled/disab #endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 -static int blendMode = 0; // Track current blending mode +static int blendMode = 0; // Track current blending mode // Default framebuffer size -static int screenWidth = 0; // Default framebuffer width -static int screenHeight= 0; // Default framebuffer height +static int framebufferWidth = 0; // Default framebuffer width +static int framebufferHeight = 0; // Default framebuffer height //---------------------------------------------------------------------------------- // Module specific Functions Declaration @@ -1019,7 +1019,7 @@ void rlOrtho(double left, double right, double bottom, double top, double znear, #endif // Set the viewport area (transformation from normalized device coordinates to window coordinates) -// NOTE: Updates global variables: screenWidth, screenHeight +// NOTE: Updates global variables: framebufferWidth, framebufferHeight void rlViewport(int x, int y, int width, int height) { glViewport(x, y, width, height); @@ -1714,8 +1714,8 @@ void rlglInit(int width, int height) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers (depth buffer required for 3D) // Store screen size into global variables - screenWidth = width; - screenHeight = height; + framebufferWidth = width; + framebufferHeight = height; TraceLog(LOG_INFO, "OpenGL default states initialized successfully"); } @@ -3235,7 +3235,7 @@ Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size) glBindFramebuffer(GL_FRAMEBUFFER, 0); // Reset viewport dimensions to default - glViewport(0, 0, screenWidth, screenHeight); + glViewport(0, 0, framebufferWidth, framebufferHeight); //glEnable(GL_CULL_FACE); // NOTE: Texture2D is a GL_TEXTURE_CUBE_MAP, not a GL_TEXTURE_2D! @@ -3313,7 +3313,7 @@ Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size) glBindFramebuffer(GL_FRAMEBUFFER, 0); // Reset viewport dimensions to default - glViewport(0, 0, screenWidth, screenHeight); + glViewport(0, 0, framebufferWidth, framebufferHeight); irradiance.width = size; irradiance.height = size; @@ -3408,7 +3408,7 @@ Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size) glBindFramebuffer(GL_FRAMEBUFFER, 0); // Reset viewport dimensions to default - glViewport(0, 0, screenWidth, screenHeight); + glViewport(0, 0, framebufferWidth, framebufferHeight); prefilter.width = size; prefilter.height = size; @@ -3465,7 +3465,7 @@ Texture2D GenTextureBRDF(Shader shader, int size) glDeleteFramebuffers(1, &fbo); // Reset viewport dimensions to default - glViewport(0, 0, screenWidth, screenHeight); + glViewport(0, 0, framebufferWidth, framebufferHeight); brdf.width = size; brdf.height = size; @@ -3508,7 +3508,7 @@ void BeginScissorMode(int x, int y, int width, int height) rlglDraw(); // Force drawing elements glEnable(GL_SCISSOR_TEST); - glScissor(x, screenHeight - (y + height), width, height); + glScissor(x, framebufferHeight - (y + height), width, height); } // End scissor mode @@ -3527,7 +3527,7 @@ void InitVrSimulator(void) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) // Initialize framebuffer and textures for stereo rendering // NOTE: Screen size should match HMD aspect ratio - stereoFbo = rlLoadRenderTexture(screenWidth, screenHeight, UNCOMPRESSED_R8G8B8A8, 24, false); + stereoFbo = rlLoadRenderTexture(framebufferWidth, framebufferHeight, UNCOMPRESSED_R8G8B8A8, 24, false); vrSimulatorReady = true; #else @@ -3655,8 +3655,8 @@ void ToggleVrMode(void) vrStereoRender = false; // Reset viewport and default projection-modelview matrices - rlViewport(0, 0, screenWidth, screenHeight); - projection = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0); + rlViewport(0, 0, framebufferWidth, framebufferHeight); + projection = MatrixOrtho(0.0, framebufferWidth, framebufferHeight, 0.0, 0.0, 1.0); modelview = MatrixIdentity(); } else vrStereoRender = true; @@ -3694,12 +3694,12 @@ void EndVrDrawing(void) rlClearScreenBuffers(); // Clear current framebuffer // Set viewport to default framebuffer size (screen size) - rlViewport(0, 0, screenWidth, screenHeight); + rlViewport(0, 0, framebufferWidth, framebufferHeight); // Let rlgl reconfigure internal matrices rlMatrixMode(RL_PROJECTION); // Enable internal projection matrix rlLoadIdentity(); // Reset internal projection matrix - rlOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0); // Recalculate internal projection matrix + rlOrtho(0.0, framebufferWidth, framebufferHeight, 0.0, 0.0, 1.0); // Recalculate internal projection matrix rlMatrixMode(RL_MODELVIEW); // Enable internal modelview matrix rlLoadIdentity(); // Reset internal modelview matrix @@ -3742,8 +3742,8 @@ void EndVrDrawing(void) currentShader = defaultShader; // Reset viewport and default projection-modelview matrices - rlViewport(0, 0, screenWidth, screenHeight); - projection = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0); + rlViewport(0, 0, framebufferWidth, framebufferHeight); + projection = MatrixOrtho(0.0, framebufferWidth, framebufferHeight, 0.0, 0.0, 1.0); modelview = MatrixIdentity(); rlDisableDepthTest(); @@ -4409,7 +4409,7 @@ static void SetStereoView(int eye, Matrix matProjection, Matrix matModelView) Matrix eyeModelView = matModelView; // Setup viewport and projection/modelview matrices using tracking data - rlViewport(eye*screenWidth/2, 0, screenWidth/2, screenHeight); + rlViewport(eye*framebufferWidth/2, 0, framebufferWidth/2, framebufferHeight); // Apply view offset to modelview matrix eyeModelView = MatrixMultiply(matModelView, vrConfig.eyesViewOffset[eye]);