changeset 358:bc3bae2880ec trunk

[svn] - add support for projectM
author nenolod
date Sun, 10 Dec 2006 22:50:34 -0800
parents c4b4c6011c66
children 2d13a1d0b7b6
files ChangeLog configure.ac mk/rules.mk.in src/projectm/Makefile src/projectm/main.c src/projectm/sdltoprojectM.h src/projectm/video_init.c src/projectm/video_init.h
diffstat 8 files changed, 867 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Dec 10 22:10:32 2006 -0800
+++ b/ChangeLog	Sun Dec 10 22:50:34 2006 -0800
@@ -1,3 +1,11 @@
+2006-12-11 06:10:32 +0000  Yoshiki Yazawa <yaz@cc.rim.or.jp>
+  revision [782]
+  - fix for potential bug.
+  
+  trunk/src/cue/cuesheet.c |    2 +-
+  1 file changed, 1 insertion(+), 1 deletion(-)
+
+
 2006-12-11 04:33:47 +0000  Yoshiki Yazawa <yaz@cc.rim.or.jp>
   revision [780]
   cuesheet improvement:
--- a/configure.ac	Sun Dec 10 22:10:32 2006 -0800
+++ b/configure.ac	Sun Dec 10 22:50:34 2006 -0800
@@ -966,9 +966,29 @@
 	VISUALIZATION_PLUGINS="$VISUALIZATION_PLUGINS paranormal"
 fi
 
