Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / samples / 3d / cegui / NeLDriver.cpp
blobf5b3786707f42a13c3e8303d920433f0a8a73bd4
1 /**
2 * \file NeLDriver.cpp
3 * \date November 2004
4 * \author Matt Raykowski
5 * \author Henri Kuuste
6 */
8 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
9 // Copyright (C) 2010 Winch Gate Property Limited
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU Affero General Public License as
13 // published by the Free Software Foundation, either version 3 of the
14 // License, or (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Affero General Public License for more details.
21 // You should have received a copy of the GNU Affero General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "globals.h"
25 #include "resource.h"
26 #include "NeLDriver.h"
28 #include <CEGUIExceptions.h>
30 #ifdef NL_OS_WINDOWS
31 # include <windows.h>
32 # undef min
33 # undef max
34 #endif
36 int frame = 0;
38 void NeLDriver::init() {
39 #ifdef NL_OS_WINDOWS
40 HWND hWnd = (HWND )m_Driver->getDisplay();
41 SetWindowText(hWnd,"CEGUI NeL Demo");
42 #endif
44 // Create the window with config file values
45 if (!m_Driver->setDisplay(NL3D::UDriver::CMode(800, 600, 32, true, 0))) {
46 nlwarning ("Can't set display mode %d %d %d %d %d", 800, 600, 32, false, 0);
47 return;
49 m_Driver->setFontManagerMaxMemory(2000000);
50 m_TextContext = m_Driver->createTextContext(NLMISC::CPath::lookup("n019003l.pfb"));
51 if(m_TextContext == 0) {
52 nlwarning("Can't create text context");
53 return;
55 m_TextContext->setKeep800x600Ratio(false);
56 m_Driver->setAmbientColor(NLMISC::CRGBA(82, 100, 133, 255));
57 m_Driver->enableFog(false);
58 m_Scene = m_Driver->createScene(false);
59 if(m_Scene == 0) {
60 nlwarning("Can't create a NeL UScene");
61 return;
63 m_Scene->getCam().setPerspective(NLMISC::degToRad(90.0f), 1.33f, 1.0f*GScale, 30000.0f*GScale);
64 m_Scene->getCam().setTransformMode(NL3D::UTransformable::DirectMatrix);
65 m_Scene->enableLightingSystem(true);
66 m_Scene->setSunAmbient(NLMISC::CRGBA(82, 100, 133, 255));
67 m_Scene->setSunDiffuse(NLMISC::CRGBA(255,255,255));
68 m_Scene->setSunSpecular(NLMISC::CRGBA(255,255,255));
69 m_Scene->setSunDirection(NLMISC::CVector(-1,0,-1));
71 m_Scene->setPolygonBalancingMode(NL3D::UScene::PolygonBalancingOn);
72 m_Scene->setGroupLoadMaxPolygon("Fx", 5000);
74 // INITIALIZE TIMES
75 m_FirstTime = NLMISC::CTime::ticksToSecond(NLMISC::CTime::getPerformanceTime());
76 m_OldTime = NLMISC::CTime::ticksToSecond(NLMISC::CTime::getPerformanceTime());
77 m_Time = NLMISC::CTime::ticksToSecond(NLMISC::CTime::getPerformanceTime());
81 void NeLDriver::update() {
82 using namespace NLMISC;
83 H_AUTO(NeLDriver_update);
84 // UPDATE THE TIME.
85 m_OldTime = m_Time;
86 double newTime = NLMISC::CTime::ticksToSecond(NLMISC::CTime::getPerformanceTime());
87 m_Time = newTime - m_FirstTime;
88 m_DeltaTime = m_Time - m_OldTime;
89 m_DeltaTimeSmooth.addValue(m_DeltaTime);
91 // 3D
92 m_Scene->animate(m_Time);
94 // INPUT
95 m_Driver->EventServer.pump();
98 double NeLDriver::getFps() {
99 return m_DeltaTimeSmooth.getSmoothValue() ? 1.0 / m_DeltaTimeSmooth.getSmoothValue() : 0.0;
102 void NeLDriver::render() {
103 using namespace NLMISC;
104 H_AUTO(NeLDriver_render);
105 m_Scene->render();
108 NL3D::UDriver &NeLDriver::getDriver() const {
109 return *m_Driver;
112 NL3D::UScene &NeLDriver::getScene() const {
113 return *m_Scene;
116 NL3D::UTextContext &NeLDriver::getTextContext() const {
117 return *m_TextContext;