Tested some desktop stuff and added projection matrix updates for window resizing.

This commit is contained in:
Reece Mackie 2019-04-26 19:25:23 +01:00
parent 3e8d52b0ff
commit ff33e12ee5
5 changed files with 117 additions and 66 deletions

View File

@ -28,6 +28,8 @@ int main(int argc, char* argv[])
int screenWidth = 800;
int screenHeight = 450;
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);

View File

@ -18,7 +18,7 @@ int main(Platform::Array<Platform::String^>^)
App::App()
{
//This does not work... need to fix this.
SetConfigFlags(FLAG_SHOW_LOGO);
SetConfigFlags(0);
}
static int posX = 100;

View File

@ -123,6 +123,16 @@ public:
virtual void Run()
{
//Get display dimensions
DisplayInformation^ dInfo = DisplayInformation::GetForCurrentView();
Vector2 screenSize = { dInfo->ScreenWidthInRawPixels, dInfo->ScreenHeightInRawPixels };
//Send display dimensions
UWPMessage* msg = CreateUWPMessage();
msg->Type = SetDisplayDims;
msg->Vector0 = screenSize;
UWPSendMessage(msg);
while (!mWindowClosed)
{
if (mWindowVisible)
@ -285,7 +295,12 @@ protected:
void OnResuming(Platform::Object^ sender, Platform::Object^ args) {}
// Window event handlers.
void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args) {}
void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args)
{
UWPMessage* msg = CreateUWPMessage();
msg->Type = HandleResize;
UWPSendMessage(msg);
}
void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args)
{
@ -416,8 +431,8 @@ private:
bool mWindowClosed = false;
bool mWindowVisible = true;
int width = 800;
int height = 450;
int width = 640;
int height = 480;
};
//Application source for creating the program

View File

@ -626,13 +626,11 @@ void InitWindow(int width, int height, const char *title)
mousePosition.y = (float)screenHeight/2.0f;
// raylib logo appearing animation (if enabled)
#if !defined(PLATFORM_UWP)
if (showLogo)
{
SetTargetFPS(60);
LogoAnimation();
}
#endif //defined(PLATFORM_UWP)
#endif // defined(PLATFORM_ANDROID)
}
@ -887,7 +885,6 @@ int GetScreenHeight(void)
// Get native window handle
void *GetWindowHandle(void)
{
//TODO: See if we can do UWP?
#ifdef PLATFORM_DESKTOP
// NOTE: Returned handle is: void *HWND (windows.h)
return glfwGetWin32Window(window);
@ -2764,6 +2761,8 @@ static bool InitGraphicsDevice(int width, int height)
eglQuerySurface(display, surface, EGL_WIDTH, &screenWidth);
eglQuerySurface(display, surface, EGL_HEIGHT, &screenHeight);
//SetupFramebuffer(displayWidth, displayHeight); //Borked
#else // PLATFORM_ANDROID, PLATFORM_RPI
EGLint numConfigs;
@ -2934,8 +2933,8 @@ static void SetupFramebuffer(int width, int height)
TraceLog(LOG_WARNING, "DOWNSCALING: Required screen size (%ix%i) is bigger than display size (%ix%i)", screenWidth, screenHeight, displayWidth, displayHeight);
// Downscaling to fit display with border-bars
float widthRatio = (float)displayWidth/(float)screenWidth;
float heightRatio = (float)displayHeight/(float)screenHeight;
float widthRatio = (float)displayWidth / (float)screenWidth;
float heightRatio = (float)displayHeight / (float)screenHeight;
if (widthRatio <= heightRatio)
{
@ -2953,7 +2952,7 @@ static void SetupFramebuffer(int width, int height)
}
// Screen scaling required
float scaleRatio = (float)renderWidth/(float)screenWidth;
float scaleRatio = (float)renderWidth / (float)screenWidth;
screenScaling = MatrixScale(scaleRatio, scaleRatio, scaleRatio);
// NOTE: We render to full display resolution!
@ -2969,13 +2968,13 @@ static void SetupFramebuffer(int width, int height)
TraceLog(LOG_INFO, "UPSCALING: Required screen size: %i x %i -> Display size: %i x %i", screenWidth, screenHeight, displayWidth, displayHeight);
// Upscaling to fit display with border-bars
float displayRatio = (float)displayWidth/(float)displayHeight;
float screenRatio = (float)screenWidth/(float)screenHeight;
float displayRatio = (float)displayWidth / (float)displayHeight;
float screenRatio = (float)screenWidth / (float)screenHeight;
if (displayRatio <= screenRatio)
{
renderWidth = screenWidth;
renderHeight = (int)round((float)screenWidth/displayRatio);
renderHeight = (int)round((float)screenWidth / displayRatio);
renderOffsetX = 0;
renderOffsetY = (renderHeight - screenHeight);
}
@ -3263,6 +3262,39 @@ static void PollInputEvents(void)
break;
}
case SetDisplayDims:
{
displayWidth = msg->Vector0.x;
displayHeight = msg->Vector0.y;
break;
}
case HandleResize:
{
eglQuerySurface(display, surface, EGL_WIDTH, &screenWidth);
eglQuerySurface(display, surface, EGL_HEIGHT, &screenHeight);
// If window is resized, viewport and projection matrix needs to be re-calculated
rlViewport(0, 0, screenWidth, screenHeight); // Set viewport width and height
rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
rlLoadIdentity(); // Reset current matrix (PROJECTION)
rlOrtho(0, screenWidth, screenHeight, 0, 0.0f, 1.0f); // Orthographic projection mode with top-left corner at (0,0)
rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix
rlLoadIdentity(); // Reset current matrix (MODELVIEW)
rlClearScreenBuffers(); // Clear screen buffers (color and depth)
// Window size must be updated to be used on 3D mode to get new aspect ratio (BeginMode3D())
// NOTE: Be careful! GLFW3 will choose the closest fullscreen resolution supported by current monitor,
// for example, if reescaling back to 800x450 (desired), it could set 720x480 (closest fullscreen supported)
currentWidth = screenWidth;
currentHeight = screenHeight;
// NOTE: Postprocessing texture is not scaled to new size
windowResized = true;
break;
}
}
DeleteUWPMessage(msg); //Delete, we are done

View File

@ -82,6 +82,8 @@ typedef enum
MarkGamepadActive, //Int0 (gamepad), Bool0 (active or not)
MarkGamepadButton, //Int0 (gamepad), Int1 (button), Char0 (status)
MarkGamepadAxis, //Int0 (gamepad), int1 (axis), Float0 (value)
SetDisplayDims, //Vector0 (display dimensions)
HandleResize, //Vector0 (new dimensions) - Onresized event
} UWPMessageType;
typedef struct UWPMessage {