Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / client / src / main_loop_temp.cpp
blobd7da4f1258981aaf65c9416bc8630d5656030acb
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013-2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdpch.h"
21 #include "main_loop_temp.h"
23 #include "global.h"
25 // tempDumpValidPolys
26 #include <nel/gui/interface_element.h>
27 #include <nel/gui/ctrl_polygon.h>
28 #include "interface_v3/interface_manager.h"
30 // tempDumpColPolys
31 #include <nel/3d/packed_world.h>
32 #include "r2/editor.h"
33 #include "user_entity.h"
34 #include <nel/3d/driver_user.h>
36 using namespace NLMISC;
37 using namespace NL3D;
39 // ********************************************************************
40 // ********************************************************************
41 // ********************************************************************
42 // ********************************************************************
43 // ********************************************************************
45 // TMP TMP
46 void tempDumpValidPolys()
48 struct CPolyDisp : public CInterfaceElementVisitor
50 virtual void visitCtrl(CCtrlBase *ctrl)
52 CCtrlPolygon *cp = dynamic_cast<CCtrlPolygon *>(ctrl);
53 if (cp)
55 sint32 cornerX, cornerY;
56 cp->getParent()->getCorner(cornerX, cornerY, cp->getParentPosRef());
57 for(sint32 y = 0; y < (sint32) Screen.getHeight(); ++y)
59 for(sint32 x = 0; x < (sint32) Screen.getWidth(); ++x)
61 if (cp->contains(CVector2f((float) (x - cornerX), (float) (y - cornerY))))
63 ((CRGBA *) &Screen.getPixels()[0])[x + (Screen.getHeight() - 1 - y) * Screen.getWidth()] = CRGBA::Magenta;
69 CBitmap Screen;
70 } polyDisp;
71 Driver->getBuffer(polyDisp.Screen);
72 CInterfaceManager::getInstance()->visit(&polyDisp);
73 COFile output("poly.tga");
74 polyDisp.Screen.writeTGA(output);
77 // ********************************************************************
78 // ********************************************************************
79 // ********************************************************************
80 // ********************************************************************
81 // ********************************************************************
83 // TMP TMP
84 static void viewportToScissor(const CViewport &vp, CScissor &scissor)
86 scissor.X = vp.getX();
87 scissor.Y = vp.getY();
88 scissor.Width = vp.getWidth();
89 scissor.Height = vp.getHeight();
92 // TMP TMP
93 void tempDumpColPolys()
95 CPackedWorld *pw = R2::getEditor().getIslandCollision().getPackedIsland();
96 if (pw)
98 static CMaterial material;
99 static CMaterial wiredMaterial;
100 static CMaterial texturedMaterial;
101 static CVertexBuffer vb;
102 static bool initDone = false;
103 if (!initDone)
105 vb.setVertexFormat(CVertexBuffer::PositionFlag);
106 vb.setPreferredMemory(CVertexBuffer::AGPVolatile, false);
107 material.initUnlit();
108 material.setDoubleSided(true);
109 material.setZFunc(CMaterial::lessequal);
110 wiredMaterial.initUnlit();
111 wiredMaterial.setDoubleSided(true);
112 wiredMaterial.setZFunc(CMaterial::lessequal);
113 wiredMaterial.setColor(CRGBA(255, 255, 255, 250));
114 wiredMaterial.texEnvOpAlpha(0, CMaterial::Replace);
115 wiredMaterial.texEnvArg0Alpha(0, CMaterial::Diffuse, CMaterial::SrcAlpha);
116 wiredMaterial.setBlend(true);
117 wiredMaterial.setBlendFunc(CMaterial::srcalpha, CMaterial::invsrcalpha);
118 texturedMaterial.initUnlit();
119 texturedMaterial.setDoubleSided(true);
120 texturedMaterial.setZFunc(CMaterial::lessequal);
121 initDone = true;
123 // just add a projected texture
124 R2::getEditor().getIslandCollision().loadEntryPoints();
125 R2::CScenarioEntryPoints &sep = R2::CScenarioEntryPoints::getInstance();
126 CVectorD playerPos = UserEntity->pos();
127 R2::CScenarioEntryPoints::CCompleteIsland *island = sep.getCompleteIslandFromCoords(CVector2f((float) playerPos.x, (float) playerPos.y));
128 static CSString currIsland;
129 if (island && island->Island != currIsland)
131 currIsland = island->Island;
132 CTextureFile *newTex = new CTextureFile(currIsland + "_sp.tga");
133 newTex->setWrapS(ITexture::Clamp);
134 newTex->setWrapT(ITexture::Clamp);
135 texturedMaterial.setTexture(0, newTex);
136 texturedMaterial.texEnvOpRGB(0, CMaterial::Replace);
137 texturedMaterial.texEnvArg0RGB(0, CMaterial::Texture, CMaterial::SrcColor);
138 texturedMaterial.setTexCoordGen(0, true);
139 texturedMaterial.setTexCoordGenMode(0, CMaterial::TexCoordGenObjectSpace);
140 CMatrix mat;
141 CVector scale((float) (island->XMax - island->XMin),
142 (float) (island->YMax - island->YMin), 0.f);
143 scale.x = 1.f / favoid0(scale.x);
144 scale.y = 1.f / favoid0(scale.y);
145 scale.z = 0.f;
146 mat.setScale(scale);
147 mat.setPos(CVector(- island->XMin * scale.x, - island->YMin * scale.y, 0.f));
149 CMatrix uvScaleMat;
151 uint texWidth = (uint) (island->XMax - island->XMin);
152 uint texHeight = (uint) (island->YMax - island->YMin);
153 float UScale = (float) texWidth / raiseToNextPowerOf2(texWidth);
154 float VScale = (float) texHeight / raiseToNextPowerOf2(texHeight);
156 uvScaleMat.setScale(CVector(UScale, - VScale, 0.f));
157 uvScaleMat.setPos(CVector(0.f, VScale, 0.f));
159 texturedMaterial.enableUserTexMat(0, true);
160 texturedMaterial.setUserTexMat(0, uvScaleMat * mat);
162 const CFrustum &frust = MainCam.getFrustum();
165 IDriver *driver = ((CDriverUser *) Driver)->getDriver();
167 driver->enableFog(true);
168 const CRGBA clearColor = CRGBA(0, 0, 127, 0);
169 driver->setupFog(frust.Far * 0.8f, frust.Far, clearColor);
170 CViewport vp;
171 vp.init(0.f, 0.f, 1.f, 1.f);
172 driver->setupViewport(vp);
173 CScissor scissor;
174 viewportToScissor(vp, scissor);
175 driver->setupScissor(scissor);
177 driver->setFrustum(frust.Left, frust.Right, frust.Bottom, frust.Top, frust.Near, frust.Far, frust.Perspective);
178 driver->setupViewMatrix(MainCam.getMatrix().inverted());
179 driver->setupModelMatrix(CMatrix::Identity);
182 const CVector localFrustCorners[8] =
184 CVector(frust.Left, frust.Near, frust.Top),
185 CVector(frust.Right, frust.Near, frust.Top),
186 CVector(frust.Right, frust.Near, frust.Bottom),
187 CVector(frust.Left, frust.Near, frust.Bottom),
188 CVector(frust.Left * frust.Far / frust.Near, frust.Far, frust.Top * frust.Far / frust.Near),
189 CVector(frust.Right * frust.Far / frust.Near, frust.Far, frust.Top * frust.Far / frust.Near),
190 CVector(frust.Right * frust.Far / frust.Near, frust.Far, frust.Bottom * frust.Far / frust.Near),
191 CVector(frust.Left * frust.Far / frust.Near, frust.Far, frust.Bottom * frust.Far / frust.Near)
193 // roughly compute covered zones
196 sint frustZoneMinX = INT_MAX;
197 sint frustZoneMaxX = INT_MIN;
198 sint frustZoneMinY = INT_MAX;
199 sint frustZoneMaxY = INT_MIN;
200 for(uint k = 0; k < sizeofarray(localFrustCorners); ++k)
202 CVector corner = camMat * localFrustCorners[k];
203 sint zoneX = (sint) (corner.x / 160.f) - zoneMinX;
204 sint zoneY = (sint) floorf(corner.y / 160.f) - zoneMinY;
205 frustZoneMinX = std::min(frustZoneMinX, zoneX);
206 frustZoneMinY = std::min(frustZoneMinY, zoneY);
207 frustZoneMaxX = std::max(frustZoneMaxX, zoneX);
208 frustZoneMaxY = std::max(frustZoneMaxY, zoneY);
212 const uint TRI_BATCH_SIZE = 10000; // batch size for rendering
213 static std::vector<TPackedZoneBaseSPtr> zones;
214 zones.clear();
215 pw->getZones(zones);
216 for(uint k = 0; k < zones.size(); ++k)
218 zones[k]->render(vb, *driver, texturedMaterial, wiredMaterial, MainCam.getMatrix(), TRI_BATCH_SIZE, localFrustCorners);
223 // ********************************************************************
224 // ********************************************************************
225 // ********************************************************************
226 // ********************************************************************
227 // ********************************************************************
229 /* end of file */