Tested some desktop stuff and added projection matrix updates for window resizing.
This commit is contained in:
parent
3e8d52b0ff
commit
ff33e12ee5
|
|
@ -28,6 +28,8 @@ int main(int argc, char* argv[])
|
||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ int main(Platform::Array<Platform::String^>^)
|
||||||
App::App()
|
App::App()
|
||||||
{
|
{
|
||||||
//This does not work... need to fix this.
|
//This does not work... need to fix this.
|
||||||
SetConfigFlags(FLAG_SHOW_LOGO);
|
SetConfigFlags(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int posX = 100;
|
static int posX = 100;
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,16 @@ public:
|
||||||
|
|
||||||
virtual void Run()
|
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)
|
while (!mWindowClosed)
|
||||||
{
|
{
|
||||||
if (mWindowVisible)
|
if (mWindowVisible)
|
||||||
|
|
@ -285,7 +295,12 @@ protected:
|
||||||
void OnResuming(Platform::Object^ sender, Platform::Object^ args) {}
|
void OnResuming(Platform::Object^ sender, Platform::Object^ args) {}
|
||||||
|
|
||||||
// Window event handlers.
|
// 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)
|
void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args)
|
||||||
{
|
{
|
||||||
|
|
@ -416,8 +431,8 @@ private:
|
||||||
bool mWindowClosed = false;
|
bool mWindowClosed = false;
|
||||||
bool mWindowVisible = true;
|
bool mWindowVisible = true;
|
||||||
|
|
||||||
int width = 800;
|
int width = 640;
|
||||||
int height = 450;
|
int height = 480;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Application source for creating the program
|
//Application source for creating the program
|
||||||
|
|
|
||||||
50
src/core.c
50
src/core.c
|
|
@ -626,13 +626,11 @@ void InitWindow(int width, int height, const char *title)
|
||||||
mousePosition.y = (float)screenHeight/2.0f;
|
mousePosition.y = (float)screenHeight/2.0f;
|
||||||
|
|
||||||
// raylib logo appearing animation (if enabled)
|
// raylib logo appearing animation (if enabled)
|
||||||
#if !defined(PLATFORM_UWP)
|
|
||||||
if (showLogo)
|
if (showLogo)
|
||||||
{
|
{
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
LogoAnimation();
|
LogoAnimation();
|
||||||
}
|
}
|
||||||
#endif //defined(PLATFORM_UWP)
|
|
||||||
#endif // defined(PLATFORM_ANDROID)
|
#endif // defined(PLATFORM_ANDROID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -887,7 +885,6 @@ int GetScreenHeight(void)
|
||||||
// Get native window handle
|
// Get native window handle
|
||||||
void *GetWindowHandle(void)
|
void *GetWindowHandle(void)
|
||||||
{
|
{
|
||||||
//TODO: See if we can do UWP?
|
|
||||||
#ifdef PLATFORM_DESKTOP
|
#ifdef PLATFORM_DESKTOP
|
||||||
// NOTE: Returned handle is: void *HWND (windows.h)
|
// NOTE: Returned handle is: void *HWND (windows.h)
|
||||||
return glfwGetWin32Window(window);
|
return glfwGetWin32Window(window);
|
||||||
|
|
@ -2764,6 +2761,8 @@ static bool InitGraphicsDevice(int width, int height)
|
||||||
eglQuerySurface(display, surface, EGL_WIDTH, &screenWidth);
|
eglQuerySurface(display, surface, EGL_WIDTH, &screenWidth);
|
||||||
eglQuerySurface(display, surface, EGL_HEIGHT, &screenHeight);
|
eglQuerySurface(display, surface, EGL_HEIGHT, &screenHeight);
|
||||||
|
|
||||||
|
//SetupFramebuffer(displayWidth, displayHeight); //Borked
|
||||||
|
|
||||||
#else // PLATFORM_ANDROID, PLATFORM_RPI
|
#else // PLATFORM_ANDROID, PLATFORM_RPI
|
||||||
EGLint numConfigs;
|
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);
|
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
|
// Downscaling to fit display with border-bars
|
||||||
float widthRatio = (float)displayWidth/(float)screenWidth;
|
float widthRatio = (float)displayWidth / (float)screenWidth;
|
||||||
float heightRatio = (float)displayHeight/(float)screenHeight;
|
float heightRatio = (float)displayHeight / (float)screenHeight;
|
||||||
|
|
||||||
if (widthRatio <= heightRatio)
|
if (widthRatio <= heightRatio)
|
||||||
{
|
{
|
||||||
|
|
@ -2953,7 +2952,7 @@ static void SetupFramebuffer(int width, int height)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Screen scaling required
|
// Screen scaling required
|
||||||
float scaleRatio = (float)renderWidth/(float)screenWidth;
|
float scaleRatio = (float)renderWidth / (float)screenWidth;
|
||||||
screenScaling = MatrixScale(scaleRatio, scaleRatio, scaleRatio);
|
screenScaling = MatrixScale(scaleRatio, scaleRatio, scaleRatio);
|
||||||
|
|
||||||
// NOTE: We render to full display resolution!
|
// 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);
|
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
|
// Upscaling to fit display with border-bars
|
||||||
float displayRatio = (float)displayWidth/(float)displayHeight;
|
float displayRatio = (float)displayWidth / (float)displayHeight;
|
||||||
float screenRatio = (float)screenWidth/(float)screenHeight;
|
float screenRatio = (float)screenWidth / (float)screenHeight;
|
||||||
|
|
||||||
if (displayRatio <= screenRatio)
|
if (displayRatio <= screenRatio)
|
||||||
{
|
{
|
||||||
renderWidth = screenWidth;
|
renderWidth = screenWidth;
|
||||||
renderHeight = (int)round((float)screenWidth/displayRatio);
|
renderHeight = (int)round((float)screenWidth / displayRatio);
|
||||||
renderOffsetX = 0;
|
renderOffsetX = 0;
|
||||||
renderOffsetY = (renderHeight - screenHeight);
|
renderOffsetY = (renderHeight - screenHeight);
|
||||||
}
|
}
|
||||||
|
|
@ -3263,6 +3262,39 @@ static void PollInputEvents(void)
|
||||||
break;
|
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
|
DeleteUWPMessage(msg); //Delete, we are done
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,8 @@ typedef enum
|
||||||
MarkGamepadActive, //Int0 (gamepad), Bool0 (active or not)
|
MarkGamepadActive, //Int0 (gamepad), Bool0 (active or not)
|
||||||
MarkGamepadButton, //Int0 (gamepad), Int1 (button), Char0 (status)
|
MarkGamepadButton, //Int0 (gamepad), Int1 (button), Char0 (status)
|
||||||
MarkGamepadAxis, //Int0 (gamepad), int1 (axis), Float0 (value)
|
MarkGamepadAxis, //Int0 (gamepad), int1 (axis), Float0 (value)
|
||||||
|
SetDisplayDims, //Vector0 (display dimensions)
|
||||||
|
HandleResize, //Vector0 (new dimensions) - Onresized event
|
||||||
} UWPMessageType;
|
} UWPMessageType;
|
||||||
|
|
||||||
typedef struct UWPMessage {
|
typedef struct UWPMessage {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user