added timekeeping and rotating orange quad by time
This commit is contained in:
parent
8551a3800d
commit
79df97d192
27
dwss.cc
27
dwss.cc
@ -28,6 +28,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
@ -40,6 +41,7 @@
|
|||||||
#include <gtk/gtkgl.h>
|
#include <gtk/gtkgl.h>
|
||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
|
||||||
#include "gs-theme-window.h"
|
#include "gs-theme-window.h"
|
||||||
|
|
||||||
@ -52,6 +54,16 @@ static GOptionEntry options[] = {
|
|||||||
{NULL}
|
{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
|
static gboolean
|
||||||
expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data)
|
expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data)
|
||||||
{
|
{
|
||||||
@ -63,6 +75,10 @@ expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data)
|
|||||||
g_assert_not_reached();
|
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);
|
glBegin(GL_QUADS);
|
||||||
glColor3f(1, 0.6, 0);
|
glColor3f(1, 0.6, 0);
|
||||||
glNormal3f(0, 0, 1);
|
glNormal3f(0, 0, 1);
|
||||||
@ -71,6 +87,7 @@ expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data)
|
|||||||
glVertex2f(-1, -1);
|
glVertex2f(-1, -1);
|
||||||
glVertex2f(1, 0);
|
glVertex2f(1, 0);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
if (gdk_gl_drawable_is_double_buffered(gldrawable))
|
if (gdk_gl_drawable_is_double_buffered(gldrawable))
|
||||||
gdk_gl_drawable_swap_buffers(gldrawable);
|
gdk_gl_drawable_swap_buffers(gldrawable);
|
||||||
@ -97,8 +114,14 @@ configure (GtkWidget *da, GdkEventConfigure *event, gpointer user_data)
|
|||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
gluPerspective(60.0,
|
||||||
|
(double)da->allocation.width / (double)da->allocation.height,
|
||||||
|
0.001,
|
||||||
|
1000.0);
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glLoadIdentity();
|
||||||
|
glTranslatef(0, 0, -2);
|
||||||
|
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
|
|
||||||
@ -182,6 +205,10 @@ main (int argc,
|
|||||||
|
|
||||||
gtk_timeout_add(12, update, NULL);
|
gtk_timeout_add(12, update, NULL);
|
||||||
|
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
start_msec = tv.tv_sec + tv.tv_usec / 1000;
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
|
||||||
return EX_OK;
|
return EX_OK;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user