diff --git a/desmume/src/gtk-glade/Makefile.am b/desmume/src/gtk-glade/Makefile.am index a4ee7ce2a..73da41b9d 100644 --- a/desmume/src/gtk-glade/Makefile.am +++ b/desmume/src/gtk-glade/Makefile.am @@ -1,7 +1,7 @@ bin_PROGRAMS = desmume-glade desmume_glade_SOURCES = \ callbacks.c callbacks.h callbacks_IO.c callbacks_IO.h desmume.c desmume.h \ - globals.h keyval_names.c main.c printscreen.c \ + globals.h keyval_names.c main.c printscreen.c gdk_gl.c gdk_gl.h \ dTools/callbacks_1_ioregs.c dTools/callbacks_2_memview.c \ dTools/callbacks_3_palview.c dTools/callbacks_dtools.h \ dTools/dTools_display.h \ diff --git a/desmume/src/gtk-glade/callbacks_IO.c b/desmume/src/gtk-glade/callbacks_IO.c index 74167e446..9a9824f3c 100755 --- a/desmume/src/gtk-glade/callbacks_IO.c +++ b/desmume/src/gtk-glade/callbacks_IO.c @@ -22,11 +22,9 @@ #include "callbacks_IO.h" -// comment for GL :D -#undef HAVE_LIBGDKGLEXT_X11_1_0 - static u16 Cur_Keypad = 0; int ScreenCoeff_Size=1; +float fScreenCoeff_Size=1.0; gboolean ScreenRotate=FALSE; gboolean Boost=FALSE; int BoostFS=20; @@ -112,7 +110,6 @@ void decode_screen () { pixel++; } } -#ifndef HAVE_LIBGDKGLEXT_X11_1_0 #define LOOP(a,b,c,d,e,f) \ L=W*ScreenCoeff_Size; \ BL=L*sizeof(u32); \ @@ -129,14 +126,6 @@ void decode_screen () { rgb32 += L; \ } \ } -#else - #define LOOP(a,b,c,d,e,f) \ - for (a; b; c) { \ - for (d; e; f) { \ - rgb32 = image[y][x]; rgb32++; \ - } \ - } -#endif /* load pixels in buffer accordingly */ if (ScreenRotate) { W=RAW_H; H=RAW_W; @@ -149,14 +138,19 @@ void decode_screen () { } #ifndef HAVE_LIBGDKGLEXT_X11_1_0 - // they are empty if no opengl -void init_GL_capabilities(GtkWidget * widget) {} +// else see gdk_gl.c / gdk_gl.h +BOOL my_gl_Begin (int screen) { return FALSE; } +void my_gl_End (int screen) {} +void init_GL_capabilities() {} void init_GL(GtkWidget * widget, int screen) {} -void reshape (GtkWidget * widget) {} +void reshape (GtkWidget * widget, int screen) {} gboolean screen (GtkWidget * widget, int off) { int H,W,L; + if (off==0) + decode_screen(); + if (ScreenRotate) { W=RAW_H; H=RAW_W; } else { @@ -171,122 +165,6 @@ gboolean screen (GtkWidget * widget, int off) { GDK_RGB_DITHER_NONE,((guchar*)on_screen_image32)+off,L); return TRUE; } - -#else /* if HAVE_LIBGDKGLEXT_X11_1_0 */ - -void init_GL_capabilities(GtkWidget * widget) { - GdkGLConfig * my_glConfig; - my_glConfig = gdk_gl_config_new_by_mode ( - GDK_GL_MODE_RGB - | GDK_GL_MODE_DEPTH - | GDK_GL_MODE_DOUBLE - ); - if (!gtk_widget_set_gl_capability( - widget, - my_glConfig, - NULL, - TRUE, - GDK_GL_RGBA_TYPE)) { - printf ("gtk_widget_set_gl_capability\n"); - gtk_main_quit(); - } -} - -GLuint Textures[1]; - -void init_GL(GtkWidget * widget, int screen) { - GdkGLContext *my_glContext = gtk_widget_get_gl_context (widget); - GdkGLDrawable *my_glDrawable = gtk_widget_get_gl_drawable (widget); - if (!gdk_gl_drawable_gl_begin(my_glDrawable, my_glContext)) - return; - - /* Set the background black */ - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - - glEnable(GL_TEXTURE_2D); - glGenTextures(1, &Textures[0]); - -/* - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); -*/ - // beautiful quad - glBegin(GL_QUADS); - glColor3ub(255,0,0); glVertex2d(-0.75,-0.75); - glColor3ub(128,255,0); glVertex2d(-0.75, 0.75); - glColor3ub(0,255,128); glVertex2d( 0.75, 0.75); - glColor3ub(0,0,255); glVertex2d( 0.75,-0.75); - glEnd(); - - glFlush (); - if (gdk_gl_drawable_is_double_buffered (my_glDrawable)) - gdk_gl_drawable_swap_buffers (my_glDrawable); - gdk_gl_drawable_gl_end(my_glDrawable); -} - -void reshape (GtkWidget * widget) { - GdkGLContext *my_glContext = gtk_widget_get_gl_context (widget); - GdkGLDrawable *my_glDrawable = gtk_widget_get_gl_drawable (widget); - if (!gdk_gl_drawable_gl_begin (my_glDrawable, my_glContext)) return; - - glViewport (0, 0, widget->allocation.width, widget->allocation.height); - - gdk_gl_drawable_gl_end (my_glDrawable); -} - -gboolean screen (GtkWidget * widget, int screen) { - int H,W,off; - GdkGLContext *my_glContext = gtk_widget_get_gl_context (widget); - GdkGLDrawable *my_glDrawable = gtk_widget_get_gl_drawable (widget); - if (!gdk_gl_drawable_gl_begin(my_glDrawable, my_glContext)) - return TRUE; - - glLoadIdentity(); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - - // colorful quads so that there's something to see in case of pb - glBegin(GL_QUADS); - glColor3ub(255,0,0); glVertex2d(-0.75,-0.75); - glColor3ub(128,255,0); glVertex2d(-0.75, 0.75); - glColor3ub(0,255,128); glVertex2d( 0.75, 0.75); - glColor3ub(0,0,255); glVertex2d( 0.75,-0.75); - glColor3ub(255,255,255); - glEnd(); - - off = (screen)?RAW_OFFSET:0; - - if (ScreenRotate) { - glRotatef(90.0, 0.0, 0.0, 1.0); - } - - glBindTexture(GL_TEXTURE_2D, Textures[0]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, 4, - 256, 256, 0, GL_RGBA, - GL_UNSIGNED_SHORT_1_5_5_5_REV, -// GL_UNSIGNED_SHORT_5_5_5_1, - GPU_screen+off); - - glBegin(GL_QUADS); - // texcoords 0.75 means 192, 1 means 256 - glTexCoord2f(0.0, 0.00); glVertex2d(-1.0, 1.0); - glTexCoord2f(0.0, 0.75); glVertex2d(-1.0,-1.0); - glTexCoord2f(1.0, 0.75); glVertex2d( 1.0,-1.0); - glTexCoord2f(1.0, 0.00); glVertex2d( 1.0, 1.0); - glEnd(); - - - glFlush (); - if (gdk_gl_drawable_is_double_buffered (my_glDrawable)) - gdk_gl_drawable_swap_buffers (my_glDrawable); - gdk_gl_drawable_gl_end(my_glDrawable); - return TRUE; -} - #endif /* if HAVE_LIBGDKGLEXT_X11_1_0 */ @@ -300,9 +178,6 @@ void on_wDraw_Sub_realize (GtkWidget *widget, gpointer user_data) { } gboolean on_wDraw_Main_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data) { -#ifndef HAVE_LIBGDKGLEXT_X11_1_0 - decode_screen(); -#endif return screen(widget, 0); } gboolean on_wDraw_Sub_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data) { @@ -310,10 +185,10 @@ gboolean on_wDraw_Sub_expose_event (GtkWidget *widget, GdkEventExpose *event } gboolean on_wDraw_Main_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data) { - reshape(widget); return TRUE; + reshape(widget, 0); return TRUE; } gboolean on_wDraw_Sub_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data) { - reshape(widget); return TRUE; + reshape(widget, 1); return TRUE; } diff --git a/desmume/src/gtk-glade/callbacks_IO.h b/desmume/src/gtk-glade/callbacks_IO.h index 9b027f660..c86d54090 100755 --- a/desmume/src/gtk-glade/callbacks_IO.h +++ b/desmume/src/gtk-glade/callbacks_IO.h @@ -22,9 +22,6 @@ #include "globals.h" -void init_GL_capabilities(GtkWidget * widget); - - /* INPUT BUTTONS / KEYBOARD */ G_MODULE_EXPORT gboolean on_wMainW_key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data); G_MODULE_EXPORT gboolean on_wMainW_key_release_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data); diff --git a/desmume/src/gtk-glade/gdk_gl.c b/desmume/src/gtk-glade/gdk_gl.c new file mode 100755 index 000000000..4f8ae29e8 --- /dev/null +++ b/desmume/src/gtk-glade/gdk_gl.c @@ -0,0 +1,162 @@ +/* gdk_gl.c - this file is part of DeSmuME + * + * Copyright (C) 2007 Damien Nozay (damdoum) + * Author: damdoum at users.sourceforge.net + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "gdk_gl.h" + +#ifdef HAVE_LIBGDKGLEXT_X11_1_0 +GLuint Textures[1]; +GdkGLConfig *my_glConfig=NULL; +GdkGLContext *my_glContext=NULL; +GdkGLDrawable *my_glDrawable[3]={NULL,NULL,NULL}; +GtkWidget *pDrawingTexArea; + +INLINE void my_gl_Identity() { + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); +} + +INLINE void my_gl_DrawBeautifulQuad() { + // beautiful quad + glBegin(GL_QUADS); + glColor3ub(255,0,0); glVertex2d(-0.75,-0.75); + glColor3ub(128,255,0); glVertex2d(-0.75, 0.75); + glColor3ub(0,255,128); glVertex2d( 0.75, 0.75); + glColor3ub(0,0,255); glVertex2d( 0.75,-0.75); + glEnd(); + glColor3ub(255,255,255); +} + +BOOL my_gl_Begin (int screen) { + return gdk_gl_drawable_gl_begin(my_glDrawable[screen], my_glContext); +} + +void my_gl_End (int screen) { + glFlush (); + if (gdk_gl_drawable_is_double_buffered (my_glDrawable[screen])) + gdk_gl_drawable_swap_buffers (my_glDrawable[screen]); + gdk_gl_drawable_gl_end(my_glDrawable[screen]); +} + +void init_GL(GtkWidget * widget, int screen) { + // init GL capability + if (!gtk_widget_set_gl_capability( + widget, my_glConfig, + NULL, TRUE, + GDK_GL_RGBA_TYPE)) { + printf ("gtk_widget_set_gl_capability\n"); + exit(1); + } + // realize so that we get a GdkWindow + gtk_widget_realize(widget); + // make sure we realize + gtk_events_pending(); + + my_glDrawable[screen] = gtk_widget_get_gl_drawable(widget); + // shared context + if (my_glContext == NULL) { + // not initialized ! + my_glContext = gtk_widget_get_gl_context(widget); + if (!my_gl_Begin(screen)) return; + + /* Set the background black */ + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + my_gl_DrawBeautifulQuad(); + + // generated ONE texture (display) + glEnable(GL_TEXTURE_2D); + glGenTextures(1, &Textures[0]); + + my_gl_End(screen); + } + reshape(widget, screen); +} + +void init_GL_capabilities() { + my_glConfig = gdk_gl_config_new_by_mode ( + GDK_GL_MODE_RGB + | GDK_GL_MODE_DEPTH + | GDK_GL_MODE_DOUBLE + ); + // initialize 1st drawing area + init_GL(pDrawingArea,0); + // initialize 2nd drawing area (sharing context) + init_GL(pDrawingArea2,1); +} + +void reshape (GtkWidget * widget, int screen) { + if (my_glDrawable[screen] == NULL || + !my_gl_Begin(screen)) return; + + glViewport (0, 0, widget->allocation.width, widget->allocation.height); + + my_gl_End(screen); +} + +INLINE void my_gl_Texture2D() { + glBindTexture(GL_TEXTURE_2D, Textures[0]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +} + +INLINE void my_gl_ScreenTex() { + glTexImage2D(GL_TEXTURE_2D, 0, 4, + 256, 512, 0, GL_RGBA, + GL_UNSIGNED_SHORT_1_5_5_5_REV, +// GL_UNSIGNED_SHORT_5_5_5_1, + GPU_screen); +} + +void my_gl_ScreenTexApply(int screen) { + float off = (screen)?0.375:0; + glBegin(GL_QUADS); + // texcoords 0.375 means 192, 1 means 256 + glTexCoord2f(0.0, off+0.000); glVertex2d(-1.0, 1.0); + glTexCoord2f(0.0, off+0.375); glVertex2d(-1.0,-1.0); + glTexCoord2f(1.0, off+0.375); glVertex2d( 1.0,-1.0); + glTexCoord2f(1.0, off+0.000); glVertex2d( 1.0, 1.0); + glEnd(); +} + +gboolean screen (GtkWidget * widget, int screen) { + int H,W; + if (!my_gl_Begin(screen)) return TRUE; + + glLoadIdentity(); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + my_gl_DrawBeautifulQuad(); + + // rotate + if (ScreenRotate) glRotatef(90.0, 0.0, 0.0, 1.0); + + // draw screen + my_gl_Texture2D(); + if (screen==0) my_gl_ScreenTex(); + my_gl_ScreenTexApply(screen); + + my_gl_End(screen); + return TRUE; +} + +#endif /* if HAVE_LIBGDKGLEXT_X11_1_0 */ diff --git a/desmume/src/gtk-glade/gdk_gl.h b/desmume/src/gtk-glade/gdk_gl.h new file mode 100755 index 000000000..997651252 --- /dev/null +++ b/desmume/src/gtk-glade/gdk_gl.h @@ -0,0 +1,30 @@ +/* gdk_gl.h - this file is part of DeSmuME + * + * Copyright (C) 2007 Damien Nozay (damdoum) + * Author: damdoum at users.sourceforge.net + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "globals.h" + +BOOL my_gl_Begin (int screen); +void my_gl_End (int screen); + +void init_GL_capabilities(); +void init_GL(GtkWidget * widget, int screen); +void reshape (GtkWidget * widget, int screen); +gboolean screen (GtkWidget * widget, int off); diff --git a/desmume/src/gtk-glade/glade/DeSmuMe.glade b/desmume/src/gtk-glade/glade/DeSmuMe.glade index 31addf66c..b2efbf49f 100755 --- a/desmume/src/gtk-glade/glade/DeSmuMe.glade +++ b/desmume/src/gtk-glade/glade/DeSmuMe.glade @@ -581,7 +581,7 @@ True - 1,0x + 1x True True @@ -597,7 +597,6 @@ - True @@ -1055,7 +1054,6 @@ False GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK - @@ -1220,7 +1218,6 @@ False GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK - diff --git a/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade b/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade index 356b59089..1569a794f 100755 --- a/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade +++ b/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade @@ -526,4 +526,73 @@ ARM7 cpu + + True + Texture viewer + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-close + True + GTK_RELIEF_NORMAL + True + -7 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 256 + 256 + GDK_EXPOSURE_MASK + + + + + 0 + True + True + + + + + + diff --git a/desmume/src/gtk-glade/globals.h b/desmume/src/gtk-glade/globals.h index c0a1a85a8..e3b1f1e36 100755 --- a/desmume/src/gtk-glade/globals.h +++ b/desmume/src/gtk-glade/globals.h @@ -35,6 +35,18 @@ //#include // more portable #include "SDL.h" + +// fix gtk-glade on windows with no configure +#ifndef DATADIR +#define DATADIR " " +#endif +#ifndef GLADEUI_UNINSTALLED_DIR +#define GLADEUI_UNINSTALLED_DIR "glade/" +#endif + + +// comment for GL :D +#undef HAVE_LIBGDKGLEXT_X11_1_0 #ifdef HAVE_LIBGDKGLEXT_X11_1_0 #include #include @@ -55,6 +67,7 @@ #include "../types.h" #include "../saves.h" #include "desmume.h" +#include "gdk_gl.h" int Frameskip; u16 Keypad_Temp[NB_KEYS]; diff --git a/desmume/src/gtk-glade/main.c b/desmume/src/gtk-glade/main.c index 7ec4f1851..371a3673f 100755 --- a/desmume/src/gtk-glade/main.c +++ b/desmume/src/gtk-glade/main.c @@ -223,6 +223,7 @@ int main(int argc, char *argv[]) { gtk_init(&argc, &argv); #ifdef HAVE_LIBGDKGLEXT_X11_1_0 gtk_gl_init(&argc, &argv); + register_gl_fun(my_gl_Begin,my_gl_End); #endif if(argc == 2) commandLine_File = argv[1]; @@ -251,14 +252,12 @@ int main(int argc, char *argv[]) { pDrawingArea = glade_xml_get_widget(xml, "wDraw_Main"); pDrawingArea2 = glade_xml_get_widget(xml, "wDraw_Sub"); - init_GL_capabilities(pDrawingArea); - init_GL_capabilities(pDrawingArea2); - - /* connect the signals in the interface */ glade_xml_signal_autoconnect(xml); glade_xml_signal_autoconnect(xml_tools); + init_GL_capabilities(); + /* VĂ©rifie la ligne de commandes */ if(commandLine_File) { if(desmume_open(commandLine_File) >= 0) {