From 79df97d19223ca6d1957a9bdf8186d112db748a5 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 24 Nov 2010 14:41:13 -0500 Subject: [PATCH] added timekeeping and rotating orange quad by time --- dwss.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/dwss.cc b/dwss.cc index 8cdd288..9debf9a 100644 --- a/dwss.cc +++ b/dwss.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,7 @@ #include #include +#include #include "gs-theme-window.h" @@ -52,6 +54,16 @@ static GOptionEntry options[] = { {NULL} }; +static uint64_t start_msec; + +static uint32_t getElapsedTime() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t msec = tv.tv_sec + tv.tv_usec / 1000; + return msec - start_msec; +} + static gboolean expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data) { @@ -63,6 +75,10 @@ expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data) g_assert_not_reached(); } + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(getElapsedTime()/1000.0*360.0, 0, 0, 1); glBegin(GL_QUADS); glColor3f(1, 0.6, 0); glNormal3f(0, 0, 1); @@ -71,6 +87,7 @@ expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data) glVertex2f(-1, -1); glVertex2f(1, 0); glEnd(); + glPopMatrix(); if (gdk_gl_drawable_is_double_buffered(gldrawable)) gdk_gl_drawable_swap_buffers(gldrawable); @@ -97,8 +114,14 @@ configure (GtkWidget *da, GdkEventConfigure *event, gpointer user_data) glMatrixMode(GL_PROJECTION); glLoadIdentity(); + gluPerspective(60.0, + (double)da->allocation.width / (double)da->allocation.height, + 0.001, + 1000.0); glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -2); glShadeModel(GL_SMOOTH); @@ -182,6 +205,10 @@ main (int argc, gtk_timeout_add(12, update, NULL); + struct timeval tv; + gettimeofday(&tv, NULL); + start_msec = tv.tv_sec + tv.tv_usec / 1000; + gtk_main (); return EX_OK;