summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/engine.h1
-rw-r--r--lib/engine.cc38
-rw-r--r--lib/glbase.cc1
-rw-r--r--src/test.cc99
4 files changed, 89 insertions, 50 deletions
diff --git a/include/engine.h b/include/engine.h
index 6925b5f..d739bde 100644
--- a/include/engine.h
+++ b/include/engine.h
@@ -11,6 +11,7 @@ namespace mogltk {
static int setup() throw(GeneralException);
static int GetInited();
static SDL_RWops * RWFromHandle(Handle *) throw (GeneralException);
+ static void pollevents();
private:
static int inited;
};
diff --git a/lib/engine.cc b/lib/engine.cc
index 84014c7..d065346 100644
--- a/lib/engine.cc
+++ b/lib/engine.cc
@@ -13,6 +13,8 @@ int mogltk::engine::setup() throw(GeneralException) {
throw GeneralException(_("Unable to start SDL base system"));
}
atexit(SDL_Quit);
+
+ SDL_ShowCursor(0);
inited = 1;
@@ -87,3 +89,39 @@ SDL_RWops * mogltk::engine::RWFromHandle(Handle * h) throw (GeneralException) {
}
return r;
}
+
+void mogltk::engine::pollevents() {
+ SDL_Event event;
+
+ while(true) {
+ SDL_WaitEvent(&event);
+ switch(event.type) {
+ case SDL_VIDEOEXPOSE:
+ printm(M_INFO, "Needs to redraw\n");
+ return;
+ case SDL_MOUSEMOTION:
+ printm(M_INFO, "Mouse has gone over the screen - (%i, %i)\n", event.motion.x, event.motion.y);
+ break;
+ case SDL_QUIT:
+ printm(M_INFO, "Quit requested\n");
+ exit(0);
+ break;
+ case SDL_ACTIVEEVENT:
+ switch (event.active.state) {
+ case SDL_APPMOUSEFOCUS:
+ printm(M_INFO, String("Application ") + (event.active.gain ? "gained" : "loosed") + " mouse focus\n");
+ break;
+ case SDL_APPINPUTFOCUS:
+ printm(M_INFO, String("Application ") + (event.active.gain ? "gained" : "loosed") + " input focus\n");
+ break;
+ case SDL_APPACTIVE:
+ printm(M_INFO, String("Application was ") + (event.active.gain ? "restored" : "iconified"));
+ break;
+ }
+ break;
+ default:
+ printm(M_INFO, "Unknow event: %i\n", event.type);
+ break;
+ }
+ }
+}
diff --git a/lib/glbase.cc b/lib/glbase.cc
index 0db56db..346421f 100644
--- a/lib/glbase.cc
+++ b/lib/glbase.cc
@@ -120,6 +120,7 @@ void mogltk::glbase::Leave2DMode(void) {
void mogltk::glbase::Flip() {
SDL_GL_SwapBuffers();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ mogltk::engine::pollevents();
}
bool mogltk::glbase::is2D() {
diff --git a/src/test.cc b/src/test.cc
index d4dacc9..bd98ef3 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -21,60 +21,59 @@ virtual int startup() throw (GeneralException) {
mogltk::texture * mytex = new mogltk::texture(pattern, true);
delete pattern;
- mogltk::glbase::Enter2DMode();
+ while (true) {
+ mogltk::glbase::Enter2DMode();
- mytex->Bind();
- glBegin(GL_TRIANGLE_STRIP);
- glColor3d(0, 0, 0);
- glTexCoord2i(0, 0);
- glVertex2f(50, 50);
- glColor3d(1, 0, 0);
- glTexCoord2i(511, 0);
- glVertex2f(561, 50);
- glColor3d(0, 1, 0);
- glTexCoord2i(0, 511);
- glVertex2f(50, 561);
- glColor3d(0, 0, 1);
- glTexCoord2i(511, 511);
- glVertex2f(561, 561);
- glEnd();
+ mytex->Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ glColor3d(0, 0, 0);
+ glTexCoord2i(0, 0);
+ glVertex2f(50, 50);
+ glColor3d(1, 0, 0);
+ glTexCoord2i(511, 0);
+ glVertex2f(561, 50);
+ glColor3d(0, 1, 0);
+ glTexCoord2i(0, 511);
+ glVertex2f(50, 561);
+ glColor3d(0, 0, 1);
+ glTexCoord2i(511, 511);
+ glVertex2f(561, 561);
+ glEnd();
- mogltk::texture::Unbind();
- glBegin(GL_TRIANGLE_STRIP);
- glColor3d(0, 0, 0);
- glVertex2f(400, 100);
- glColor3d(1, 0, 0);
- glVertex2f(450, 100);
- glColor3d(0, 1, 0);
- glVertex2f(400, 150);
- glColor3d(0, 0, 1);
- glVertex2f(450, 150);
- glEnd();
+ mogltk::texture::Unbind();
+ glBegin(GL_TRIANGLE_STRIP);
+ glColor3d(0, 0, 0);
+ glVertex2f(400, 100);
+ glColor3d(1, 0, 0);
+ glVertex2f(450, 100);
+ glColor3d(0, 1, 0);
+ glVertex2f(400, 150);
+ glColor3d(0, 0, 1);
+ glVertex2f(450, 150);
+ glEnd();
- glBegin(GL_TRIANGLE_STRIP);
- CORNFLOWERBLUE.Bind();
- glVertex2f( 5, 5);
- DEEPSKYBLUE.Bind();
- glVertex2f(150, 5);
- MIDNIGHTBLUE.Bind();
- glVertex2f( 5, 80);
- NAVY.Bind();
- glVertex2f(150, 80);
- glEnd();
- font.setshadow(1);
- font.putcursor(10, 30);
- font.setcolor(WHITE);
- font.printf(
- "PixelPawa!\n"
- "It works!!\n"
- "I can't believe it!\n"
- );
- mogltk::glbase::Leave2DMode();
- mogltk::glbase::Flip();
-
-// sleep(15);
- getchar();
+ glBegin(GL_TRIANGLE_STRIP);
+ CORNFLOWERBLUE.Bind();
+ glVertex2f( 5, 5);
+ DEEPSKYBLUE.Bind();
+ glVertex2f(150, 5);
+ MIDNIGHTBLUE.Bind();
+ glVertex2f( 5, 80);
+ NAVY.Bind();
+ glVertex2f(150, 80);
+ glEnd();
+ font.setshadow(1);
+ font.putcursor(10, 30);
+ font.setcolor(WHITE);
+ font.printf(
+ "PixelPawa!\n"
+ "It works!!\n"
+ "I can't believe it!\n"
+ );
+ mogltk::glbase::Leave2DMode();
+ mogltk::glbase::Flip();
+ }
delete mytex;