SkyLine.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <GLEXT/GLState.h>
00022 #include <sky/SkyLine.h>
00023 #include <common/Defines.h>
00024 #include <math.h>
00025 
00026 SkyLine::SkyLine() :
00027         listNo_(0)
00028 {
00029 }
00030 
00031 SkyLine::~SkyLine()
00032 {
00033         clear();
00034 }
00035 
00036 void SkyLine::clear()
00037 {
00038         if (listNo_) glDeleteLists(listNo_, 1);
00039         listNo_ = 0;
00040 }
00041 
00042 void SkyLine::draw(float radius, float radius2, float height)
00043 {
00044         if (listNo_)
00045         {
00046                 glCallList(listNo_);
00047         }
00048         else
00049         {
00050                 glNewList(listNo_ = glGenLists(1), GL_COMPILE_AND_EXECUTE);
00051                         actualDraw(radius, radius2, height);
00052                 glEndList();
00053         }
00054 }
00055 
00056 void SkyLine::actualDraw(float radius, float radius2, float height)
00057 {
00058         GLState state(GLState::TEXTURE_ON | GLState::BLEND_ON | GLState::ALPHATEST_ON);
00059 
00060         glColor3f(1.0f, 1.0f, 1.0);
00061         glBegin(GL_QUAD_STRIP);
00062         for (float a=0.0f; a<=360.0f; a+=360.0f / 12)
00063         {
00064                 float x = sinf(a / 180.0f * PI) * radius;
00065                 float y = cosf(a / 180.0f * PI) * radius2;
00066 
00067                 glTexCoord2f(a / 360.0f, 1.0f);
00068                 glVertex3f(x, y, height);
00069 
00070                 glTexCoord2f(a / 360.0f, 0.0f);
00071                 glVertex3f(x, y, 0.0f);
00072         }
00073         glEnd();
00074 }
00075 

Generated on Mon Feb 16 15:14:47 2009 for Scorched3D by  doxygen 1.5.3