-if test "$have_xspf" = "yes"; then
-	CONTAINER_PLUGINS="$CONTAINER_PLUGINS xspf"
-	AC_DEFINE(HAVE_XSPF_PLAYLIST, 1, [Define if XSPF playlists are available.])
+dnl *** ProjectM (GL Milkdrop port)
+
+AC_ARG_ENABLE(projectm,
+[  --disable-projectm          disable projectM vis plugin. (default=enabled)],
+[have_projectm=$enableval],
+[have_projectm=yes])
+
+if test "$have_projectm" = "yes"; then
+	PKG_CHECK_MODULES(LIBPROJECTM, libprojectM >= 0.0.0, [have_projectm="yes"], [have_projectm="no"])
+	if test x$libprjM = xno; then
+	        AC_MSG_WARN([*** libprojectM not found.
+	                        libprojectM is needed to build this package.
+	                        You can download libprojectM at http://xmms-projectM.sf.net/])
+	fi
+	LIBPROJECTM_datadir=`pkg-config --variable=pkgdatadir libprojectM`;
+	LIBPROJECTM_sysconfdir=`pkg-config --variable=sysconfdir libprojectM`;
+	LIBPROJECTM_CFLAGS="$LIBPROJECTM_CFLAGS -DPROJECTM_DATADIR=\\\"$LIBPROJECTM_datadir\\\" -DPROJECTM_SYSCONFDIR=\\\"$LIBPROJECTM_sysconfdir\\\"";
+fi
+AC_SUBST(LIBPROJECTM_LIBS)
+AC_SUBST(LIBPROJECTM_CFLAGS)
+
+if test "$have_projectm" = "yes"; then
+	VISUALIZATION_PLUGINS="$VISUALIZATION_PLUGINS projectm"
 fi
 
 dnl *** TTA
@@ -1127,6 +1147,7 @@
 echo "  Blur Scope:                             yes"
 echo "  Spectrum Analyzer:                      yes"
 echo "  Paranormal Visualization Library:       $have_paranormal"
+echo "  ProjectM (GL milkdrop):                 $have_projectm"
 echo
 echo "  Container"
 echo "  ---------"
--- a/mk/rules.mk.in	Sun Dec 10 22:10:32 2006 -0800
+++ b/mk/rules.mk.in	Sun Dec 10 22:50:34 2006 -0800
@@ -337,3 +337,5 @@
 WAVPACK_LIBS ?= @WAVPACK_LIBS@
 XXF86VM_CFLAGS ?= @XXF86VM_CFLAGS@
 XXF86VM_LIBS ?= @XXF86VM_LIBS@
+LIBPROJECTM_CFLAGS ?= @LIBPROJECTM_CFLAGS@
+LIBPROJECTM_LIBS ?= @LIBPROJECTM_LIBS@
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/projectm/Makefile	Sun Dec 10 22:50:34 2006 -0800
@@ -0,0 +1,16 @@
+include ../../mk/rules.mk
+include ../../mk/init.mk
+
+OBJECTIVE_LIBS = libprojectm$(SHARED_SUFFIX)
+
+LIBDIR = $(plugindir)/$(VISUALIZATION_PLUGIN_DIR)
+
+LIBADD = $(GTK_LIBS) $(SDL_LIBS) $(LIBPROJECTM_LIBS) -lprojectM
+
+SOURCES = main.c video_init.c
+
+OBJECTS = ${SOURCES:.c=.o}
+
+CFLAGS += $(PICFLAGS) $(GTK_CFLAGS) $(ARCH_DEFINES) $(XML_CPPFLAGS) $(SDL_CFLAGS) $(LIBPROJECTM_CFLAGS) -I../../intl -I../..
+
+include ../../mk/objective.mk
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/projectm/main.c	Sun Dec 10 22:50:34 2006 -0800
@@ -0,0 +1,466 @@
+/* 
+xmms-projectM v0.99 - xmms-projectm.sourceforge.net
+--------------------------------------------------
+
+Lead Developers:  Carmelo Piccione (cep@andrew.cmu.edu) &
+                  Peter Sperl (peter@sperl.com)
+
+We have also been advised by some professors at CMU, namely Roger B. Dannenberg.
+http://www-2.cs.cmu.edu/~rbd/    
+  
+The inspiration for this program was Milkdrop by Ryan Geiss. Obviously. 
+
+This code is distributed under the GPL.
+
+
+THANKS FOR THE CODE!!!
+-------------------------------------------------
+The base for this program was andy@nobugs.org's XMMS plugin tutorial
+http://www.xmms.org/docs/vis-plugin.html
+
+We used some FFT code by Takuya OOURA instead of XMMS' built-in fft code
+fftsg.c - http://momonga.t.u-tokyo.ac.jp/~ooura/fft.html
+
+For font rendering we used GLF by Roman Podobedov
+glf.c - http://astronomy.swin.edu.au/~pbourke/opengl/glf/
+
+and some beat detection code was inspired by Frederic Patin @
+www.gamedev.net/reference/programming/features/beatdetection/
+
+*/
+
+
+#include <stdio.h>
+#include <audacious/plugin.h>
+#include <string.h>
+#include <stdlib.h>
+#include <gtk/gtk.h>
+#include <audacious/util.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_thread.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include <audacious/beepctrl.h>
+#include <math.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <projectM/projectM.h>
+#include <projectM/console_interface.h>
+#include "sdltoprojectM.h"
+#include "video_init.h"
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+#define CONFIG_FILE "/config"
+#define PRESETS_DIR "/presets"
+#define FONTS_DIR "/fonts"
+
+// Forward declarations 
+static void projectM_xmms_init(void); 
+static void projectM_cleanup(void);
+static void projectM_about(void);
+static void projectM_configure(void);
+static void projectM_playback_start(void);
+static void projectM_playback_stop(void);
+static void projectM_render_pcm(gint16 pcm_data[2][512]);
+static void projectM_render_freq(gint16 pcm_data[2][256]);
+void read_config();
+
+
+//extern preset_t * active_preset;
+
+// Callback functions
+VisPlugin projectM_vtable = {
+  NULL, // Handle, filled in by xmms
+  NULL, // Filename, filled in by xmms
+  0,                     // Session ID
+  "projectM v0.99",       // description
+  2, // # of PCM channels for render_pcm()
+  0, // # of freq channels wanted for render_freq()
+  projectM_xmms_init,     // Called when plugin is enabled
+  projectM_cleanup,        // Called when plugin is disabled
+  projectM_about,          // Show the about box
+  projectM_configure,      // Show the configure box
+  NULL,                     // Called to disable plugin, filled in by xmms
+  projectM_playback_start, // Called when playback starts
+  projectM_playback_stop,  // Called when playback stops
+  projectM_render_pcm,      // Render the PCM data, must return quickly
+  projectM_render_freq     // Render the freq data, must return quickly
+};
+
+// XMMS entry point
+VisPlugin *get_vplugin_info(void)
+{
+  return &projectM_vtable;
+}
+
+// Our worker thread
+SDL_Thread *worker_thread;
+
+SDL_mutex *mutex;
+
+SDL_sem *sem;
+
+SDL_Event event;
+
+SDL_Surface *screen;
+//SDL_RenderTarget *RenderTarget = NULL;
+//GLuint RenderTargetTextureID;
+
+projectM_t *globalPM = NULL;
+
+int maxsamples=512;
+
+int texsize=512;
+int gx=32,gy=24;
+int wvw=640,wvh=480;
+int fvw=1280,fvh=960;
+int fps=30, fullscreen=0;
+char *disp;
+
+int disable_projectm(void) {
+	projectM_vtable.disable_plugin(&projectM_vtable);
+	return 0;
+}
+
+int get_xmms_title(void) {
+	static char check_title = 1;
+	static int last_pos;
+	static char *last_title = NULL;
+	int pos;
+	char *title = NULL;
+
+	//Nice optimization, but we want the title no matter what so I can display it when the song changes
+#if 0
+	if(!(globalPM->showtitle%2)) {
+		/* Repeat less often when not showing title */
+		return 1000;
+	}
+#endif
+
+	pos = xmms_remote_get_playlist_pos(projectM_vtable.xmms_session);
+	/* Only check every 1 second for title change, otherwise check pos */
+	if(check_title || pos != last_pos) {
+		title = xmms_remote_get_playlist_title(
+				projectM_vtable.xmms_session, pos);
+		if(title && (!last_title || strcmp(last_title,title))) {
+			globalPM->title = title;
+			globalPM->drawtitle = 1;
+			g_free(last_title);
+			last_title = title;
+		} else if(title && last_title != title) {
+			/* New copy of last title */
+			g_free(title);
+		}
+		check_title = !check_title;
+	}
+	last_pos = pos;
+	/* Repeat every 500ms */
+	return 500;
+}
+
+void worker_func()
+{ 
+  char projectM_data[PATH_MAX];
+ 
+  SDL_TimerID title_timer = NULL;
+
+ 
+  read_config();
+ 
+  init_display(wvw,wvh,fullscreen);
+
+  SDL_WM_SetCaption("projectM v0.99", "projectM v0.99");
+ 
+
+  /** Initialise projectM */
+    
+  globalPM = (projectM_t *)malloc( sizeof( projectM_t ) );
+
+  projectM_reset( globalPM );
+  
+  globalPM->fullscreen = fullscreen;
+  globalPM->renderTarget->texsize = texsize;
+  globalPM->gx=gx;
+  globalPM->gy=gy;
+  globalPM->fps=fps;
+  globalPM->renderTarget->usePbuffers=0;
+  
+  strcpy(projectM_data, PROJECTM_DATADIR);
+  strcpy(projectM_data+strlen(PROJECTM_DATADIR), FONTS_DIR);
+  projectM_data[strlen(PROJECTM_DATADIR)+strlen(FONTS_DIR)]='\0';
+  
+  globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 );
+  strcpy( globalPM->fontURL, projectM_data );
+  
+  strcpy(projectM_data+strlen(PROJECTM_DATADIR), PRESETS_DIR);
+  projectM_data[strlen(PROJECTM_DATADIR)+strlen(PRESETS_DIR)]='\0';
+  
+  globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 );
+  strcpy( globalPM->presetURL, projectM_data );
+  
+  
+  projectM_init( globalPM );
+  
+  projectM_resetGL( globalPM, wvw, wvh );
+
+  title_timer = SDL_AddTimer(500, get_xmms_title, NULL);
+   
+    /** Initialise the thread */
+ 
+    SDL_SemTryWait(sem);
+ while ( SDL_SemTryWait(sem) ) {
+        projectMEvent evt;
+        projectMKeycode key;
+        projectMModifier mod;
+
+        /** Process SDL events */
+        SDL_Event event;
+        while ( SDL_PollEvent( &event ) ) {
+            /** Translate into projectM codes and process */
+            evt = sdl2pmEvent( event );
+            key = sdl2pmKeycode( event.key.keysym.sym );
+            mod = sdl2pmModifier( event.key.keysym.mod );
+
+            if ( evt == PROJECTM_KEYDOWN ) {                 
+     
+
+                if(key == SDLK_f)
+                {
+                    int w, h;
+                    if (fullscreen == 0) {
+                        w = fvw;
+                        h = fvh;
+                    } else {
+                        w = wvw;
+                        h = wvh;
+                    }
+                    globalPM->fullscreen = fullscreen ^= 1;
+                    resize_display(w, h, fullscreen);
+                    projectM_resetGL( globalPM, w, h ); 
+                }
+                else  key_handler(globalPM,evt,key,mod);
+
+            }
+            else if ( evt == PROJECTM_VIDEORESIZE )
+            {
+                wvw=event.resize.w;
+                wvh=event.resize.h;
+                resize_display(wvw, wvh, 0);
+                projectM_resetGL( globalPM, wvw, wvh ); 
+
+            } 
+            else if ( evt == PROJECTM_VIDEOQUIT ) {
+
+	(void) gtk_idle_add (disable_projectm, NULL);
+	/*				if(quit_timer == NULL)
+	                quit_timer = SDL_AddTimer(500, disable_projectm, NULL);*/
+            }
+
+        }
+             
+
+        /** Render the new frame */
+
+	renderFrame( globalPM );
+ 
+        SDL_GL_SwapBuffers();
+      }
+
+ 
+		
+  printf("Worker thread: Exiting\n"); 
+  if(title_timer) SDL_RemoveTimer(title_timer);
+  g_free(globalPM->title);
+  free(globalPM->presetURL);
+  free(globalPM->fontURL);
+  free(globalPM);
+  close_display();
+}
+
+static void projectM_xmms_init(void) 
+{
+  
+  printf("projectM plugin: Initializing\n");
+
+  SDL_EnableUNICODE(1); 
+  
+  mutex = SDL_CreateMutex();
+
+  sem = SDL_CreateSemaphore(1);
+
+  worker_thread = SDL_CreateThread ((void *) worker_func, NULL);
+ 
+}
+
+
+
+static void projectM_cleanup(void)
+{
+   
+    SDL_SemPost(sem);
+    SDL_WaitThread(worker_thread, NULL);
+
+    SDL_DestroySemaphore(sem);
+    printf("Destroy Semaphore\n");
+    SDL_DestroyMutex(mutex);
+    printf("Destroy Mutex\n");
+  
+    printf("projectM plugin: Cleanup completed\n");
+}
+static void projectM_about(void)
+{
+  printf("projectM plugin: About\n");
+}
+static void projectM_configure(void)
+{
+  printf("projectM plugin: Configure\n");
+}
+static void projectM_playback_start(void)
+{
+  printf("projectM plugin: Playback starting\n");
+}
+static void projectM_playback_stop(void)
+{
+  printf("projectM plugin: Playback stopping\n");
+}
+static void projectM_render_pcm(gint16 pcm_data[2][512])
+{
+
+    if (0 < SDL_SemValue(sem)) return;
+  	SDL_mutexP(mutex);
+       
+        addPCM16Data(pcm_data,512);
+	 
+	SDL_mutexV(mutex);
+	
+}
+
+static void projectM_render_freq(gint16 freq_data[2][256])
+{
+  printf("NO GOOD\n");
+ }
+
+
+void read_config()
+{
+
+   int n;
+   
+   char num[80];
+   FILE *in; 
+   FILE *out;
+
+   char* home;
+   char projectM_home[PATH_MAX];
+   char projectM_config[PATH_MAX];
+
+   strcpy(projectM_config, PROJECTM_DATADIR);
+   strcpy(projectM_config+strlen(PROJECTM_DATADIR), CONFIG_FILE);
+   projectM_config[strlen(PROJECTM_DATADIR)+strlen(CONFIG_FILE)]='\0';
+
+   home=getenv("HOME");
+   strcpy(projectM_home, home);
+   strcpy(projectM_home+strlen(home), "/.projectM/config");
+   projectM_home[strlen(home)+strlen("/.projectM/config")]='\0';
+
+  
+ if ((in = fopen(projectM_home, "r")) != 0) 
+   {
+     printf("reading ~/.projectM/config \n");
+   }
+ else
+   {
+     printf("trying to create ~/.projectM/config \n");
+
+     strcpy(projectM_home, home);
+     strcpy(projectM_home+strlen(home), "/.projectM");
+     projectM_home[strlen(home)+strlen("/.projectM")]='\0';
+     mkdir(projectM_home,0755);
+
+     strcpy(projectM_home, home);
+     strcpy(projectM_home+strlen(home), "/.projectM/config");
+     projectM_home[strlen(home)+strlen("/.projectM/config")]='\0';
+     
+     if((out = fopen(projectM_home,"w"))!=0)
+       {
+	
+	 if ((in = fopen(projectM_config, "r")) != 0) 
+	   {
+	     
+	     while(fgets(num,80,in)!=NULL)
+	       {
+		 fputs(num,out);
+	       }
+	     fclose(in);
+	     fclose(out);
+	    
+
+	     if ((in = fopen(projectM_home, "r")) != 0) 
+	       { printf("created ~/.projectM/config successfully\n");  }
+	     else{printf("This shouldn't happen, using implementation defualts\n");return;}
+	   }
+	 else{printf("Cannot find projectM default config, using implementation defaults\n");return;}
+       }
+     else
+       {
+	 printf("Cannot create ~/.projectM/config, using default config file\n");
+	 if ((in = fopen(projectM_config, "r")) != 0) 
+	   { printf("Successfully opened default config file\n");}
+	 else{ printf("Using implementation defaults, your system is really messed up, I'm suprised we even got this far\n");	   return;}
+	   
+       }
+
+   }
+
+
+
+     fgets(num, 80, in);  fgets(num, 80, in);  fgets(num, 80, in);
+     if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &texsize);  
+
+     fgets(num, 80, in);
+     if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &gx);  
+
+     fgets(num, 80, in);
+     if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &gy);   
+
+     fgets(num, 80, in);
+     if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &wvw);  
+
+     fgets(num, 80, in);
+     if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &wvh);  
+
+     fgets(num, 80, in);
+     if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fvw);  
+
+     fgets(num, 80, in);
+     if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fvh);  
+
+     fgets(num, 80, in);
+     if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fps);
+
+     fgets(num, 80, in);
+     if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fullscreen);
+     /*
+     fgets(num, 80, in);
+     fgets(num, 80, in);
+     
+     n=0;
+     while (num[n]!=' ' && num[n]!='\n' && n < 80 && num[n]!=EOF)
+       {
+	 	 disp[n]=num[n];
+		 n++;
+       }
+     disp[n]=0;
+
+    
+     // sprintf(disp,"%s",num );
+      setenv("DISPLAY",disp,1);
+      printf("%s %d\n", disp,strlen(disp));
+      setenv("LD_PRELOAD", "/usr/lib/tls/libGL.so.1.0.4496", 1);
+     */
+   fclose(in); 
+  
+} 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/projectm/sdltoprojectM.h	Sun Dec 10 22:50:34 2006 -0800
@@ -0,0 +1,148 @@
+/**
+ * $Id: sdltoprojectM.h,v 1.1.1.1 2005/12/23 18:42:00 psperl Exp $
+ *
+ * Translates SDL -> projectM variables
+ *
+ * $Log: sdltoprojectM.h,v $
+ * Revision 1.1.1.1  2005/12/23 18:42:00  psperl
+ * Initial Import
+ *
+ * Revision 1.1  2004/10/08 00:35:28  cvs
+ * Moved and imported
+ *
+ * Revision 1.1.1.1  2004/10/04 12:56:00  cvs
+ * Imported
+ *
+ */
+
+#ifndef _SDLTOPROJECTM_H
+#define _SDLTOPROJECTM_H
+
+#include "projectM/event.h"
+#ifdef WIN32
+#include <SDL.h>
+#else
+#include <SDL/SDL.h>
+#endif
+
+projectMEvent sdl2pmEvent( SDL_Event event ) { \
+							
+    switch ( event.type ) { \
+        case SDL_VIDEORESIZE:
+            return PROJECTM_VIDEORESIZE; \
+        case SDL_KEYUP: \
+            return PROJECTM_KEYUP; \
+        case SDL_KEYDOWN: \
+            return PROJECTM_KEYDOWN; \
+        case SDL_QUIT: \
+            return PROJECTM_VIDEOQUIT; \
+        default:
+            return PROJECTM_KEYUP; \
+      } \
+  } \
+
+projectMKeycode sdl2pmKeycode( SDLKey keysym ) { \
+    switch ( keysym ) { \
+        case SDLK_F1: \
+            return PROJECTM_K_F1; \
+        case SDLK_F2: \
+            return PROJECTM_K_F2; \
+        case SDLK_F3: \
+            return PROJECTM_K_F3; \
+        case SDLK_F4: \
+            return PROJECTM_K_F4; \
+        case SDLK_F5: \
+            return PROJECTM_K_F5; \
+        case SDLK_F6: \
+            return PROJECTM_K_F6; \
+        case SDLK_F7: \
+            return PROJECTM_K_F7; \
+        case SDLK_F8: \
+            return PROJECTM_K_F8; \
+        case SDLK_F9: \
+            return PROJECTM_K_F9; \
+        case SDLK_F10: \
+            return PROJECTM_K_F10; \
+        case SDLK_F11: \
+            return PROJECTM_K_F11; \
+        case SDLK_F12: \
+            return PROJECTM_K_F12; \
+	  case SDLK_ESCAPE: \
+	    return PROJECTM_K_ESCAPE; 
+    case SDLK_a:
+      return PROJECTM_K_a;
+    case SDLK_b:
+      return PROJECTM_K_b;
+    case SDLK_c:  
+      return PROJECTM_K_c;
+    case SDLK_d: 
+      return PROJECTM_K_d; 
+    case SDLK_e:
+      return PROJECTM_K_e; 
+    case SDLK_f: 
+      return PROJECTM_K_f; 
+    case SDLK_g: 
+      return PROJECTM_K_g; 
+    case SDLK_h: 
+      return PROJECTM_K_h; 
+    case SDLK_i: 
+      return PROJECTM_K_i; 
+    case SDLK_j:
+      return PROJECTM_K_j;
+    case SDLK_k:
+      return PROJECTM_K_k;
+    case SDLK_l:  
+      return PROJECTM_K_l;
+    case SDLK_m: 
+      return PROJECTM_K_m; 
+    case SDLK_n:
+      return PROJECTM_K_n; 
+    case SDLK_o: 
+      return PROJECTM_K_o; 
+    case SDLK_p: 
+      return PROJECTM_K_p; 
+    case SDLK_q: 
+      return PROJECTM_K_q; 
+    case SDLK_r: 
+      return PROJECTM_K_r; 
+    case SDLK_s: 
+      return PROJECTM_K_s; 
+    case SDLK_t:
+      return PROJECTM_K_t; 
+    case SDLK_u: 
+      return PROJECTM_K_u; 
+    case SDLK_v: 
+      return PROJECTM_K_v; 
+    case SDLK_w: 
+      return PROJECTM_K_w; 
+    case SDLK_x: 
+      return PROJECTM_K_x; 
+    case SDLK_y: 
+      return PROJECTM_K_y; 
+    case SDLK_z: 
+      return PROJECTM_K_z; 
+    case SDLK_UP:
+      return PROJECTM_K_UP;
+    case SDLK_RETURN:
+      return PROJECTM_K_RETURN;
+    case SDLK_RIGHT:
+      return PROJECTM_K_RIGHT;
+    case SDLK_LEFT:
+      return PROJECTM_K_LEFT;
+    case SDLK_DOWN:
+      return PROJECTM_K_DOWN;
+    case SDLK_PAGEUP:
+      return PROJECTM_K_PAGEUP;
+    case SDLK_PAGEDOWN:
+      return PROJECTM_K_PAGEDOWN;
+   
+        default: \
+            return PROJECTM_K_NONE; \
+      } \
+  } \
+
+projectMModifier sdl2pmModifier( SDLMod mod ) { \
+    return PROJECTM_KMOD_LSHIFT; \
+  } \
+
+#endif /** _SDLTOPROJECTM_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/projectm/video_init.c	Sun Dec 10 22:50:34 2006 -0800
@@ -0,0 +1,198 @@
+//video_init.c - SDL/Opengl Windowing Creation/Resizing Functions
+//
+//by Peter Sperl
+//
+//Opens an SDL Window and creates an OpenGL session
+//also able to handle resizing and fullscreening of windows
+//just call init_display again with differant variables
+
+#include <SDL/SDL.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+
+extern SDL_Surface *screen;
+extern int texsize;
+void setup_opengl( int w, int h );
+
+void close_display() {
+  SDL_Quit();
+}
+
+void resize_display(int w, int h, int f) {
+  int flags;
+  if (f) flags =  SDL_OPENGL|SDL_HWSURFACE|SDL_FULLSCREEN;
+  else   flags =  SDL_OPENGL|SDL_HWSURFACE|SDL_RESIZABLE;
+//  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
+  screen = SDL_SetVideoMode( w, h, 0, flags ) ;
+  if(screen == 0 ) {
+      fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) );
+      return;
+  }
+  setup_opengl(w,h);
+  SDL_ShowCursor(f ? SDL_DISABLE : SDL_ENABLE);
+}
+
+//init_display
+//
+//Sets screen to new width and height (w,h)
+//Also switches between fullscreen and windowed
+//with the boolean f (fullscreen)
+void init_display(int w, int h, int f)
+{
+  
+  /* Information about the current video settings. */
+  const SDL_VideoInfo* info = NULL;
+  int bpp = 0;
+  /* Flags we will pass into SDL_SetVideoMode. */
+  int flags = 0;
+  /* First, initialize SDL's video subsystem. */
+  if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 ) {
+    /* Failed, exit. */
+    fprintf( stderr, "Video initialization failed: %s\n",
+             SDL_GetError( ) );
+    //projectM_vtable.disable_plugin (&projectM_vtable);
+    return;
+    
+  }
+  /* Let's get some video information. */
+  info = SDL_GetVideoInfo( );
+  if( !info ) {
+    /* This should probably never happen. */
+    fprintf( stderr, "Video query failed: %s\n",
+             SDL_GetError( ) );
+    //    projectM_vtable.disable_plugin (&projectM_vtable);
+    return;
+  }
+  
+  bpp = info->vfmt->BitsPerPixel;
+  
+  //SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
+  //SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
+  //SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
+
+  // SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 8 );
+  //  SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 8 );
+  //  SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 8 );
+  SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
+  SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
+  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
+
+  if (f==0)
+     flags = SDL_OPENGL|SDL_HWSURFACE|SDL_RESIZABLE;
+  else flags = SDL_OPENGL|SDL_HWSURFACE|SDL_FULLSCREEN;
+
+  screen= SDL_SetVideoMode( w, h, bpp, flags ) ;
+
+  if(screen == 0 ) {
+    /* 
+     * This could happen for a variety of reasons,
+     * including DISPLAY not being set, the specified
+     * resolution not being available, etc.
+     */
+   fprintf( stderr, "Video mode set failed: %s\n",
+	     SDL_GetError( ) );
+    
+   // projectM_vtable.disable_plugin (&projectM_vtable);
+    return;
+    
+  }
+  
+  
+  // setup_opengl(w,h);
+  //gluOrtho2D(0, w, 0, h);
+}
+
+
+ void setup_opengl( int w, int h )
+{
+   
+    /* Our shading model--Gouraud (smooth). */
+     glShadeModel( GL_SMOOTH);
+    /* Culling. */
+    //    glCullFace( GL_BACK );
+    //    glFrontFace( GL_CCW );
+    //    glEnable( GL_CULL_FACE );
+    /* Set the clear color. */
+    glClearColor( 0, 0, 0, 0 );
+    /* Setup our viewport. */
+     glViewport( 0, 0, w, h );
+    /*
+     * Change to the projection matrix and set
+     * our viewing volume.
+     */
+    glMatrixMode(GL_TEXTURE);
+    glLoadIdentity();
+    
+    //    gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height);
+    glMatrixMode(GL_PROJECTION);
+    glLoadIdentity();  
+   
+    //    glFrustum(0.0, height, 0.0,width,10,40);
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
+
+glDrawBuffer(GL_BACK); 
+  glReadBuffer(GL_BACK); 
+  glEnable(GL_BLEND); 
+
+     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
+     // glBlendFunc(GL_SRC_ALPHA, GL_ONE); 
+  glEnable(GL_LINE_SMOOTH);
+  glEnable(GL_POINT_SMOOTH);
+  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+  glClear(GL_COLOR_BUFFER_BIT);
+ 
+  // glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,texsize,texsize,0);
+  //glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,texsize,texsize);
+   glLineStipple(2, 0xAAAA);
+  
+    
+}
+#if 0
+void CreateRenderTarget(int texsize,int *RenderTargetTextureID, int *RenderTarget )
+{
+    /* Create the texture that will be bound to the render target */
+    glGenTextures(1, RenderTargetTextureID);
+    glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+    /* Create the render target */
+    *RenderTarget = SDL_GL_CreateRenderTarget(texsize,texsize, NULL);
+        if ( *RenderTarget ) {
+    
+	int value;
+	//printf("Created render target:\n");
+	SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_RED_SIZE, &value );
+	//	printf( "SDL_GL_RED_SIZE: %d\n", value);
+	SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_GREEN_SIZE, &value );
+	//	printf( "SDL_GL_GREEN_SIZE: %d\n", value);
+	SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_BLUE_SIZE, &value );
+	//	printf( "SDL_GL_BLUE_SIZE: %d\n", value);
+	SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_ALPHA_SIZE, &value );
+	//	printf( "SDL_GL_ALPHA_SIZE: %d\n", value);
+	SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_DEPTH_SIZE, &value );
+	//	printf( "SDL_GL_DEPTH_SIZE: %d\n", value );
+
+	SDL_GL_BindRenderTarget(*RenderTarget, *RenderTargetTextureID);
+       
+    } else {
+        /* We can fake a render target in this demo by rendering to the
+         * screen and copying to a texture before we do normal rendering.
+         */
+	printf("Failed to create render target, using screen buffer\n");
+
+        glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
+        glTexImage2D(GL_TEXTURE_2D,
+			0,
+			GL_RGB,
+			texsize, texsize,
+			0,
+			GL_RGB,
+			GL_UNSIGNED_BYTE,
+			NULL);
+    }
+
+
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/projectm/video_init.h	Sun Dec 10 22:50:34 2006 -0800
@@ -0,0 +1,5 @@
+ void setup_opengl( int w, int h );
+ void init_display( int w, int h, int fullscreen );
+ 
+
+void CreateRenderTarget(int texsize,int *RenderTargetTextureID, int *RenderTarget);