/******************************************************************************* Copyright (c) 2009, Charles McGarvey All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include #include #include #include "opengl.hh" #include "video.hh" #include "vector.hh" #include "YoinkApp.hh" YoinkApp::YoinkApp(int argc, char* argv[]) : dc::engine("Yoink "VERSION, argc, argv, "yoinkrc") { std::cout << "Yoink "VERSION << std::endl << "Compiled " << __TIME__ " " __DATE__ << std::endl << "Send requests, patches, and bug reports to <" PACKAGE_BUGREPORT << ">." << std::endl << std::endl; state = 0.0; glEnable(GL_TEXTURE_2D); heroineTexture = new dc::texture("Heroine.png"); glShadeModel(GL_SMOOTH); //glEnable(GL_DEPTH_TEST); // Enable transparency: glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glLoadIdentity(); } YoinkApp::~YoinkApp() { delete heroineTexture; std::cout << "Goodbye..." << std::endl; } void YoinkApp::update(double t, double dt) { //dt *= 0.1; prevstate = state; state += dt; } void drawrect(dc::scalar a, dc::scalar b, dc::scalar c, dc::scalar d) { glBegin(GL_QUADS); glTexCoord2f(1.0, 1.0); glVertex3d(a, d, 0.0); glTexCoord2f(1.0, 0.0); glVertex3d(a, b, 0.0); glTexCoord2f(0.0, 0.0); glVertex3d(c, b, 0.0); glTexCoord2f(0.0, 1.0); glVertex3d(c, d, 0.0); glEnd(); } void YoinkApp::draw(double alpha) { static dc::vector3 c1 = dc::vector3::random(0.0, 1.0); static dc::vector3 c2 = dc::vector3::random(0.0, 1.0); glClearColor(1.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); double drawstate = state * alpha + prevstate * (1.0 - alpha); double sinstate = std::sin(drawstate); double cosstate = std::cos(drawstate); glBindTexture(GL_TEXTURE_2D, 0); glColor3dv(c1.array); drawrect(-cosstate, -sinstate, sinstate, cosstate); glColor3dv(c2.array); drawrect(0.0, 0.0, sinstate, cosstate); glColor4f(1.0, 1.0, 1.0, 1.0); heroineTexture->bind(); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glTexCoord2f(1.0/8.0, 0.0); glVertex3f(1.0, 0.0, 0.0); glTexCoord2f(1.0/8.0, 1.0/4.0); glVertex3f(1.0, 1.0, 0.0); glTexCoord2f(0.0, 1.0/4.0); glVertex3f(0.0, 1.0, 0.0); glEnd(); glFlush(); } void YoinkApp::dispatchEvent(const SDL_Event& event) { switch (event.type) { case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) { stop(); } else if (event.key.keysym.sym == SDLK_f) { getVideo().toggleFull(); } break; case SDL_QUIT: stop(); break; } } #include "dispatcher.hh" class Foo : public dc::notification { public: static void func(const dc::notification& meh) { std::cout << "func: " << std::endl; } void snap(int zzz, const dc::notification& nice, float lean) { std::cout << "snap: " << zzz << "," << lean << std::endl; } }; void MyHandler(const dc::notification& cool) { std::cout << "MyHandler with a notification" << std::endl; } int main(int argc, char* argv[]) { YoinkApp app(argc, argv); return app.run(); }