From 4080704c88d7a0538eca9e4541f875c033e6bcc7 Mon Sep 17 00:00:00 2001 From: damdoum Date: Tue, 13 Feb 2007 17:50:15 +0000 Subject: [PATCH] blending effect for pause --- .../gtk-glade/dTools/callbacks_4_tileview.c | 103 +++++++++++++++++- .../src/gtk-glade/dTools/callbacks_dtools.h | 2 +- desmume/src/gtk-glade/desmume.c | 3 +- desmume/src/gtk-glade/gdk_gl.c | 46 ++++++-- desmume/src/gtk-glade/gdk_gl.h | 1 + .../src/gtk-glade/glade/DeSmuMe_Dtools.glade | 2 +- desmume/src/gtk-glade/globals.h | 1 + 7 files changed, 140 insertions(+), 18 deletions(-) diff --git a/desmume/src/gtk-glade/dTools/callbacks_4_tileview.c b/desmume/src/gtk-glade/dTools/callbacks_4_tileview.c index 91cf801c9..84f355f77 100755 --- a/desmume/src/gtk-glade/dTools/callbacks_4_tileview.c +++ b/desmume/src/gtk-glade/dTools/callbacks_4_tileview.c @@ -76,8 +76,12 @@ static int colnum=0; static void refresh(); static GtkWidget * wPaint; static GtkSpinButton * wSpin; -static u16 mem[0x100]; +static int gl_context_num=0; +#define TILE_NUM_MAX 1024 +#define TILE_W_SZ 8 +#define TILE_H_SZ 8 +static u16 tiles[TILE_NUM_MAX][TILE_H_SZ*TILE_W_SZ]; static COLOR c; static COLOR32 c32; @@ -89,14 +93,101 @@ static void wtools_4_update() { } - static void refresh() { + u16 palette_16[64]; + u16 palette_256[64]; + u8 * index16 = mem_addr[memnum]; + u8 * index256 = mem_addr[memnum]; + u8 * indexBMP = mem_addr[memnum]; + u16 * pal; + int tile_n, index; + guint Textures; + + return; + + // this little thing doesnt display properly + // quad gets drawn in the wrong place ? + if (!my_gl_Begin(gl_context_num)) return; + my_gl_Identity(); + + glClearColor(0.5,0.5,0.5,1.0); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + my_gl_DrawBeautifulQuad(); + my_gl_End(gl_context_num); + + return; + + + glEnable(GL_TEXTURE_2D); + glGenTextures(1, &Textures); + + //proxy + glBindTexture(GL_TEXTURE_2D, Textures); + glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, + 256, 256, 0, + GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); + + + switch(colnum) { + case 0: //BMP + for (tile_n=0; tile_n> 5)<<3, + 8, 8, GL_RGBA, + GL_UNSIGNED_SHORT_1_5_5_5_REV, indexBMP); + indexBMP +=64; + } + break; + case 1: //256c + if (pal = pal_addr[palindex]) { + pal += palnum*256; + for (tile_n=0; tile_n<1024; tile_n++) { + for (index=0; index<64; index++) { + palette_256[index]=pal[*index256]; + index256++; + } + glTexSubImage2D(GL_TEXTURE_2D, 0, + (tile_n & 0x1F)<<3, (tile_n >> 5)<<3, + 8, 8, GL_RGBA, + GL_UNSIGNED_SHORT_1_5_5_5_REV, palette_256); + } + } + break; + case 2: //16c + if (pal = pal_addr[palindex]) { + pal += palnum*16; + for (tile_n=0; tile_n<1024; tile_n++) { + for (index=0; index<64; index++) { + if (index & 1) continue; + palette_16[index] =pal[*index16 & 15]; + palette_16[index+1]=pal[*index16 >> 4]; + index16++; + } + glTexSubImage2D(GL_TEXTURE_2D, 0, + (tile_n & 0x1F)<<3, (tile_n >> 5)<<3, + 8, 8, GL_RGBA, + GL_UNSIGNED_SHORT_1_5_5_5_REV, palette_16); + } + } + break; + } + + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex2d(-1.0, 1.0); + glTexCoord2f(0.0, 1.0); glVertex2d(-1.0,-1.0); + glTexCoord2f(1.0, 1.0); glVertex2d( 1.0,-1.0); + glTexCoord2f(1.0, 0.0); glVertex2d( 1.0, 1.0); + glEnd(); + + glDeleteTextures(1, &Textures); + my_gl_End(gl_context_num); } static void initialize() { GtkComboBox * combo; if (init) return; + init=TRUE; wPaint= glade_xml_get_widget(xml_tools, "wDraw_Tile"); wSpin = (GtkSpinButton*)glade_xml_get_widget(xml_tools, "wtools_4_palnum"); @@ -104,7 +195,9 @@ static void initialize() { init_combo_palette(combo, pal_addr); combo = (GtkComboBox*)glade_xml_get_widget(xml_tools, "wtools_4_memory"); init_combo_memory(combo, mem_addr); - init=TRUE; + + gl_context_num = init_GL_free(wPaint); + gtk_widget_show(wPaint); } @@ -136,6 +229,10 @@ void on_wtools_4_rXX_toggled (GtkToggleButton *togglebutton, gpointer user_data colnum = dyn_CAST(int,user_data); refresh(); } +gboolean on_wDraw_Tile_expose_event (GtkWidget * w, GdkEventExpose * e, gpointer user_data) { + refresh(); + return TRUE; +} diff --git a/desmume/src/gtk-glade/dTools/callbacks_dtools.h b/desmume/src/gtk-glade/dTools/callbacks_dtools.h index 5e52bd132..32621f81f 100755 --- a/desmume/src/gtk-glade/dTools/callbacks_dtools.h +++ b/desmume/src/gtk-glade/dTools/callbacks_dtools.h @@ -67,5 +67,5 @@ G_MODULE_EXPORT void on_wtools_4_memory_changed (GtkComboBox *, gpoi G_MODULE_EXPORT void on_wtools_4_palette_changed (GtkComboBox *, gpointer ); G_MODULE_EXPORT void on_wtools_4_palnum_value_changed (GtkSpinButton *, gpointer ); G_MODULE_EXPORT void on_wtools_4_rXX_toggled (GtkToggleButton *togglebutton, gpointer user_data); - +G_MODULE_EXPORT gboolean on_wDraw_Tile_expose_event (GtkWidget *, GdkEventExpose *, gpointer ); diff --git a/desmume/src/gtk-glade/desmume.c b/desmume/src/gtk-glade/desmume.c index f95c8c29b..d51accef8 100755 --- a/desmume/src/gtk-glade/desmume.c +++ b/desmume/src/gtk-glade/desmume.c @@ -145,7 +145,8 @@ gboolean EmuLoop(gpointer data) gtk_widget_queue_draw(pDrawingArea2); return TRUE; } - + gtk_widget_queue_draw(pDrawingArea); + gtk_widget_queue_draw(pDrawingArea2); regMainLoop = FALSE; return FALSE; } diff --git a/desmume/src/gtk-glade/gdk_gl.c b/desmume/src/gtk-glade/gdk_gl.c index 4bdf8c121..07e886389 100755 --- a/desmume/src/gtk-glade/gdk_gl.c +++ b/desmume/src/gtk-glade/gdk_gl.c @@ -39,16 +39,15 @@ GtkWidget *pDrawingTexArea; #undef _DUP4 #undef _DUP2 -INLINE void my_gl_Identity() { +void my_gl_Identity() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } -INLINE void my_gl_DrawBeautifulQuad() { +void my_gl_DrawBeautifulQuad() { // beautiful quad - glColor4ub(255,255,255,128); glBegin(GL_QUADS); glColor3ub(255,0,0); glVertex2d(-0.75,-0.75); glColor3ub(128,255,0); glVertex2d(-0.75, 0.75); @@ -58,6 +57,13 @@ INLINE void my_gl_DrawBeautifulQuad() { glColor3ub(255,255,255); } + +void my_gl_DrawLogo() { + + +} + + BOOL my_gl_Begin (int screen) { return gdk_gl_drawable_gl_begin(my_glDrawable[screen], my_glContext[screen]); } @@ -75,6 +81,7 @@ void my_gl_Clear(int screen) { /* Set the background black */ glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClearDepth(1.0); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); my_gl_DrawBeautifulQuad(); @@ -86,7 +93,9 @@ void init_GL(GtkWidget * widget, int screen, int share_num) { // init GL capability if (!gtk_widget_set_gl_capability( widget, my_glConfig, - &my_glContext[share_num], TRUE, + my_glContext[share_num], + //NULL, + TRUE, GDK_GL_RGBA_TYPE)) { printf ("gtk_widget_set_gl_capability\n"); exit(1); @@ -94,7 +103,7 @@ void init_GL(GtkWidget * widget, int screen, int share_num) { // realize so that we get a GdkWindow gtk_widget_realize(widget); // make sure we realize - while (gtk_events_pending()) gtk_main_iteration(); +// while (gtk_events_pending()) gtk_main_iteration(); my_glDrawable[screen] = gtk_widget_get_gl_drawable(widget); if (screen == share_num) { @@ -160,7 +169,9 @@ INLINE void my_gl_Texture2D() { } INLINE void my_gl_ScreenTex() { - glTexImage2D(GL_TEXTURE_2D, 0, 4, +// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, +// pause effect + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 512, 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, // GL_UNSIGNED_SHORT_5_5_5_1, @@ -172,9 +183,9 @@ void my_gl_ScreenTexApply(int screen) { 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); + glTexCoord2f(1.0, off+0.375); glVertex2d( 1.0,-1.0); + glTexCoord2f(0.0, off+0.375); glVertex2d(-1.0,-1.0); glEnd(); } @@ -188,12 +199,16 @@ gboolean screen (GtkWidget * widget, int viewportscreen) { if (!my_gl_Begin(viewportscreen)) return TRUE; - glLoadIdentity(); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); +// glLoadIdentity(); - my_gl_DrawBeautifulQuad(); + glEnable(GL_TEXTURE_2D); +// glEnable(GL_BLEND); +// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); if (desmume_running()) { + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glColor4ub(255,255,255,255); // rotate glRotatef(ScreenRotate, 0.0, 0.0, 1.0); // draw screen @@ -201,8 +216,15 @@ gboolean screen (GtkWidget * widget, int viewportscreen) { if (viewportscreen==0) { my_gl_ScreenTex(); } - my_gl_ScreenTexApply(screen); + } else { + // background color black + glClearColor(0.0f, 0.0f, 0.0f, 0.5f); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glColor4f(0.5f,0.5f,0.5f,0.5f); } + my_gl_ScreenTexApply(screen); + glDisable(GL_TEXTURE_2D); +// glDisable(GL_BLEND); my_gl_End(viewportscreen); return TRUE; } diff --git a/desmume/src/gtk-glade/gdk_gl.h b/desmume/src/gtk-glade/gdk_gl.h index d740b49bb..93434cf6c 100755 --- a/desmume/src/gtk-glade/gdk_gl.h +++ b/desmume/src/gtk-glade/gdk_gl.h @@ -33,6 +33,7 @@ BOOL my_gl_Begin (int screen); void my_gl_End (int screen); void my_gl_Clear(int screen); +void my_gl_DrawBeautifulQuad(); void init_GL_capabilities(); void init_GL(GtkWidget * widget, int screen, int share_num); diff --git a/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade b/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade index 767357a3a..15eb9adf9 100755 --- a/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade +++ b/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade @@ -609,7 +609,7 @@ ARM7 cpu 256 256 GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK - + 0 diff --git a/desmume/src/gtk-glade/globals.h b/desmume/src/gtk-glade/globals.h index f1b1d4c8a..956f71449 100755 --- a/desmume/src/gtk-glade/globals.h +++ b/desmume/src/gtk-glade/globals.h @@ -112,6 +112,7 @@ typedef void (*VoidFunPtr)(); void notify_Tools(); void register_Tool(VoidFunPtr fun); void unregister_Tool(VoidFunPtr fun); +gchar * get_ui_file (const char *filename); /* callbacks.c */ void enable_rom_features();