Atmosphere.cpp   Atmosphere.cpp 
skipping to change at line 22 skipping to change at line 22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include <QDebug> #include <QDebug>
#include "GLee.h" #ifdef USE_OPENGL_ES2
#include "GLES2/gl2.h"
#endif
#include <QGLShaderProgram>
#include <QtOpenGL>
#include "Atmosphere.hpp" #include "Atmosphere.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelToneReproducer.hpp" #include "StelToneReproducer.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include "StelFileMgr.hpp"
// Uncomment to try out vertex buffers
//#define USE_VERTEX_BUFFERS 1
inline bool myisnan(double value) inline bool myisnan(double value)
{ {
return value != value; return value != value;
} }
Atmosphere::Atmosphere(void) :viewport(0,0,0,0),skyResolutionY(44), posGrid (NULL), colorGrid(NULL), indices(NULL), Atmosphere::Atmosphere(void) :viewport(0,0,0,0),skyResolutionY(44), posGrid (NULL), colorGrid(NULL), indices(NULL),
averageLuminance(0.f), eclipseFactor(1.), lightPollutionLuminan ce(0) averageLuminance(0.f), eclipseFac tor(1.f), lightPollutionLuminance(0)
{ {
setFadeDuration(3.f); setFadeDuration(3.f);
useShader = StelApp::getInstance().getUseGLShaders();
if (useShader)
{
QString filePath;
try
{
filePath = StelFileMgr::findFile("data/shaders/xyYTo
RGB.glsl");
}
catch (std::runtime_error& e)
{
qFatal("Can't find data/shaders/xyYToRGB.glsl shader
file to load");
}
qDebug() << "Use vertex shader for atmosphere rendering: " <
< filePath;
QGLShader* vShader = new QGLShader(QGLShader::Vertex);
if (!vShader->compileSourceFile(filePath))
{
qWarning() << "Error while compiling shader: " << vS
hader->log();
useShader = false;
}
if (!vShader->log().isEmpty())
{
qWarning() << "Warnings while compiling vertex shade
r: " << vShader->log();
}
QGLShader* fShader = new QGLShader(QGLShader::Fragment);
if (!fShader->compileSourceCode(
"varying mediump vec4 result
SkyColor;\n"
"void main()\n"
"{\n"
" gl_FragColor = resultSk
yColor;\n"
"}"))
{
qWarning() << "Error while compiling fragment shader
: " << fShader->log();
useShader = false;
}
if (!fShader->log().isEmpty())
{
qWarning() << "Warnings while compiling fragment sha
der: " << vShader->log();
}
atmoShaderProgram = new QGLShaderProgram();
atmoShaderProgram->addShader(vShader);
atmoShaderProgram->addShader(fShader);
if (!atmoShaderProgram->link())
{
qWarning() << "Error while linking shader program: "
<< atmoShaderProgram->log();
useShader = false;
}
if (!atmoShaderProgram->log().isEmpty())
{
qWarning() << "Warnings while linking shader: " << a
tmoShaderProgram->log();
}
atmoShaderProgram->bind();
shaderAttribLocations.alphaWaOverAlphaDa = atmoShaderProgram
->uniformLocation("alphaWaOverAlphaDa");
shaderAttribLocations.oneOverGamma = atmoShaderProgram->unif
ormLocation("oneOverGamma");
shaderAttribLocations.term2TimesOneOverMaxdLpOneOverGamma =
atmoShaderProgram->uniformLocation("term2TimesOneOverMaxdLpOneOverGamma");
shaderAttribLocations.brightnessScale = atmoShaderProgram->u
niformLocation("brightnessScale");
shaderAttribLocations.sunPos = atmoShaderProgram->uniformLoc
ation("sunPos");
shaderAttribLocations.term_x = atmoShaderProgram->uniformLoc
ation("term_x");
shaderAttribLocations.Ax = atmoShaderProgram->uniformLocatio
n("Ax");
shaderAttribLocations.Bx = atmoShaderProgram->uniformLocatio
n("Bx");
shaderAttribLocations.Cx = atmoShaderProgram->uniformLocatio
n("Cx");
shaderAttribLocations.Dx = atmoShaderProgram->uniformLocatio
n("Dx");
shaderAttribLocations.Ex = atmoShaderProgram->uniformLocatio
n("Ex");
shaderAttribLocations.term_y = atmoShaderProgram->uniformLoc
ation("term_y");
shaderAttribLocations.Ay = atmoShaderProgram->uniformLocatio
n("Ay");
shaderAttribLocations.By = atmoShaderProgram->uniformLocatio
n("By");
shaderAttribLocations.Cy = atmoShaderProgram->uniformLocatio
n("Cy");
shaderAttribLocations.Dy = atmoShaderProgram->uniformLocatio
n("Dy");
shaderAttribLocations.Ey = atmoShaderProgram->uniformLocatio
n("Ey");
shaderAttribLocations.projectionMatrix = atmoShaderProgram->
uniformLocation("projectionMatrix");
shaderAttribLocations.skyVertex = atmoShaderProgram->attribu
teLocation("skyVertex");
shaderAttribLocations.skyColor = atmoShaderProgram->attribut
eLocation("skyColor");
atmoShaderProgram->release();
}
} }
Atmosphere::~Atmosphere(void) Atmosphere::~Atmosphere(void)
{ {
if (posGrid) if (posGrid)
{ {
delete[] posGrid; delete[] posGrid;
posGrid = NULL; posGrid = NULL;
} }
if (colorGrid) if (colorGrid)
{ {
delete[] colorGrid; delete[] colorGrid;
colorGrid = NULL; colorGrid = NULL;
} }
if (indices) if (indices)
{ {
delete[] indices; delete[] indices;
indices = NULL; indices = NULL;
} }
if (useShader)
{
delete atmoShaderProgram;
}
} }
void Atmosphere::computeColor(double JD, Vec3d _sunPos, Vec3d moonPos, floa t moonPhase, void Atmosphere::computeColor(double JD, Vec3d _sunPos, Vec3d moonPos, floa t moonPhase,
StelCore* core, float latitude, float altitu de, float temperature, float relativeHumidity) StelCore* core, f loat latitude, float altitude, float temperature, float relativeHumidity)
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz) ; const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz) ;
if (viewport != prj->getViewport()) if (viewport != prj->getViewport())
{ {
// The viewport changed: update the number of point of the g rid // The viewport changed: update the number of point of the g rid
viewport = prj->getViewport(); viewport = prj->getViewport();
if (posGrid) if (posGrid)
delete[] posGrid; delete[] posGrid;
if (colorGrid) if (colorGrid)
delete[] colorGrid; delete[] colorGrid;
if (indices) if (indices)
delete[] indices; delete[] indices;
skyResolutionX = (int)floor(0.5+skyResolutionY*(0.5*sqrt(3.0 ))*prj->getViewportWidth()/prj->getViewportHeight()); skyResolutionX = (int)floor(0.5+skyResolutionY*(0.5*sqrt(3.0 ))*prj->getViewportWidth()/prj->getViewportHeight());
posGrid = new Vec2f[(1+skyResolutionX)*(1+skyResolutionY)]; posGrid = new Vec2f[(1+skyResolutionX)*(1+skyResolutionY)];
colorGrid = new Vec3f[(1+skyResolutionX)*(1+skyResolutionY)] ; colorGrid = new Vec4f[(1+skyResolutionX)*(1+skyResolutionY)] ;
float stepX = (float)prj->getViewportWidth() / (skyResolutio nX-0.5); float stepX = (float)prj->getViewportWidth() / (skyResolutio nX-0.5);
float stepY = (float)prj->getViewportHeight() / skyResolutio nY; float stepY = (float)prj->getViewportHeight() / skyResolutio nY;
float viewport_left = (float)prj->getViewportPosX(); float viewport_left = (float)prj->getViewportPosX();
float viewport_bottom = (float)prj->getViewportPosY(); float viewport_bottom = (float)prj->getViewportPosY();
for (int x=0; x<=skyResolutionX; ++x) for (int x=0; x<=skyResolutionX; ++x)
{ {
for(int y=0; y<=skyResolutionY; ++y) for(int y=0; y<=skyResolutionY; ++y)
{ {
Vec2f &v(posGrid[y*(1+skyResolutionX)+x]); Vec2f &v(posGrid[y*(1+skyResolutionX)+x]);
v[0] = viewport_left + ((x == 0) ? 0.f : v[0] = viewport_left + ((x == 0) ? 0.f :
(x == skyResolutionX) ? (flo at)prj->getViewportWidth() : (x-0.5*(y&1))*stepX); (x == skyResolutionX) ? (flo at)prj->getViewportWidth() : (x-0.5*(y&1))*stepX);
v[1] = viewport_bottom+y*stepY; v[1] = viewport_bottom+y*stepY;
} }
} }
// Generate the indices used to draw the quads // Generate the indices used to draw the quads
indices = new GLushort[skyResolutionX*skyResolutionY*4]; indices = new unsigned int[(skyResolutionX+1)*skyResolutionY *2];
int i=0; int i=0;
for (int y2=0; y2<skyResolutionY; ++y2) for (int y2=0; y2<skyResolutionY; ++y2)
{ {
GLushort g0 = y2*(1+skyResolutionX); unsigned int g0 = y2*(1+skyResolutionX);
GLushort g1 = g0; unsigned int g1 = (y2+1)*(1+skyResolutionX);
if (y2&1) for (int x2=0; x2<=skyResolutionX; ++x2)
{ {
g1+=(1+skyResolutionX); indices[i++]=g0++;
} indices[i++]=g1++;
else
{
g0+=(1+skyResolutionX);
}
for (int x2=0; x2<skyResolutionX; ++x2)
{
indices[i++]=g0;
indices[i++]=g1;
indices[i++]=++g1;
indices[i++]=++g0;
} }
} }
#ifdef USE_VERTEX_BUFFERS
// Load the data on the GPU using vertex buffers
glGenBuffersARB(1, &vertexBufferId);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBufferId);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, (1+skyResolutionX)*(1+s
kyResolutionY)*2*sizeof(float), posGrid, GL_STATIC_DRAW_ARB);
glGenBuffersARB(1, &indicesBufferId);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indicesBufferId
);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, skyResolutionX*
skyResolutionY*4*sizeof(GLushort), indices, GL_STATIC_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
#endif
} }
if (myisnan(_sunPos.length())) if (myisnan(_sunPos.length()))
_sunPos.set(0.,0.,-1.*AU); _sunPos.set(0.,0.,-1.*AU);
if (myisnan(moonPos.length())) if (myisnan(moonPos.length()))
moonPos.set(0.,0.,-1.*AU); moonPos.set(0.,0.,-1.*AU);
// Update the eclipse intensity factor to apply on atmosphere model // Update the eclipse intensity factor to apply on atmosphere model
// these are for radii // these are for radii
const double sun_angular_size = atan(696000./AU/_sunPos.length()); const float sun_angular_size = atan(696000.f/AU/_sunPos.length());
const double moon_angular_size = atan(1738./AU/moonPos.length()); const float moon_angular_size = atan(1738.f/AU/moonPos.length());
const double touch_angle = sun_angular_size + moon_angular_size; const float touch_angle = sun_angular_size + moon_angular_size;
// determine luminance falloff during solar eclipses // determine luminance falloff during solar eclipses
_sunPos.normalize(); _sunPos.normalize();
moonPos.normalize(); moonPos.normalize();
double separation_angle = std::acos(_sunPos.dot(moonPos)); // angle between them float separation_angle = std::acos(_sunPos.dot(moonPos)); // angle between them
// qDebug("touch at %f\tnow at %f (%f)\n", touch_angle, separation_a ngle, separation_angle/touch_angle); // qDebug("touch at %f\tnow at %f (%f)\n", touch_angle, separation_a ngle, separation_angle/touch_angle);
// bright stars should be visible at total eclipse // bright stars should be visible at total eclipse
// TODO: correct for atmospheric diffusion // TODO: correct for atmospheric diffusion
// TODO: use better coverage function (non-linear) // TODO: use better coverage function (non-linear)
// because of above issues, this algorithm darkens more quickly than reality // because of above issues, this algorithm darkens more quickly than reality
if( separation_angle < touch_angle) if (separation_angle < touch_angle)
{ {
double dark_angle = moon_angular_size - sun_angular_size; float dark_angle = moon_angular_size - sun_angular_size;
float min; float min = 0.0001f; // so bright stars show up at total ec
if(dark_angle < 0) lipse
if (dark_angle < 0.f)
{ {
// annular eclipse // annular eclipse
float asun = sun_angular_size*sun_angular_size; float asun = sun_angular_size*sun_angular_size;
min = (asun - moon_angular_size*moon_angular_size)/a sun; // minimum proportion of sun uncovered min = (asun - moon_angular_size*moon_angular_size)/a sun; // minimum proportion of sun uncovered
dark_angle *= -1; dark_angle *= -1;
} }
else min = 0.0001; // so bright stars show up at total ecli pse
if (separation_angle < dark_angle) if (separation_angle < dark_angle)
eclipseFactor = min; eclipseFactor = min;
else else
eclipseFactor = min + (1.-min)*(separation_angle-dar k_angle)/(touch_angle-dark_angle); eclipseFactor = min + (1.f-min)*(separation_angle-da rk_angle)/(touch_angle-dark_angle);
} }
else else
eclipseFactor = 1.; eclipseFactor = 1.f;
// No need to calculate if not visible // No need to calculate if not visible
if (!fader.getInterstate()) if (!fader.getInterstate())
{ {
averageLuminance = 0.001 + lightPollutionLuminance; averageLuminance = 0.001f + lightPollutionLuminance;
return; return;
} }
// Calculate the atmosphere RGB for each point of the grid // Calculate the atmosphere RGB for each point of the grid
float sunPos[3]; float sunPos[3];
sunPos[0] = _sunPos[0]; sunPos[0] = _sunPos[0];
sunPos[1] = _sunPos[1]; sunPos[1] = _sunPos[1];
sunPos[2] = _sunPos[2]; sunPos[2] = _sunPos[2];
float moon_pos[3]; float moon_pos[3];
moon_pos[0] = moonPos[0]; moon_pos[0] = moonPos[0];
moon_pos[1] = moonPos[1]; moon_pos[1] = moonPos[1];
moon_pos[2] = moonPos[2]; moon_pos[2] = moonPos[2];
skipping to change at line 207 skipping to change at line 263
skyb.setLocation(latitude * M_PI/180., altitude, temperature, relati veHumidity); skyb.setLocation(latitude * M_PI/180., altitude, temperature, relati veHumidity);
skyb.setSunMoon(moon_pos[2], sunPos[2]); skyb.setSunMoon(moon_pos[2], sunPos[2]);
// Calculate the date from the julian day. // Calculate the date from the julian day.
int year, month, day; int year, month, day;
StelUtils::getDateFromJulianDay(JD, &year, &month, &day); StelUtils::getDateFromJulianDay(JD, &year, &month, &day);
skyb.setDate(year, month, moonPhase); skyb.setDate(year, month, moonPhase);
// Variables used to compute the average sky luminance // Variables used to compute the average sky luminance
double sum_lum = 0.; double sum_lum = 0.;
unsigned int nb_lum = 0;
Vec3d point(1., 0., 0.); Vec3d point(1., 0., 0.);
skylightStruct2 b2; skylightStruct2 b2;
float lumi; float lumi;
// Compute the sky color for every point above the ground // Compute the sky color for every point above the ground
for (int i=0; i<(1+skyResolutionX)*(1+skyResolutionY); ++i) for (int i=0; i<(1+skyResolutionX)*(1+skyResolutionY); ++i)
{ {
Vec2f &v(posGrid[i]); const Vec2f &v(posGrid[i]);
prj->unProject(v[0],v[1],point); prj->unProject(v[0],v[1],point);
Q_ASSERT(fabs(point.lengthSquared()-1.0) < 1e-10); Q_ASSERT(fabs(point.lengthSquared()-1.0) < 1e-10);
if (point[2]<=0) if (point[2]<=0)
{ {
point[2] = -point[2]; point[2] = -point[2];
// The sky below the ground is the symetric of the o ne above : // The sky below the ground is the symmetric of the one above :
// it looks nice and gives proper values for brightn ess estimation // it looks nice and gives proper values for brightn ess estimation
} }
// Use the Skybright.cpp 's models for brightness which give s better results. // Use the Skybright.cpp 's models for brightness which give s better results.
lumi = skyb.getLuminance(moon_pos[0]*point[0]+moon_pos[1]*po int[1]+ lumi = skyb.getLuminance(moon_pos[0]*point[0]+moon_pos[1]*po int[1]+
moon_pos[2]*point[2], sunPos[0]*point[0]+sun Pos[1]*point[1]+ moon_pos[2]*point[2], sunPos[0]*point[0]+sun Pos[1]*point[1]+
sunPos[2]*point[2], point[2]); sunPos[2]*point[2], point[2]);
lumi *= eclipseFactor; lumi *= eclipseFactor;
// Add star background luminance // Add star background luminance
lumi += 0.0001; lumi += 0.0001;
// Multiply by the input scale of the ToneConverter (is not done automatically by the xyYtoRGB method called later) // Multiply by the input scale of the ToneConverter (is not done automatically by the xyYtoRGB method called later)
//lumi*=eye->getInputScale(); //lumi*=eye->getInputScale();
// Add the light pollution luminance AFTER the scaling to av oid scaling it because it is the cause // Add the light pollution luminance AFTER the scaling to av oid scaling it because it is the cause
// of the scaling itself // of the scaling itself
lumi += lightPollutionLuminance; lumi += lightPollutionLuminance;
// Store for later statistics // Store for later statistics
sum_lum+=lumi; sum_lum+=lumi;
++nb_lum;
if (lumi>0.01) // Now need to compute the xy part of the color component
// This can be done in the openGL shader if possible
if (useShader)
{ {
b2.pos[0] = point[0]; // Store the back projected position + luminance in
b2.pos[1] = point[1]; the input color to the shader
b2.pos[2] = point[2]; colorGrid[i].set(point[0], point[1], point[2], lumi)
// Use the Skylight model for the color ;
sky.getxyYValuev(b2);
} }
else else
{ {
// Too dark to see atmosphere color, don't bother co if (lumi>0.01)
mputing it {
b2.color[0]=0.25; b2.pos[0] = point[0];
b2.color[1]=0.25; b2.pos[1] = point[1];
b2.pos[2] = point[2];
// Use the Skylight model for the color
sky.getxyYValuev(b2);
}
else
{
// Too dark to see atmosphere color, don't b
other computing it
b2.color[0]=0.25;
b2.color[1]=0.25;
}
colorGrid[i].set(b2.color[0], b2.color[1], lumi, 1.f
);
} }
colorGrid[i].set(b2.color[0], b2.color[1], lumi);
} }
// Update average luminance // Update average luminance
averageLuminance = sum_lum/nb_lum; averageLuminance = sum_lum/((1+skyResolutionX)*(1+skyResolutionY));
} }
// Draw the atmosphere using the precalc values stored in tab_sky // Draw the atmosphere using the precalc values stored in tab_sky
void Atmosphere::draw(StelCore* core) void Atmosphere::draw(StelCore* core)
{ {
if (StelApp::getInstance().getVisionModeNight()) if (StelApp::getInstance().getVisionModeNight())
return; return;
StelToneReproducer* eye = core->getToneReproducer(); StelToneReproducer* eye = core->getToneReproducer();
if (fader.getInterstate()) if (!fader.getInterstate())
return;
StelPainter sPainter(core->getProjection2d());
glBlendFunc(GL_ONE, GL_ONE);
sPainter.enableTexture2d(false);
glEnable(GL_BLEND);
const float atm_intensity = fader.getInterstate();
if (useShader)
{ {
const float atm_intensity = fader.getInterstate(); atmoShaderProgram->bind();
float a, b, c;
eye->getShadersParams(a, b, c);
atmoShaderProgram->setUniformValue(shaderAttribLocations.alp
haWaOverAlphaDa, a);
atmoShaderProgram->setUniformValue(shaderAttribLocations.one
OverGamma, b);
atmoShaderProgram->setUniformValue(shaderAttribLocations.ter
m2TimesOneOverMaxdLpOneOverGamma, c);
atmoShaderProgram->setUniformValue(shaderAttribLocations.bri
ghtnessScale, atm_intensity);
Vec3f sunPos;
float term_x, Ax, Bx, Cx, Dx, Ex, term_y, Ay, By, Cy, Dy, Ey
;
sky.getShadersParams(sunPos, term_x, Ax, Bx, Cx, Dx, Ex, ter
m_y, Ay, By, Cy, Dy, Ey);
atmoShaderProgram->setUniformValue(shaderAttribLocations.sun
Pos, sunPos[0], sunPos[1], sunPos[2]);
atmoShaderProgram->setUniformValue(shaderAttribLocations.ter
m_x, term_x);
atmoShaderProgram->setUniformValue(shaderAttribLocations.Ax,
Ax);
atmoShaderProgram->setUniformValue(shaderAttribLocations.Bx,
Bx);
atmoShaderProgram->setUniformValue(shaderAttribLocations.Cx,
Cx);
atmoShaderProgram->setUniformValue(shaderAttribLocations.Dx,
Dx);
atmoShaderProgram->setUniformValue(shaderAttribLocations.Ex,
Ex);
atmoShaderProgram->setUniformValue(shaderAttribLocations.ter
m_y, term_y);
atmoShaderProgram->setUniformValue(shaderAttribLocations.Ay,
Ay);
atmoShaderProgram->setUniformValue(shaderAttribLocations.By,
By);
atmoShaderProgram->setUniformValue(shaderAttribLocations.Cy,
Cy);
atmoShaderProgram->setUniformValue(shaderAttribLocations.Dy,
Dy);
atmoShaderProgram->setUniformValue(shaderAttribLocations.Ey,
Ey);
const Mat4f& m = sPainter.getProjector()->getProjectionMatri
x();
atmoShaderProgram->setUniformValue(shaderAttribLocations.pro
jectionMatrix,
QMatrix4x4(m[0], m[4], m[8], m[12], m[1], m[5], m[9]
, m[13], m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]));
atmoShaderProgram->enableAttributeArray(shaderAttribLocation
s.skyVertex);
atmoShaderProgram->enableAttributeArray(shaderAttribLocation
s.skyColor);
atmoShaderProgram->setAttributeArray(shaderAttribLocations.s
kyVertex, (const GLfloat*)posGrid, 2, 0);
atmoShaderProgram->setAttributeArray(shaderAttribLocations.s
kyColor, (const GLfloat*)colorGrid, 4, 0);
// Adapt luminance at this point to avoid a mismatch with th // And draw everything at once
e adaption value unsigned int* shift=indices;
for (int y=0;y<skyResolutionY;++y)
{
glDrawElements(GL_TRIANGLE_STRIP, (skyResolutionX+1)
*2, GL_UNSIGNED_INT, shift);
shift += (skyResolutionX+1)*2;
}
atmoShaderProgram->disableAttributeArray(shaderAttribLocatio
ns.skyVertex);
atmoShaderProgram->disableAttributeArray(shaderAttribLocatio
ns.skyColor);
atmoShaderProgram->release();
}
else
{
// No shader is available on this graphics card, compute col
ors with the CPU
// Adapt luminance at this point to avoid a mismatch with th
e adaptation value
for (int i=0;i<(1+skyResolutionX)*(1+skyResolutionY);++i) for (int i=0;i<(1+skyResolutionX)*(1+skyResolutionY);++i)
{ {
Vec3f& c = colorGrid[i]; Vec4f& c = colorGrid[i];
eye->xyYToRGB(c); eye->xyYToRGB(c);
c*=atm_intensity; c*=atm_intensity;
} }
sPainter.setShadeModel(StelPainter::ShadeModelSmooth);
sPainter.enableClientStates(true, false, true, false);
sPainter.setColorPointer(4, GL_FLOAT, colorGrid);
sPainter.setVertexPointer(2, GL_FLOAT, posGrid);
StelPainter sPainter(core->getProjection2d());
glBlendFunc(GL_ONE, GL_ONE);
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
// Load the color components
glColorPointer(3, GL_FLOAT, 0, colorGrid);
#ifdef USE_VERTEX_BUFFERS
// Bind the vertex and indices buffer
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBufferId);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indicesBufferId
);
glVertexPointer(2, GL_FLOAT, 0, 0);
// And draw everything at once
glDrawElements(GL_QUADS, skyResolutionX*skyResolutionY*4, GL
_UNSIGNED_SHORT, 0);
// Unbind buffers
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
#else
// Load the vertex array
glVertexPointer(2, GL_FLOAT, 0, posGrid);
// And draw everything at once // And draw everything at once
glDrawElements(GL_QUADS, skyResolutionX*skyResolutionY*4, GL unsigned int* shift=indices;
_UNSIGNED_SHORT, indices); for (int y=0;y<skyResolutionY;++y)
#endif {
sPainter.drawFromArray(StelPainter::TriangleStrip, (
glDisableClientState(GL_VERTEX_ARRAY); skyResolutionX+1)*2, 0, false, shift);
glDisableClientState(GL_COLOR_ARRAY); shift += (skyResolutionX+1)*2;
}
glShadeModel(GL_FLAT); sPainter.setShadeModel(StelPainter::ShadeModelFlat);
} }
} }
 End of changes. 36 change blocks. 
110 lines changed or deleted 264 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/