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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#include "System/mmgr.h"
#include "SkyBox.h"
#include "Rendering/GlobalRendering.h"
#include "Rendering/GL/myGL.h"
#include "Rendering/Textures/Bitmap.h"
#include "Game/Camera.h"
#include "Map/MapInfo.h"
#include "Map/ReadMap.h"
#include "System/Exceptions.h"
#include "System/float3.h"
#include "System/Log/ILog.h"
#define LOG_SECTION_SKY_BOX "SkyBox"
LOG_REGISTER_SECTION_GLOBAL(LOG_SECTION_SKY_BOX)
// use the specific section for all LOG*() calls in this source file
#ifdef LOG_SECTION_CURRENT
#undef LOG_SECTION_CURRENT
#endif
#define LOG_SECTION_CURRENT LOG_SECTION_SKY_BOX
CSkyBox::CSkyBox(const std::string& texture)
{
CBitmap btex;
if (!btex.Load(texture)) {
LOG_L(L_WARNING, "could not load skybox texture from file %s",
texture.c_str());
tex = 0;
} else {
tex = btex.CreateTexture(true);
glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
cloudDensity = mapInfo->atmosphere.cloudDensity;
cloudColor = mapInfo->atmosphere.cloudColor;
skyColor = mapInfo->atmosphere.skyColor;
sunColor = mapInfo->atmosphere.sunColor;
fogStart = mapInfo->atmosphere.fogStart;
globalRendering->drawFog = (fogStart <= 0.99f);
}
CSkyBox::~CSkyBox(void)
{
}
void CSkyBox::Draw()
{
glColor3f(1,1,1);
glDisable(GL_FOG);
glDisable(GL_BLEND);
glDepthMask(0);
glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, 1, 0, 1);
GLfloat verts[] = {
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 0.0f
};
float3 texcoords[] = {
-camera->CalcPixelDir( 0, 0),
-camera->CalcPixelDir(globalRendering->viewSizeX, 0),
-camera->CalcPixelDir(globalRendering->viewSizeX, globalRendering->viewSizeY),
-camera->CalcPixelDir( 0, globalRendering->viewSizeY)
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(3, GL_FLOAT, 0, texcoords);
glVertexPointer(2, GL_FLOAT, 0, verts);
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
// glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
glDepthMask(1);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
ISky::SetupFog();
}
|