Skip to content

Instantly share code, notes, and snippets.

@Photon89
Created December 30, 2021 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Photon89/b1f312ecf48af6050d34062413a2cb33 to your computer and use it in GitHub Desktop.
Save Photon89/b1f312ecf48af6050d34062413a2cb33 to your computer and use it in GitHub Desktop.
WIP Patch for lightspeed to port it to GTK2
diff -ruN lightspeed-1.2a-old/configure.in lightspeed-1.2a-new/configure.in
--- lightspeed-1.2a-old/configure.in 2001-08-08 19:44:21.000000000 +0200
+++ lightspeed-1.2a-new/configure.in 2021-12-30 09:36:49.071634000 +0100
@@ -37,7 +37,7 @@
# Checks for GTK+ libraries.
#
-AM_PATH_GTK(1.0.1, , AC_MSG_ERROR([Cannot find proper GTK+ version]))
+AM_PATH_GTK_2_0(2.0.1, , AC_MSG_ERROR([Cannot find proper GTK+ version]))
#
# Check for OpenGL libraries
@@ -69,11 +69,11 @@
GTKGL_LDOPTS="-L$with_gtkgl_prefix/lib"
fi
-AC_CHECK_LIB(gtkgl, gtk_gl_area_new, ,
+AC_CHECK_LIB(gtkgl-2.0, gtk_gl_area_new, ,
AC_MSG_ERROR([Cannot find GtkGLArea library.]),
$GTKGL_LDOPTS $GTK_LIBS $GL_LIBS)
-GTKGL_LIBS="$GTKGL_LDOPTS -lgtkgl"
+GTKGL_LIBS="$GTKGL_LDOPTS -lgtkgl-2.0"
#
# Test for libpng
@@ -94,7 +94,7 @@
png_ok=no)
AC_MSG_RESULT($png_ok)
if test "$png_ok" = yes; then
- PNG='png'; LIBPNG_LIB='-lpng -lz'
+ PNG='png'; LIBPNG_LIB='-lpng -lz -lm'
else
AC_MSG_WARN(*** PNG exporter cannot be built (PNG library is too old) ***)
fi
@@ -136,7 +136,9 @@
# That's a wrap!
#
-CFLAGS="$CFLAGS $GTK_CFLAGS $GL_CFLAGS $GTKGL_CFLAGS"
+# REMOVE -pg for release!
+# CFLAGS="$CFLAGS $GTK_CFLAGS $GL_CFLAGS $GTKGL_CFLAGS -DGTK_ENABLE_BROKEN"
+CFLAGS="$CFLAGS $GTK_CFLAGS $GL_CFLAGS $GTKGL_CFLAGS -DGTK_ENABLE_BROKEN -pg"
LIBS="$LIBS $GTKGL_LIBS $GTK_LIBS $GL_LIBS $IMG_LIBS"
AC_OUTPUT(Makefile src/Makefile)
diff -ruN lightspeed-1.2a-old/src/animation.c lightspeed-1.2a-new/src/animation.c
--- lightspeed-1.2a-old/src/animation.c 2000-10-26 23:00:27.000000000 +0200
+++ lightspeed-1.2a-new/src/animation.c 2021-12-30 14:53:26.133803000 +0100
@@ -89,6 +89,8 @@
/* Do pending redraws (if any) ONLY if event queue is empty */
if (gtk_events_pending( ) == 0) {
+ //if (!g_main_context_pending(NULL)) {
+ fprintf(stderr, "gtk_events_pending=0\n");
for (i = 0; i < num_cams; i++)
if (usr_cams[i]->redraw) {
camera_calc_xyz( CAM_POSITION, usr_cams[i] );
@@ -102,6 +104,11 @@
#endif
}
else
+ fprintf(stderr, "gtk_events_pending=1\n");
+ if ( gtk_get_current_event () == NULL ) {
+ fprintf(stderr, "current event is NULL\n");
+ fflush( stderr );
+ }
redraw_deferred = TRUE;
/* Semi-BUG: Framerate goes artificially high if only spawned cameras are moved
diff -ruN lightspeed-1.2a-old/src/gtkwidgets.c lightspeed-1.2a-new/src/gtkwidgets.c
--- lightspeed-1.2a-old/src/gtkwidgets.c 2000-10-26 23:00:27.000000000 +0200
+++ lightspeed-1.2a-new/src/gtkwidgets.c 2021-12-26 00:29:59.293003000 +0100
@@ -25,6 +25,8 @@
#include "lightspeed.h"
+#include <gtk/gtktext.h>
+#include <gtk/gtkaccelgroup.h>
/* Creates and installs an OpenGL widget into specified box */
@@ -64,7 +66,7 @@
{
GtkWidget *dialog_window_w;
- dialog_window_w = gtk_window_new( GTK_WINDOW_DIALOG );
+ dialog_window_w = gtk_window_new( GDK_WINDOW_DIALOG );
gtk_window_set_title( GTK_WINDOW(dialog_window_w), title );
gtk_container_set_border_width( GTK_CONTAINER(dialog_window_w), 0 );
if (callback_close != NULL) {
@@ -361,7 +363,7 @@
return;
}
if (GTK_IS_WINDOW(widget)) {
- gtk_accel_group_attach( accel_group, GTK_OBJECT(widget) );
+ gtk_window_add_accel_group( accel_group, GTK_OBJECT(widget) );
return;
}
@@ -551,10 +553,11 @@
set_entry_width( GtkWidget *entry_w, const char *span_str )
{
GtkStyle *style;
+ GdkFont *font;
int width;
style = gtk_widget_get_style( entry_w );
- width = gdk_string_width( style->font, span_str );
+ width = gdk_string_width( font, span_str );
gtk_widget_set_usize( entry_w, width, 0 );
}
@@ -649,9 +652,9 @@
gtk_box_pack_start( GTK_BOX(hbox_w), text_w, TRUE, TRUE, 0 );
gtk_widget_show( text_w );
/* Vertical scroll bar */
- vscrollbar_w = gtk_vscrollbar_new( GTK_TEXT(text_w)->vadj );
- gtk_box_pack_start( GTK_BOX(hbox_w), vscrollbar_w, FALSE, FALSE, 0 );
- gtk_widget_show( vscrollbar_w );
+ //vscrollbar_w = gtk_vscrollbar_new( GTK_TEXT(text_w)->vadj );
+ //gtk_box_pack_start( GTK_BOX(hbox_w), vscrollbar_w, FALSE, FALSE, 0 );
+ //gtk_widget_show( vscrollbar_w );
/* Bring in the text */
gtk_widget_realize( text_w );
diff -ruN lightspeed-1.2a-old/src/lightspeed.h lightspeed-1.2a-new/src/lightspeed.h
--- lightspeed-1.2a-old/src/lightspeed.h 2000-10-26 23:00:27.000000000 +0200
+++ lightspeed-1.2a-new/src/lightspeed.h 2021-12-30 14:03:32.101328000 +0100
@@ -50,7 +50,7 @@
#include "settings.h"
/* For GTK+/glib 1.0 compatibility */
-#include "compat.h"
+// #include "compat.h"
/* Optional memory allocation tracking */
#ifdef WITH_TRACKMEM
diff -ruN lightspeed-1.2a-old/src/menu_cbs.c lightspeed-1.2a-new/src/menu_cbs.c
--- lightspeed-1.2a-old/src/menu_cbs.c 2001-08-08 19:49:17.000000000 +0200
+++ lightspeed-1.2a-new/src/menu_cbs.c 2021-12-26 00:09:54.165448000 +0100
@@ -1319,7 +1319,7 @@
#endif
break;
}
- GTKGL_TEMP_endgl( GTK_GL_AREA(usr_cams[i]->ogl_w) );
+ //GTKGL_TEMP_endgl( GTK_GL_AREA(usr_cams[i]->ogl_w) );
}
/* Redraw everything */
diff -ruN lightspeed-1.2a-old/src/misc.c lightspeed-1.2a-new/src/misc.c
--- lightspeed-1.2a-old/src/misc.c 2000-10-26 23:00:27.000000000 +0200
+++ lightspeed-1.2a-new/src/misc.c 2021-12-30 14:03:57.014180000 +0100
@@ -443,17 +443,17 @@
glHint( GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE );
glEnable( GL_LIGHTING );
glEnable( GL_DEPTH_TEST );
- GTKGL_TEMP_endgl( GTK_GL_AREA(cam->ogl_w) );
- gtk_gl_area_swapbuffers( GTK_GL_AREA(cam->ogl_w) );
+ // GTKGL_TEMP_endgl( GTK_GL_AREA(cam->ogl_w) );
+ gtk_gl_area_swap_buffers( GTK_GL_AREA(cam->ogl_w) );
}
/* NOP is referenced in compat.h
* When no one in the world is using GTK 1.0, I'll get rid of this */
-int *NOP( void )
+/*int *NOP( void )
{
while (FALSE);
return NULL;
}
-
+*/
/* end misc.c */
diff -ruN lightspeed-1.2a-old/src/ogl.c lightspeed-1.2a-new/src/ogl.c
--- lightspeed-1.2a-old/src/ogl.c 2000-10-26 23:00:27.000000000 +0200
+++ lightspeed-1.2a-new/src/ogl.c 2021-12-28 19:21:33.841980000 +0100
@@ -73,7 +73,8 @@
ogl_draw_string( NULL, INITIALIZE, NIL );
if (on_screen) {
- GTKGL_TEMP_endgl( GTK_GL_AREA(ogl_w) );
+// GTKGL_TEMP_endgl( GTK_GL_AREA(ogl_w) );
+ glFlush();
/* Call ogl_resize( ) to finish viewport initialization */
ogl_resize( ogl_w, NULL, NULL );
@@ -103,7 +104,8 @@
height = ogl_w->allocation.height;
gtk_gl_area_make_current( GTK_GL_AREA(ogl_w) );
glViewport( 0, 0, width, height );
- GTKGL_TEMP_endgl( GTK_GL_AREA(ogl_w) );
+ // GTKGL_TEMP_endgl( GTK_GL_AREA(ogl_w) );
+ glFlush();
/* Update dimensions in camera struct */
i = assoc_cam_id( ogl_w );
@@ -291,8 +293,10 @@
info_display( INFODISP_DRAW, NIL );
if (drawing_to_screen) {
- GTKGL_TEMP_endgl( GTK_GL_AREA(cam->ogl_w) );
- gtk_gl_area_swapbuffers( GTK_GL_AREA(cam->ogl_w) );
+// GTKGL_TEMP_endgl( GTK_GL_AREA(cam->ogl_w) );
+// glFlush();
+ gtk_gl_area_swap_buffers( GTK_GL_AREA(cam->ogl_w) );
+ gtk_widget_queue_draw( GTK_GL_AREA(cam->ogl_w) );
profile( PROFILE_OGLDRAW_DONE );
cam->redraw = FALSE;
}
@@ -519,8 +523,9 @@
glEnable( GL_DEPTH_TEST );
}
- GTKGL_TEMP_endgl( GTK_GL_AREA(cam->ogl_w) );
- gtk_gl_area_swapbuffers( GTK_GL_AREA(cam->ogl_w) );
+ // GTKGL_TEMP_endgl( GTK_GL_AREA(cam->ogl_w) );
+ gtk_widget_queue_draw( GTK_GL_AREA(cam->ogl_w) );
+ gtk_gl_area_swap_buffers( GTK_GL_AREA(cam->ogl_w) );
}
diff -ruN lightspeed-1.2a-old/src/snapshot.c lightspeed-1.2a-new/src/snapshot.c
--- lightspeed-1.2a-old/src/snapshot.c 2000-10-26 23:00:27.000000000 +0200
+++ lightspeed-1.2a-new/src/snapshot.c 2021-12-30 14:03:17.204949000 +0100
@@ -27,6 +27,7 @@
#ifdef HAVE_LIBPNG
#include <png.h>
+#include <zlib.h>
static int write_png( int message, const void *data );
#endif
@@ -85,8 +86,8 @@
err = !gdk_gl_pixmap_make_current( glpixmap, context );
if (err) {
message_window( STR_DLG_Error, STR_MSG_no_ogl_context );
- gdk_gl_context_unref( context );
- gdk_gl_pixmap_unref( glpixmap );
+ // gdk_gl_context_unref( context );
+ // gdk_gl_pixmap_unref( glpixmap );
gdk_pixmap_unref( pixmap );
return -1;
}
@@ -179,8 +180,8 @@
/* Close up output file */
write_image( format, IMAGE_COMPLETE, NULL );
- gdk_gl_context_unref( context );
- gdk_gl_pixmap_unref( glpixmap );
+ // gdk_gl_context_unref( context );
+ // gdk_gl_pixmap_unref( glpixmap );
gdk_pixmap_unref( pixmap );
return err;
@@ -250,7 +251,7 @@
return -1;
png_write_s = png_create_write_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL );
png_info_s = png_create_info_struct( png_write_s );
- if (setjmp( png_write_s->jmpbuf )) {
+ if (setjmp( png_jmpbuf( png_write_s ))) {
/* Error writing file */
png_destroy_write_struct( &png_write_s, &png_info_s );
fclose( png_fp );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment