3D Viewport resizing added. (Resizes very smooth!)

This commit is contained in:
MusicalProgrammer
2018-05-30 23:47:01 -04:00
parent a16953c8a0
commit 72954be880

View File

@@ -96,6 +96,7 @@ class Demo : public GApp {
SkyRef sky; SkyRef sky;
bool quit; bool quit;
void main(); void main();
}; };
class App : public GApp { class App : public GApp {
@@ -1453,7 +1454,14 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
app->QuitApp(); app->QuitApp();
break; break;
case WM_SIZE: case WM_SIZE:
{
int winWidth = LOWORD(lParam);
int winHeight = HIWORD(lParam);
app->renderDevice->notifyResize(winWidth,winHeight);
Rect2D viewportRect = Rect2D::xywh(0,0,winWidth,winHeight);
app->renderDevice->setViewport(viewportRect);
app->onGraphics(app->renderDevice);
}
break; break;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
@@ -1466,7 +1474,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return 0; return 0;
} }
void Demo::main() { void Demo::main() {
setDebugMode(true); setDebugMode(true);
debugController.setActive(false); debugController.setActive(false);
@@ -1475,78 +1482,76 @@ void Demo::main() {
fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt")); fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt"));
fntlighttrek = GFont::fromFile(GetFileInPath("/content/font/lighttrek.fnt")); fntlighttrek = GFont::fromFile(GetFileInPath("/content/font/lighttrek.fnt"));
sky = Sky::create(NULL, ExePath() + "/content/sky/"); sky = Sky::create(NULL, ExePath() + "/content/sky/");
//run();
RealTime now, lastTime;
double simTimeRate = 1.0f;
float fps=30.f;
RealTime now, lastTime; RealTime desiredFrameDuration=1.0/fps;
double simTimeRate = 1.0f;
float fps=30.f;
RealTime desiredFrameDuration=1.0/fps;
onInit(); onInit();
RealTime lastWaitTime; RealTime lastWaitTime;
//GWindow* wind = window();
//wind-> MSG messages;
MSG messages; /* Here messages to the application are saved */ RECT cRect;
GetClientRect(hWndMain,&cRect);
renderDevice->notifyResize(cRect.right,cRect.bottom);
Rect2D viewportRect = Rect2D::xywh(0,0,cRect.right,cRect.bottom);
renderDevice->setViewport(viewportRect);
while (!quit) while (!quit)
{ {
lastTime = now; lastTime = now;
now = System::getTick(); now = System::getTick();
RealTime timeStep = now - lastTime; RealTime timeStep = now - lastTime;
m_userInputWatch.tick(); m_userInputWatch.tick();
onUserInput(userInput); onUserInput(userInput);
m_moduleManager->onUserInput(userInput); m_moduleManager->onUserInput(userInput);
m_userInputWatch.tock(); m_userInputWatch.tock();
m_simulationWatch.tick(); m_simulationWatch.tick();
debugController.doSimulation(clamp(timeStep, 0.0, 0.1)); debugController.doSimulation(clamp(timeStep, 0.0, 0.1));
debugCamera.setCoordinateFrame debugCamera.setCoordinateFrame
(debugController.getCoordinateFrame()); (debugController.getCoordinateFrame());
double rate = simTimeRate; double rate = simTimeRate;
RealTime rdt = timeStep; RealTime rdt = timeStep;
SimTime sdt = timeStep * rate; SimTime sdt = timeStep * rate;
SimTime idt = desiredFrameDuration * rate; SimTime idt = desiredFrameDuration * rate;
onSimulation(rdt,sdt,idt); onSimulation(rdt,sdt,idt);
m_simulationWatch.tock(); m_simulationWatch.tock();
m_waitWatch.tick(); m_waitWatch.tick();
{ {
RealTime now = System::time(); RealTime now = System::time();
// Compute accumulated time // Compute accumulated time
System::sleep(max(0.0, desiredFrameDuration - (now - lastWaitTime))); System::sleep(max(0.0, desiredFrameDuration - (now - lastWaitTime)));
//onWait(now - lastWaitTime, desiredFrameDuration);
lastWaitTime = System::time(); lastWaitTime = System::time();
} }
m_waitWatch.tock(); m_waitWatch.tock();
m_graphicsWatch.tick(); m_graphicsWatch.tick();
renderDevice->beginFrame(); renderDevice->beginFrame();
renderDevice->pushState(); renderDevice->pushState();
onGraphics(renderDevice); onGraphics(renderDevice);
renderDevice->popState(); renderDevice->popState();
renderDebugInfo(); renderDebugInfo();
renderDevice->endFrame(); renderDevice->endFrame();
debugText.clear(); debugText.clear();
m_graphicsWatch.tock(); m_graphicsWatch.tock();
while (PeekMessage (&messages, NULL, 0, 0,PM_REMOVE)) while (PeekMessage (&messages, NULL, 0, 0,PM_REMOVE))
{ {
if (IsDialogMessage(hWndMain, &messages) == 0)
if (IsDialogMessage(hWndMain, &messages) == 0) {
{ TranslateMessage(&messages);
/* Translate virtual-key messages into character messages */ DispatchMessage(&messages);
TranslateMessage(&messages); }
/* Send message to WindowProcedure */ }
DispatchMessage(&messages);
}
} }
}
} }
void Demo::QuitApp() void Demo::QuitApp()
@@ -1569,10 +1574,6 @@ int main(int argc, char** argv) {
settings.writeLicenseFile = false; settings.writeLicenseFile = false;
settings.logFilename = tempPath + "/g3dlog.txt"; settings.logFilename = tempPath + "/g3dlog.txt";
settings.window.center = true; settings.window.center = true;
//G3D::SDLWindow* wnd = new SDLWindow(settings.window);
//wnd->setMouseVisible(false);
WNDCLASSEX wc; WNDCLASSEX wc;
HINSTANCE hInstance = GetModuleHandle(NULL); HINSTANCE hInstance = GetModuleHandle(NULL);
@@ -1617,6 +1618,8 @@ int main(int argc, char** argv) {
Win32Window* win32Window = Win32Window::create(settings.window,hwndMain); Win32Window* win32Window = Win32Window::create(settings.window,hwndMain);
Demo demo = Demo(settings,win32Window); Demo demo = Demo(settings,win32Window);
SetWindowLongPtr(hwndMain,GWL_USERDATA,(LONG)&demo);
demo.run(); demo.run();
} }
catch(...) catch(...)