X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMainLayer.cc;fp=src%2FMainLayer.cc;h=2266326402f89b475df8c1a57b3f4abd3dba9d37;hp=51881a770d0e03d8f6d2846c96542c4a2e265d34;hb=a4debfe4a5f5d339410788971b698ba00cb7f09c;hpb=892da43bf5796e7c5f593a6d0f53bd797a36bd3e diff --git a/src/MainLayer.cc b/src/MainLayer.cc index 51881a7..2266326 100644 --- a/src/MainLayer.cc +++ b/src/MainLayer.cc @@ -26,7 +26,7 @@ *******************************************************************************/ -#include // getenv +#include // atexit, getenv #include #include #include @@ -36,10 +36,12 @@ #include #include #include +#include #include #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::Ptr transition = + //Mf::Transition::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; }