]> Dogcows Code - chaz/yoink/blobdiff - src/MainLayer.cc
fixed layer bugs; generalized octree
[chaz/yoink] / src / MainLayer.cc
index 51881a770d0e03d8f6d2846c96542c4a2e265d34..2266326402f89b475df8c1a57b3f4abd3dba9d37 100644 (file)
@@ -26,7 +26,7 @@
 
 *******************************************************************************/
 
-#include <cstdlib>             // getenv
+#include <cstdlib>             // atexit, getenv
 #include <cstring>
 #include <iostream>
 #include <string>
 #include <Moof/Log.hh>
 #include <Moof/OpenGL.hh>
 #include <Moof/Resource.hh>
+#include <Moof/Transition.hh>
 #include <Moof/Video.hh>
 
 #include "GameLayer.hh"
 #include "MainLayer.hh"
+#include "TitleLayer.hh"
 
 #if HAVE_CONFIG_H
 #include "config.h"
@@ -62,13 +64,28 @@ MainLayer::~MainLayer()
 void MainLayer::pushed(Mf::Engine& e)
 {
        engine = &e;
-       engine->pushLayer(GameLayer::alloc());
+
+       //Mf::Scalar coeff[] = {0.0, 1.0};
+       //Mf::Lerp interp(coeff, 0.25);
+
+       //Mf::LayerP gameLayer = GameLayer::alloc();
+       //Mf::Transition<Mf::Lerp>::Ptr transition =
+               //Mf::Transition<Mf::Lerp>::alloc(gameLayer, Mf::LayerP(), interp);
+       //engine->push(transition);
+       //engine->push(GameLayer::alloc());
+       engine->push(TitleLayer::alloc());
 }
 
 
 void MainLayer::draw(Mf::Scalar alpha) const
 {
-       glClear(GL_DEPTH_BUFFER_BIT);
+       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+       glMatrixMode(GL_PROJECTION);
+       glLoadIdentity();
+
+       glMatrixMode(GL_MODELVIEW);
+       glLoadIdentity();
 }
 
 bool MainLayer::handleEvent(const Mf::Event& event)
@@ -78,7 +95,7 @@ bool MainLayer::handleEvent(const Mf::Event& event)
                case SDL_KEYDOWN:
                        if (event.key.keysym.sym == SDLK_ESCAPE)
                        {
-                               engine->clearLayers();
+                               quit();
                        }
                        else if (event.key.keysym.sym == SDLK_f)
                        {
@@ -92,47 +109,55 @@ bool MainLayer::handleEvent(const Mf::Event& event)
                        }
                        else if (event.key.keysym.sym == SDLK_y)
                        {
-                               engine->pushLayer(GameLayer::alloc());
+                               engine->push(GameLayer::alloc());
                        }
                        break;
 
+               case SDL_VIDEORESIZE:
+                       glViewport(0, 0, event.resize.w, event.resize.h);
+                       break;
+
                case SDL_QUIT:
-                       engine->clearLayers();
+                       quit();
                        break;
        }
 
        return false;
 }
 
+void MainLayer::quit()
+{
+#if NDEBUG
+       // we don't really need to unwind the stack and shut everything down because
+       // the operating system will take care of cleaning up
+       exit(0);
+#else
+       engine->clear();
+#endif
+}
+
 
 void MainLayer::setupGL()
 {
        glEnable(GL_TEXTURE_2D);
-
-       //glEnable(GL_CULL_FACE);
        glEnable(GL_DEPTH_TEST);
 
+       glEnable(GL_LINE_SMOOTH);
+       glEnable(GL_POLYGON_SMOOTH);
        glShadeModel(GL_SMOOTH);
-       //glEnable(GL_POLYGON_SMOOTH);
 
-       //int texSize;
-       //glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
-       //std::cout << "texture size: " << texSize << std::endl;
-       
        //glEnable(GL_BLEND);
        //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_ALPHA_TEST);
        glAlphaFunc(GL_GREATER, 0.0);
 
-       glClearColor(1.0, 0.0, 0.0, 1.0);
+       glClearColor(0.0, 0.0, 0.0, 1.0);
 
-       //glMatrixMode(GL_PROJECTION);
-       //glLoadIdentity();
-       //gluPerspective(60.0, 1.33333, 1.0, 2500.0);
+       glMatrixMode(GL_PROJECTION);
+       glLoadIdentity();
+       gluPerspective(60.0, 1.33333, 1.0, 2500.0);
 
-       //glMatrixMode(GL_MODELVIEW);
-       
-       //glLineWidth(10.0f);
+       glMatrixMode(GL_MODELVIEW);
 }
 
 void MainLayer::contextRecreated(const Mf::Notification* note)
@@ -162,6 +187,11 @@ void printUsage()
                          << "See documentation for more options." << std::endl;
 }
 
+void goodbye()
+{
+       std::cout << std::endl << "Goodbye..." << std::endl << std::endl;
+}
+
 int main(int argc, char* argv[])
 {
        if (argc > 1 &&
@@ -176,6 +206,8 @@ int main(int argc, char* argv[])
                          << "Send patches and bug reports to <"
                          PACKAGE_BUGREPORT << ">." << std::endl << std::endl;
 
+       atexit(goodbye);
+
 
 #if            YOINK_LOGLEVEL >= 4
        Mf::setLogLevel(Mf::LOG_DEBUG);
@@ -227,7 +259,7 @@ int main(int argc, char* argv[])
        try
        {
                Mf::Engine app(argc, argv, PACKAGE_STRING, iconFile, configFiles);
-               app.pushLayer(MainLayer::alloc());
+               app.push(MainLayer::alloc());
 
                app.run();
        }
@@ -238,7 +270,6 @@ int main(int argc, char* argv[])
                throw e;
        }
 
-       std::cout << std::endl << "Goodbye..." << std::endl << std::endl;
        return 0;
 }
 
This page took 0.02587 seconds and 4 git commands to generate.