diff src/projectm-1.0/video_init.cxx @ 1924:725b5f3f0242

branch merge
author Ralf Ertzinger <ralf@skytale.net>
date Sun, 30 Sep 2007 21:34:41 +0200
parents a6d84a2cfaa7
children 47a4e93ed7ce
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/projectm-1.0/video_init.cxx	Sun Sep 30 21:34:41 2007 +0200
@@ -0,0 +1,156 @@
+//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() {
+  printf("quitting\n");
+  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 *fvw, int *fvh, 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;
+  }
+  
+  printf("Screen Resolution: %d x %d\n", info->current_w, info->current_h);
+  *fvw = info->current_w;
+  *fvh = info->current_h;
+  printf("set fvw and fvw\n");
+  bpp = info->vfmt->BitsPerPixel;
+  printf("set bpp\n");
+  //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 );
+  printf("set gl attributes\n");
+  if (f==0)
+     flags = SDL_OPENGL|SDL_HWSURFACE|SDL_RESIZABLE;
+  else flags = SDL_OPENGL|SDL_HWSURFACE|SDL_FULLSCREEN;
+ printf("set gl attributes2\n");
+  screen= SDL_SetVideoMode( w, h, bpp, flags ) ;
+ printf("set screen\n");
+  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;
+    
+  }
+  
+  printf("video init done\n");
+  // 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);
+  
+    
+}
+