]>
Dogcows Code - chaz/yoink/blob - src/YoinkApp.cc
2 /*******************************************************************************
4 Copyright (c) 2009, Charles McGarvey
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *******************************************************************************/
32 #include <boost/bind.hpp>
39 #include "YoinkApp.hh"
42 YoinkApp::YoinkApp(int argc
, char* argv
[])
43 : dc::engine("Yoink "VERSION
, argc
, argv
, "yoinkrc")
45 std::cout
<< "Yoink "VERSION
<< std::endl
46 << "Compiled " << __TIME__
" " __DATE__
<< std::endl
47 << "Send requests, patches, and bug reports to <" PACKAGE_BUGREPORT
48 << ">." << std::endl
<< std::endl
;
52 glEnable(GL_TEXTURE_2D
);
54 heroineTexture
= new dc::texture("Heroine.png");
56 glShadeModel(GL_SMOOTH
);
57 //glEnable(GL_DEPTH_TEST);
59 // Enable transparency:
61 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
69 delete heroineTexture
;
70 std::cout
<< "Goodbye..." << std::endl
;
74 void YoinkApp::update(double t
, double dt
)
82 void drawrect(dc::scalar a
, dc::scalar b
, dc::scalar c
, dc::scalar d
)
85 glTexCoord2f(1.0, 1.0);
86 glVertex3d(a
, d
, 0.0);
87 glTexCoord2f(1.0, 0.0);
88 glVertex3d(a
, b
, 0.0);
89 glTexCoord2f(0.0, 0.0);
90 glVertex3d(c
, b
, 0.0);
91 glTexCoord2f(0.0, 1.0);
92 glVertex3d(c
, d
, 0.0);
96 void YoinkApp::draw(double alpha
)
98 static dc::vector3 c1
= dc::vector3::random(0.0, 1.0);
99 static dc::vector3 c2
= dc::vector3::random(0.0, 1.0);
101 glClearColor(1.0, 0.0, 0.0, 1.0);
102 glClear(GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
104 double drawstate
= state
* alpha
+ prevstate
* (1.0 - alpha
);
105 double sinstate
= std::sin(drawstate
);
106 double cosstate
= std::cos(drawstate
);
108 glBindTexture(GL_TEXTURE_2D
, 0);
110 glColor3dv(c1
.array
);
111 drawrect(-cosstate
, -sinstate
, sinstate
, cosstate
);
112 glColor3dv(c2
.array
);
113 drawrect(0.0, 0.0, sinstate
, cosstate
);
115 glColor4f(1.0, 1.0, 1.0, 1.0);
117 heroineTexture
->bind();
120 glTexCoord2f(0.0, 0.0);
121 glVertex3f(0.0, 0.0, 0.0);
122 glTexCoord2f(1.0/8.0, 0.0);
123 glVertex3f(1.0, 0.0, 0.0);
124 glTexCoord2f(1.0/8.0, 1.0/4.0);
125 glVertex3f(1.0, 1.0, 0.0);
126 glTexCoord2f(0.0, 1.0/4.0);
127 glVertex3f(0.0, 1.0, 0.0);
133 void YoinkApp::dispatchEvent(const SDL_Event
& event
)
138 if (event
.key
.keysym
.sym
== SDLK_ESCAPE
)
142 else if (event
.key
.keysym
.sym
== SDLK_f
)
144 getVideo().toggleFull();
155 #include "dispatcher.hh"
157 class Foo
: public dc::notification
160 static void func(const dc::notification
& meh
)
162 std::cout
<< "func: " << std::endl
;
165 void snap(int zzz
, const dc::notification
& nice
, float lean
)
167 std::cout
<< "snap: " << zzz
<< "," << lean
<< std::endl
;
171 void MyHandler(const dc::notification
& cool
)
173 std::cout
<< "MyHandler with a notification" << std::endl
;
177 int main(int argc
, char* argv
[])
179 YoinkApp
app(argc
, argv
);
This page took 0.044698 seconds and 5 git commands to generate.