221 lines
5.4 KiB
C++
221 lines
5.4 KiB
C++
/*
|
|
* Copyright (C) 2005 Ray Strode <rstrode@redhat.com>,
|
|
* Matthias Clasen <mclasen@redhat.com>,
|
|
* Søren Sandmann <sandmann@redhat.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public License as
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
* 02111-1307, USA.
|
|
*
|
|
* Originally written by: Ray Strode <rstrode@redhat.com>
|
|
*
|
|
* Later contributions by: Matthias Clasen <mclasen@redhat.com>
|
|
* Søren Sandmann <sandmann@redhat.com>
|
|
*/
|
|
|
|
#include <math.h>
|
|
#include <stdlib.h>
|
|
#include <sysexits.h>
|
|
#include <time.h>
|
|
#include <sys/time.h>
|
|
|
|
#include <glib.h>
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gdk/gdk.h>
|
|
#include <gdk/gdkx.h>
|
|
#include <gdk/gdkgl.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
#include <gtk/gtkgl.h>
|
|
|
|
#include <GL/gl.h>
|
|
#include <GL/glu.h>
|
|
|
|
#include "gs-theme-window.h"
|
|
|
|
static gchar *geometry = NULL;
|
|
static GtkWidget *drawing_area;
|
|
|
|
static GOptionEntry options[] = {
|
|
{"geometry", 0, 0, G_OPTION_ARG_STRING, &geometry,
|
|
N_("The initial size and position of window"),
|
|
N_("WIDTHxHEIGHT+X+Y")},
|
|
{NULL}
|
|
};
|
|
|
|
static uint64_t start_msec;
|
|
|
|
static uint32_t getElapsedTime()
|
|
{
|
|
struct timeval tv;
|
|
gettimeofday(&tv, NULL);
|
|
uint64_t msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
return msec - start_msec;
|
|
}
|
|
|
|
static gboolean
|
|
expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data)
|
|
{
|
|
GdkGLContext *glcontext = gtk_widget_get_gl_context(da);
|
|
GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(da);
|
|
|
|
if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
|
|
{
|
|
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);
|
|
glVertex2f(1, 1);
|
|
glVertex2f(-1, 1);
|
|
glVertex2f(-1, -1);
|
|
glVertex2f(1, 0);
|
|
glEnd();
|
|
glPopMatrix();
|
|
|
|
if (gdk_gl_drawable_is_double_buffered(gldrawable))
|
|
gdk_gl_drawable_swap_buffers(gldrawable);
|
|
else
|
|
glFlush();
|
|
|
|
gdk_gl_drawable_gl_end(gldrawable);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
static gboolean
|
|
configure (GtkWidget *da, GdkEventConfigure *event, gpointer user_data)
|
|
{
|
|
GdkGLContext *glcontext = gtk_widget_get_gl_context(da);
|
|
GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(da);
|
|
|
|
if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
|
|
{
|
|
g_assert_not_reached();
|
|
}
|
|
|
|
glViewport(0, 0, da->allocation.width, da->allocation.height);
|
|
|
|
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);
|
|
|
|
gdk_gl_drawable_gl_end(gldrawable);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
static gboolean
|
|
update (void *user_data)
|
|
{
|
|
GdkRectangle rect;
|
|
GdkWindow *win = gtk_widget_get_parent_window(drawing_area);
|
|
rect.x = rect.y = 0;
|
|
gdk_window_get_geometry(win, NULL, NULL, &rect.width, &rect.height, NULL);
|
|
gdk_window_invalidate_rect(win, &rect, TRUE);
|
|
return TRUE;
|
|
}
|
|
|
|
int
|
|
main (int argc,
|
|
char *argv[])
|
|
{
|
|
GtkWidget *window;
|
|
GdkGLConfig *glconfig;
|
|
|
|
GtkStateType state;
|
|
|
|
GError *error;
|
|
|
|
error = NULL;
|
|
|
|
gtk_init_with_args (&argc, &argv,
|
|
_("DornerWorks ScreenSaver"),
|
|
NULL, NULL, &error);
|
|
gtk_gl_init(&argc, &argv);
|
|
|
|
|
|
if (error != NULL)
|
|
{
|
|
g_printerr (_("%s. See --help for usage information.\n"),
|
|
_(error->message));
|
|
g_error_free (error);
|
|
return EX_SOFTWARE;
|
|
}
|
|
|
|
|
|
window = gs_theme_window_new ();
|
|
|
|
g_signal_connect (G_OBJECT (window), "delete-event",
|
|
G_CALLBACK (gtk_main_quit), NULL);
|
|
|
|
drawing_area = gtk_drawing_area_new ();
|
|
|
|
glconfig = gdk_gl_config_new_by_mode( (GdkGLConfigMode)
|
|
( GDK_GL_MODE_RGB |
|
|
GDK_GL_MODE_DEPTH |
|
|
GDK_GL_MODE_DOUBLE ) );
|
|
|
|
if (!glconfig)
|
|
{
|
|
g_assert_not_reached();
|
|
}
|
|
if (!gtk_widget_set_gl_capability(drawing_area, glconfig, NULL, TRUE,
|
|
GDK_GL_RGBA_TYPE))
|
|
{
|
|
g_assert_not_reached();
|
|
}
|
|
|
|
g_signal_connect(drawing_area, "configure-event",
|
|
G_CALLBACK(configure), NULL);
|
|
g_signal_connect(drawing_area, "expose-event",
|
|
G_CALLBACK(expose), NULL);
|
|
|
|
gtk_widget_show (drawing_area);
|
|
gtk_container_add (GTK_CONTAINER (window), drawing_area);
|
|
|
|
if ((geometry == NULL)
|
|
|| !gtk_window_parse_geometry (GTK_WINDOW (window), geometry))
|
|
{
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
|
|
}
|
|
|
|
gtk_widget_show (window);
|
|
|
|
gtk_timeout_add(12, update, NULL);
|
|
|
|
struct timeval tv;
|
|
gettimeofday(&tv, NULL);
|
|
start_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
|
|
gtk_main ();
|
|
|
|
return EX_OK;
|
|
}
|