diff --git a/asteroids/Model.h b/asteroids/Model.h index f95cda7..40505f3 100644 --- a/asteroids/Model.h +++ b/asteroids/Model.h @@ -89,6 +89,7 @@ class Model : public Engine::ModelBase { } bool GetGameModified() { return mGameModified; } + protected: /** \brief Initializes the system */ virtual int OnInit (int argc, char* argv[]); diff --git a/asteroids/View.cc b/asteroids/View.cc index cb3801f..4b0c36c 100644 --- a/asteroids/View.cc +++ b/asteroids/View.cc @@ -183,6 +183,47 @@ bool View::OnReceiveEvent (const Engine::EventBasePtr &event) { /* * Module specific functions */ +void View::Resize (int width, int height) { + if (height == 0) + height = 1; + + mWindowWidth = static_cast (width); + mWindowHeight = static_cast (height); + + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + float world_width, world_height; + world_width = GetModel()->GetWorldWidth (); + world_height = GetModel()->GetWorldHeight (); + + Engine::LogMessage ("width %f height %f", world_width, world_height); + + glOrtho (- world_width * 0.5, world_width * 0.5, -world_height * 0.5, world_height * 0.5, 0., 100.); +// gluPerspective(mCamera->GetFOVY (), float (width) / float (height), 0., 100); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity (); + + Engine::LogDebug ("Resize to: %d x %d", mWindowWidth,mWindowHeight); + + /** \warning + * This call has to be made for SDL 1.2 for 1.3 there seems to be a + * workaround, however since I do not yet run SDL 1.3 I hold on to this. + * See http://lists.libsdl.org/pipermail/sdl-libsdl.org/2008-November/067306.html + */ + Uint32 video_flags = SDL_OPENGL; + + if (mDrawFullscreen) + video_flags = video_flags | SDL_FULLSCREEN; + + if( SDL_SetVideoMode( mWindowWidth, mWindowHeight, 16, video_flags) == 0 ) { + Engine::LogError ("Video mode set failed: %s", SDL_GetError ()); + exit (-1); + } +} + void View::UpdateCamera () { mCamera->SetEye ( 0., @@ -422,10 +463,10 @@ void View::DrawUi () { ViewState current_view_state = GetViewState(); - /* + stringstream fps_stream; + fps_stream << "fps: " << GetFrameRate(); SelectFont ("console.ttf size=12"); - Engine::GUI::Label (99999, GetStringViewState(current_view_state), 8, 16); - */ + Engine::GUI::Label (99999, fps_stream.str().c_str(), 8, 48); switch (current_view_state) { case ViewStateMainMenu: @@ -1659,6 +1700,7 @@ void View::DrawAsteroid (AsteroidEntity *asteroid) { glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); + glTranslatef (0., -1., 0.); // glRotatef (90, 1., 0., 0.); float scale = 1.8 * asteroid->mPhysicState->mRadius; glScalef (scale, scale, scale); diff --git a/asteroids/View.h b/asteroids/View.h index bddd53b..20edb9f 100644 --- a/asteroids/View.h +++ b/asteroids/View.h @@ -81,6 +81,7 @@ class View : public Engine::ViewBase { /** \brief Updates the camera for further drawing */ virtual void UpdateCamera (); + virtual void Resize (int width, int height); private: void DrawUi(); diff --git a/asteroids/main.cc b/asteroids/main.cc index 40a5661..e29ca4e 100644 --- a/asteroids/main.cc +++ b/asteroids/main.cc @@ -163,14 +163,15 @@ int main (int argc, char* argv[]) { version_string += FYSXASTEROIDS_VERSION; SDL_WM_SetCaption(version_string.c_str(), version_string.c_str()); - engine.GetView()->SetGridSize (8,8); - /// \todo get rid of the world settings in asteroids dynamic_cast(engine.GetPhysics())->SetWorldSize (26, 20); engine.GetPhysics()->SetWorldBounds (vector3d (-13, 0, -10), vector3d (13, 0, 10)); engine.GetPhysics()->EnableWorldWarp(Engine::PhysicsBase::WorldWarpModeX); engine.GetPhysics()->EnableWorldWarp(Engine::PhysicsBase::WorldWarpModeZ); + engine.GetView()->SetGridSize (8,8); + engine.GetView()->Resize (800, 600); + // run the default commands and load the configuration Engine::RunCommand ("exec asteroids.rc"); Engine::RunCommand ("exec config.rc"); diff --git a/engine/Sprite.cc b/engine/Sprite.cc index 25a86a5..2fe1006 100644 --- a/engine/Sprite.cc +++ b/engine/Sprite.cc @@ -163,10 +163,10 @@ void draw_sprite_helper (float u_start, float u_end, float width, float height) */ glBegin(GL_QUADS); - glTexCoord2f (u_start, 0.f); glColor3f (1.f, 0.f, 0.f); glVertex3f (0.f, 0.f, 0.f); - glTexCoord2f (u_end, 0.f); glColor3f (0.f, 1.f, 0.f); glVertex3f (0.f, 0.f, height); - glTexCoord2f (u_end, 1.f); glColor3f (0.f, 0.f, 1.f); glVertex3f (width, 0.f, height); - glTexCoord2f (u_start, 1.f); glColor3f (1.f, 0.f, 1.f); glVertex3f (width, 0.f,0.f); + glTexCoord2f (u_start, 0.f); glVertex3f (0.f, 0.f, 0.f); + glTexCoord2f (u_end, 0.f); glVertex3f (0.f, 0.f, height); + glTexCoord2f (u_end, 1.f); glVertex3f (width, 0.f, height); + glTexCoord2f (u_start, 1.f); glVertex3f (width, 0.f,0.f); glEnd(); } diff --git a/engine/ViewBase.cc b/engine/ViewBase.cc index 191f161..6c019f1 100644 --- a/engine/ViewBase.cc +++ b/engine/ViewBase.cc @@ -681,7 +681,7 @@ void ViewBase::DrawOBJModelShaded (OBJModelPtr obj_model) { texture = iter->second; } else { - LogMessage ("Disabling textures"); +// LogMessage ("Disabling textures"); } glActiveTexture(GL_TEXTURE0); @@ -1003,7 +1003,7 @@ void ViewBase::Resize (int width, int height) { glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(mCamera->GetFOVY (), float (width) / float (height), 0.1, 100); + gluPerspective(mCamera->GetFOVY (), float (width) / float (height), 0., 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity (); diff --git a/engine/ViewBase.h b/engine/ViewBase.h index 7d9edd6..7977d7f 100644 --- a/engine/ViewBase.h +++ b/engine/ViewBase.h @@ -29,7 +29,7 @@ class ViewBase : public Module{ virtual ~ViewBase() {}; /** \brief Resizes the View */ - void Resize (int width, int height); + virtual void Resize (int width, int height); /** \brief Switches to fullscreen */ void SetFullscreen (bool fullscreen); bool GetIsFullscreen () { return mDrawFullscreen; };