00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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