diff --git a/Makefile b/Makefile index 5e27ea3d98eab4c90190d984dcf7fe046945b2f7..c54673d896b99be748b44d2d586ee38c0a249ea1 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ BOINC_PREFIX ?= /home/oliver/development/aei/boinc CXX ?= g++ # variables -LIBS = -L${BOINC_PREFIX}/lib -Bstatic $(shell sdl-config --static-libs) -lfreetype -lftgl -lOGLFT -lboinc_api -lboinc -Wl,-Bdynamic -lGL -lGLU -CPPFLAGS = -DOGLFT_NO_SOLID -DOGLFT_NO_QT -I/usr/include $(shell sdl-config --cflags) $(shell pkg-config --cflags ftgl) -I${BOINC_PREFIX}/include/BOINC +LIBS = -L${BOINC_PREFIX}/lib -Bstatic $(shell sdl-config --static-libs) -lfreetype -lOGLFT -lboinc_api -lboinc -Wl,-Bdynamic -lGL -lGLU +CPPFLAGS = -DOGLFT_NO_SOLID -DOGLFT_NO_QT -I/usr/include $(shell sdl-config --cflags) -I/usr/include/freetype2 -I${BOINC_PREFIX}/include/BOINC DEPS = Makefile OBJS = starlist.o snr_list.o pulsar_list.o AbstractGraphicsEngine.o GraphicsEngineFactory.o Starsphere.o StarsphereS5R3.o WindowManager.o ${RESOURCESPEC}.o Resource.o ResourceFactory.o BOINCClientAdapter.o EinsteinS5R3Adapter.o DEBUGFLAGSCPP = -pg -ggdb -O0 diff --git a/Starsphere.cpp b/Starsphere.cpp index 4f494ef760d501176f9e05c0c32f59b5e38aac10..63ec9bc371f1fb346d5caa76f63a312ea0bff154 100644 --- a/Starsphere.cpp +++ b/Starsphere.cpp @@ -30,20 +30,14 @@ Starsphere::Starsphere() : AbstractGraphicsEngine() m_CurrentRightAscension = -1.0; m_CurrentDeclination = -1.0; m_RefreshSearchMarker = true; - - m_XStartPosLeft = 0.008; - m_YStartPosTop = 0.975; - m_FontScaleLarge = 0.0225; - m_FontScaleMedium = 0.0131; - m_FontScaleSmall = 0.0131; - m_YOffsetLarge = 0.015; - m_YOffsetMedium = 0.015; } Starsphere::~Starsphere() { - if(m_PolygonFont) delete m_PolygonFont; - if(face) delete face; + if(m_FontLogo1) delete m_FontLogo1; + if(m_FontLogo2) delete m_FontLogo2; + if(m_FontHeader) delete m_FontHeader; + if(m_FontText) delete m_FontText; } /** @@ -499,12 +493,16 @@ void Starsphere::make_globe() */ void Starsphere::resize(const int width, const int height) { - + // store current settings + m_CurrentWidth = width; + m_CurrentHeight = height; + aspect = (float)width / (float)height; + + // adjust HUD config + m_YStartPosTop = height - 25; + /* Adjust aspect ratio and projection */ glViewport(0, 0, (GLsizei) width, (GLsizei) height); - - aspect = (float)width / (float)height; - glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(95.0, aspect, 0.50, 25.0); @@ -522,25 +520,48 @@ void Starsphere::initialize(const int width, const int height, const Resource *f // setup initial dimensions resize(width, height); - // create font instance using font resource (base address + size) - m_PolygonFont = new FTGLPolygonFont(&font->data()->at(0), font->data()->size()); + // create large font instances using font resource (base address + size) + m_FontLogo1 = new OGLFT::TranslucentTexture(&font->data()->at(0), font->data()->size(), 24, 72 ); + if ( m_FontLogo1 == 0 || !m_FontLogo1->isValid() ) { + cerr << "Could not construct logo1 font face from in memory resource!" << endl; + return; + } + m_FontLogo1->setForegroundColor(1.0, 1.0, 0.0, 1.0); + + // create medium font instances using font resource (base address + size) + m_FontLogo2 = new OGLFT::TranslucentTexture(&font->data()->at(0), font->data()->size(), 13, 78 ); + if ( m_FontLogo2 == 0 || !m_FontLogo2->isValid() ) { + cerr << "Could not construct logo2 font face from in memory resource!" << endl; + return; + } + m_FontLogo2->setForegroundColor(0.75, 0.75, 0.75, 1.0); - face = new OGLFT::TranslucentTexture( "LiberationSans-Regular.ttf", 17, 100 ); -// face = new OGLFT::Outline(&font->data()->at(0), font->data()->size(), 6, 72 ); - if ( face == 0 || !face->isValid() ) { - cerr << "Could not construct face" << endl; + // create medium font instances using font resource (base address + size) + m_FontHeader = new OGLFT::TranslucentTexture(&font->data()->at(0), font->data()->size(), 13, 78 ); + if ( m_FontHeader == 0 || !m_FontHeader->isValid() ) { + cerr << "Could not construct header font face from in memory resource!" << endl; + return; } + m_FontHeader->setForegroundColor(1.0, 1.0, 0.0, 1.0); + + // create small font instances using font resource (base address + size) + m_FontText = new OGLFT::TranslucentTexture(&font->data()->at(0), font->data()->size(), 11, 72 ); + if ( m_FontText == 0 || !m_FontText->isValid() ) { + cerr << "Could not construct text font face from in memory resource!" << endl; + return; + } + m_FontText->setForegroundColor(0.75, 0.75, 0.75, 1.0); + + // more font setup and optimizations + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); #if defined( GL_RASTER_POSITION_UNCLIPPED_IBM ) glEnable( GL_RASTER_POSITION_UNCLIPPED_IBM ); #endif - glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); - face->setForegroundColor( 1.0, 1.0, 0.0, 1.0 ); -// face->setBackgroundColor( 0.0, 0.0, 0.0, 0.0 ); - m_PolygonFont->CharMap(ft_encoding_unicode); -// m_PolygonFont->Depth(0.05); - m_PolygonFont->FaceSize(1); - + // inital HUD offset setup + m_XStartPosLeft = 5; + m_YOffsetLarge = 18; + // Drawing setup: glClearColor(0.0, 0.0, 0.0, 0.0); // background is black glEnable(GL_CULL_FACE); @@ -704,39 +725,21 @@ void Starsphere::render(const double timeOfDay) // disable depth testing since we're in 2D mode glDisable(GL_DEPTH_TEST); - // enable FSAA - glEnable(GL_MULTISAMPLE_ARB); + // enable textured fonts + glEnable(GL_TEXTURE_2D); // save current state glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - glOrtho(0, 1 * aspect, 0, 1, -1, 1); + glOrtho(0, m_CurrentWidth, 0, m_CurrentHeight, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); if (isFeature(LOGO)) { - glPushMatrix(); - - glColor3f(1.0, 1.0, 0.0); - glTranslatef(m_XStartPosLeft, m_YStartPosTop, 0); -// glScalef(fontScaleLarge, fontScaleLarge, 1.0); - glScalef(0.001, 0.001, 1.0); -// m_PolygonFont->Render("Einstein@Home"); - glEnable( GL_TEXTURE_2D ); - glEnable(GL_DEPTH_TEST); - face->draw(0.0, -10.0, "Einstein@Home"); - glDisable(GL_DEPTH_TEST); - glDisable( GL_TEXTURE_2D ); - - glLoadIdentity(); - glColor4f(1.0, 1.0, 1.0, 0.5); - glTranslatef(m_XStartPosLeft, m_YStartPosTop - m_YOffsetLarge, 0); - glScalef(m_FontScaleMedium, m_FontScaleMedium, 1.0); - m_PolygonFont->Render("World Year of Physics 2005"); - - glPopMatrix(); + m_FontLogo1->draw(m_XStartPosLeft, m_YStartPosTop, "Einstein@Home"); + m_FontLogo2->draw(m_XStartPosLeft, m_YStartPosTop - m_YOffsetLarge, "World Year of Physics 2005"); } if (isFeature(SEARCHINFO)) { @@ -749,8 +752,8 @@ void Starsphere::render(const double timeOfDay) glMatrixMode(GL_MODELVIEW); glPopMatrix(); - // disable FSAA - glDisable(GL_MULTISAMPLE_ARB); + // disable font textures + glDisable(GL_TEXTURE_2D); // enable depth testing since we're leaving 2D mode glEnable(GL_DEPTH_TEST); diff --git a/Starsphere.h b/Starsphere.h index 0822f18e89b61526056d60bc6259a409dd6a97c9..d3a7d97005d06626f0416af48dbda66d0a0b5833 100644 --- a/Starsphere.h +++ b/Starsphere.h @@ -11,7 +11,6 @@ #include <SDL.h> #include <SDL_opengl.h> -#include <FTGLPolygonFont.h> #include <oglft/OGLFT.h> @@ -42,8 +41,8 @@ public: virtual ~Starsphere(); // core methods - void initialize(const int width, const int height, const Resource *font); - void resize(const int width, const int height); + virtual void initialize(const int width, const int height, const Resource *font); + virtual void resize(const int width, const int height); void render(const double timeOfDay); // event handling @@ -62,20 +61,20 @@ protected: // resource handling - FTFont *m_PolygonFont; - OGLFT::TranslucentTexture* face; + OGLFT::TranslucentTexture* m_FontLogo1; + OGLFT::TranslucentTexture* m_FontLogo2; + OGLFT::TranslucentTexture* m_FontHeader; + OGLFT::TranslucentTexture* m_FontText; // Graphics state info: + int m_CurrentWidth; + int m_CurrentHeight; float aspect; // HUD text rendering config (maybe overridden in subclasses) GLfloat m_XStartPosLeft; GLfloat m_YStartPosTop; - GLfloat m_FontScaleLarge; - GLfloat m_FontScaleMedium; - GLfloat m_FontScaleSmall; GLfloat m_YOffsetLarge; - GLfloat m_YOffsetMedium; // local HUD contents string m_UserName; diff --git a/StarsphereS5R3.cpp b/StarsphereS5R3.cpp index aa97f14555e768433e795be10414009a63026441..c93bed2e9bbfddecaa1a11bc2b11e3d6fc764cb5 100644 --- a/StarsphereS5R3.cpp +++ b/StarsphereS5R3.cpp @@ -1,14 +1,35 @@ #include "StarsphereS5R3.h" -StarsphereS5R3::StarsphereS5R3() : m_EinsteinAdapter(&m_BoincAdapter) +StarsphereS5R3::StarsphereS5R3() : Starsphere(), m_EinsteinAdapter(&m_BoincAdapter) { - m_YStartPosBottom = 0.07; } StarsphereS5R3::~StarsphereS5R3() { } +void StarsphereS5R3::initialize(const int width, const int height, const Resource *font) +{ + Starsphere::initialize(width, height, font); + + // adjust HUD config + m_YOffsetMedium = 15; + m_XStartPosRight = width - 125; + m_YStartPosBottom = 70; + m_Y1StartPosBottom = m_YStartPosBottom - m_YOffsetMedium; + m_Y2StartPosBottom = m_Y1StartPosBottom - m_YOffsetMedium; + m_Y3StartPosBottom = m_Y2StartPosBottom - m_YOffsetMedium; + m_Y4StartPosBottom = m_Y3StartPosBottom - m_YOffsetMedium; +} + +void StarsphereS5R3::resize(const int width, const int height) +{ + Starsphere::resize(width, height); + + // adjust HUD config + m_XStartPosRight = width - 125; +} + void StarsphereS5R3::refreshBOINCInformation() { Starsphere::refreshBOINCInformation(); @@ -57,67 +78,17 @@ void StarsphereS5R3::refreshBOINCInformation() void StarsphereS5R3::renderSearchInformation() { - m_XStartPosRight = 1 * aspect - 0.145; - // left info block - glPushMatrix(); - - glColor3f(1.0, 1.0, 0.0); - glTranslatef(m_XStartPosLeft, m_YStartPosBottom, 0); - glScalef(m_FontScaleMedium, m_FontScaleMedium, 1.0); - m_PolygonFont->Render("BOINC Statistics"); - - glLoadIdentity(); - glColor4f(1.0, 1.0, 1.0, 0.5); - glTranslatef(m_XStartPosLeft, m_YStartPosBottom - m_YOffsetMedium, 0); - glScalef(m_FontScaleSmall, m_FontScaleSmall, 1.0); - m_PolygonFont->Render(m_UserName.c_str()); - - glLoadIdentity(); - glTranslatef(m_XStartPosLeft, m_YStartPosBottom - 2*m_YOffsetMedium, 0); - glScalef(m_FontScaleSmall, m_FontScaleSmall, 1.0); - m_PolygonFont->Render(m_TeamName.c_str()); - - glLoadIdentity(); - glTranslatef(m_XStartPosLeft, m_YStartPosBottom - 3*m_YOffsetMedium, 0); - glScalef(m_FontScaleSmall, m_FontScaleSmall, 1.0); - m_PolygonFont->Render(m_UserCredit.c_str()); - - glLoadIdentity(); - glTranslatef(m_XStartPosLeft, m_YStartPosBottom - 4*m_YOffsetMedium, 0); - glScalef(m_FontScaleSmall, m_FontScaleSmall, 1.0); - m_PolygonFont->Render(m_UserRACredit.c_str()); + m_FontHeader->draw(m_XStartPosLeft, m_YStartPosBottom, "BOINC Statistics"); + m_FontText->draw(m_XStartPosLeft, m_Y1StartPosBottom, m_UserName.c_str()); + m_FontText->draw(m_XStartPosLeft, m_Y2StartPosBottom, m_TeamName.c_str()); + m_FontText->draw(m_XStartPosLeft, m_Y3StartPosBottom, m_UserCredit.c_str()); + m_FontText->draw(m_XStartPosLeft, m_Y4StartPosBottom, m_UserRACredit.c_str()); - glPopMatrix(); - // right info block - glPushMatrix(); - - glColor3f(1.0, 1.0, 0.0); - glTranslatef(m_XStartPosRight, m_YStartPosBottom, 0); - glScalef(m_FontScaleMedium, m_FontScaleMedium, 1.0); - m_PolygonFont->Render("Search Information"); - - glLoadIdentity(); - glColor4f(1.0, 1.0, 1.0, 0.5); - glTranslatef(m_XStartPosRight, m_YStartPosBottom - m_YOffsetMedium, 0); - glScalef(m_FontScaleSmall, m_FontScaleSmall, 1.0); - m_PolygonFont->Render(m_WUSkyPosRightAscension.c_str()); - - glLoadIdentity(); - glTranslatef(m_XStartPosRight, m_YStartPosBottom - 2*m_YOffsetMedium, 0); - glScalef(m_FontScaleSmall, m_FontScaleSmall, 1.0); - m_PolygonFont->Render(m_WUSkyPosDeclination.c_str()); - - glLoadIdentity(); - glTranslatef(m_XStartPosRight, m_YStartPosBottom - 3*m_YOffsetMedium, 0); - glScalef(m_FontScaleSmall, m_FontScaleSmall, 1.0); - m_PolygonFont->Render(m_WUPercentDone.c_str()); - - glLoadIdentity(); - glTranslatef(m_XStartPosRight, m_YStartPosBottom - 4*m_YOffsetMedium, 0); - glScalef(m_FontScaleSmall, m_FontScaleSmall, 1.0); - m_PolygonFont->Render(m_WUCPUTime.c_str()); - - glPopMatrix(); + m_FontHeader->draw(m_XStartPosRight, m_YStartPosBottom, "Search Information"); + m_FontText->draw(m_XStartPosRight, m_Y1StartPosBottom, m_WUSkyPosRightAscension.c_str()); + m_FontText->draw(m_XStartPosRight, m_Y2StartPosBottom, m_WUSkyPosDeclination.c_str()); + m_FontText->draw(m_XStartPosRight, m_Y3StartPosBottom, m_WUPercentDone.c_str()); + m_FontText->draw(m_XStartPosRight, m_Y4StartPosBottom, m_WUCPUTime.c_str()); } diff --git a/StarsphereS5R3.h b/StarsphereS5R3.h index e7e336390d4cdab4d37b0c6dff555e61b038ebae..658d1d0ad94e8fee3d6983722634f7b4caebf4de 100644 --- a/StarsphereS5R3.h +++ b/StarsphereS5R3.h @@ -14,6 +14,8 @@ public: StarsphereS5R3(); virtual ~StarsphereS5R3(); + void initialize(const int width, const int height, const Resource *font); + void resize(const int width, const int height); void refreshBOINCInformation(); private: @@ -26,8 +28,13 @@ private: string m_WUPercentDone; string m_WUCPUTime; + GLfloat m_YOffsetMedium; GLfloat m_XStartPosRight; GLfloat m_YStartPosBottom; + GLfloat m_Y1StartPosBottom; + GLfloat m_Y2StartPosBottom; + GLfloat m_Y3StartPosBottom; + GLfloat m_Y4StartPosBottom; }; #endif /*STARSPHERES5R3_H_*/ diff --git a/WindowManager.cpp b/WindowManager.cpp index a02d89295bf8ccddae5de52237d296cd3c2969b6..06dd790ba197c4b7a70a7220059bfc709f4064bf 100644 --- a/WindowManager.cpp +++ b/WindowManager.cpp @@ -96,11 +96,8 @@ bool WindowManager::initialize(const int width, const int height) //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); //SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); - - // 4x FSAA, might be too heavy for some machines :-) - // TODO: should be controlled with config values (coupled to disabling text rendering?) - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); + //SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); + //SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); // we always start in windowed mode // (starting in fullscreen fails with high CPU load!)