]> Dogcows Code - chaz/yoink/blob - src/YoinkApp.cc
64decfb73a88f9e6b0b405f1c94fa3c7c9babc2e
[chaz/yoink] / src / YoinkApp.cc
1
2 /*******************************************************************************
3
4 Copyright (c) 2009, Charles McGarvey
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
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.
15
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.
26
27 *******************************************************************************/
28
29 #include <iostream>
30 #include <string>
31
32 #include <boost/bind.hpp>
33
34 #include "opengl.hh"
35 #include "video.hh"
36
37 #include "vector.hh"
38
39 #include "YoinkApp.hh"
40
41
42 YoinkApp::YoinkApp(int argc, char* argv[])
43 : dc::engine("Yoink "VERSION, argc, argv, "yoinkrc")
44 {
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;
49
50 state = 0.0;
51
52 glEnable(GL_TEXTURE_2D);
53
54 heroineTexture = new dc::texture("Heroine.png");
55
56 glShadeModel(GL_SMOOTH);
57 //glEnable(GL_DEPTH_TEST);
58
59 // Enable transparency:
60 glEnable(GL_BLEND);
61 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
62
63 glLoadIdentity();
64
65 }
66
67 YoinkApp::~YoinkApp()
68 {
69 delete heroineTexture;
70 std::cout << "Goodbye..." << std::endl;
71 }
72
73
74 void YoinkApp::update(double t, double dt)
75 {
76 //dt *= 0.1;
77
78 prevstate = state;
79 state += dt;
80 }
81
82 void drawrect(dc::scalar a, dc::scalar b, dc::scalar c, dc::scalar d)
83 {
84 glBegin(GL_QUADS);
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);
93 glEnd();
94 }
95
96 void YoinkApp::draw(double alpha)
97 {
98 static dc::vector3 c1 = dc::vector3::random(0.0, 1.0);
99 static dc::vector3 c2 = dc::vector3::random(0.0, 1.0);
100
101 glClearColor(1.0, 0.0, 0.0, 1.0);
102 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
103
104 double drawstate = state * alpha + prevstate * (1.0 - alpha);
105 double sinstate = std::sin(drawstate);
106 double cosstate = std::cos(drawstate);
107
108 glBindTexture(GL_TEXTURE_2D, 0);
109
110 glColor3dv(c1.array);
111 drawrect(-cosstate, -sinstate, sinstate, cosstate);
112 glColor3dv(c2.array);
113 drawrect(0.0, 0.0, sinstate, cosstate);
114
115 glColor4f(1.0, 1.0, 1.0, 1.0);
116
117 heroineTexture->bind();
118
119 glBegin(GL_QUADS);
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);
128 glEnd();
129
130 glFlush();
131 }
132
133 void YoinkApp::dispatchEvent(const SDL_Event& event)
134 {
135 switch (event.type)
136 {
137 case SDL_KEYDOWN:
138 if (event.key.keysym.sym == SDLK_ESCAPE)
139 {
140 stop();
141 }
142 else if (event.key.keysym.sym == SDLK_f)
143 {
144 getVideo().toggleFull();
145 }
146 break;
147
148 case SDL_QUIT:
149 stop();
150 break;
151 }
152 }
153
154
155 #include "dispatcher.hh"
156
157 class Foo : public dc::notification
158 {
159 public:
160 static void func(const dc::notification& meh)
161 {
162 std::cout << "func: " << std::endl;
163 }
164
165 void snap(int zzz, const dc::notification& nice, float lean)
166 {
167 std::cout << "snap: " << zzz << "," << lean << std::endl;
168 }
169 };
170
171 void MyHandler(const dc::notification& cool)
172 {
173 std::cout << "MyHandler with a notification" << std::endl;
174 }
175
176
177 int main(int argc, char* argv[])
178 {
179 YoinkApp app(argc, argv);
180 return app.run();
181 }
182
This page took 0.042337 seconds and 3 git commands to generate.