This repository was archived by the owner on Mar 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGraphics.cpp
57 lines (45 loc) · 1.47 KB
/
Graphics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "Graphics.h"
#include "SDL2/SDL_syswm.h"
namespace SouthwestEngine {
// define static variables
// ogre root node
Ogre::Root* Graphics::OgreRoot;
SDL_Window* Graphics::SDLWindow;
Ogre::RenderWindow* Graphics::RenderWindow;
float Graphics::_deltaTime;
float Graphics::_lastTick;
int Graphics::Initialize(const std::string wintitle) {
SDLWindow = SDL_CreateWindow(wintitle.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 960, 540, SDL_WINDOW_RESIZABLE);
SDL_SysWMinfo wmInfo;
SDL_GetVersion(&wmInfo.version);
if (!SDL_GetWindowWMInfo(SDLWindow, &wmInfo))
{
Ogre::LogManager::getSingleton().logMessage(Ogre::String("Couldn't get WM info"));
}
Ogre::String winHandle = Ogre::StringConverter::toString((unsigned long)wmInfo.info.win.window);
Ogre::NameValuePairList params;
params["externalWindowHandle"] = winHandle;
OgreRoot = new Ogre::Root("plugins.cfg", "ogre.cfg", "ogre.log");
if (!OgreRoot->showConfigDialog(nullptr))
return 1;
OgreRoot->initialise(false);
// create main window
RenderWindow = OgreRoot->createRenderWindow(wintitle, 960, 540, false, ¶ms);
_lastTick = SDL_GetTicks();
return 0;
}
void Graphics::Update() {
OgreRoot->renderOneFrame();
_deltaTime = SDL_GetTicks() - _lastTick;
_lastTick = SDL_GetTicks();
}
void Graphics::Stop() {
RenderWindow->destroy();
OgreRoot->shutdown();
// destroy sdl window
SDL_DestroyWindow(SDLWindow);
}
float Graphics::DeltaTime() {
return _deltaTime;
}
}