1 //video_init.c - SDL/Opengl Windowing Creation/Resizing Functions
2 //
3 //by Peter Sperl
4 //
5 //Opens an SDL Window and creates an OpenGL session
6 //also able to handle resizing and fullscreening of windows
7 //just call init_display again with differant variables
8 
9 #include <SDL/SDL.h>
10 #include <GL/gl.h>
11 #include <GL/glu.h>
12 #include "video_init.h"
13 #include <iostream>
14 extern SDL_Surface *screen;
15 extern int texsize;
16 
resize_display(int w,int h,int f)17 void resize_display(int w, int h, int f) {
18   int flags;
19   if (f) flags =  SDL_OPENGL|SDL_HWSURFACE|SDL_FULLSCREEN;
20   else   flags =  SDL_OPENGL|SDL_HWSURFACE|SDL_RESIZABLE;
21 //  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
22   screen = SDL_SetVideoMode( w, h, 0, flags ) ;
23   if(screen == 0 ) {
24       fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) );
25       return;
26   }
27 
28   SDL_ShowCursor(f ? SDL_DISABLE : SDL_ENABLE);
29 }
30 
31 //init_display
32 //
33 //Sets screen to new width and height (w,h)
34 //Also switches between fullscreen and windowed
35 //with the boolean f (fullscreen)
init_display(int w,int h,int * fvw,int * fvh,int f)36 void init_display(int w, int h, int *fvw, int *fvh, int f)
37 {
38 
39   /* Information about the current video settings. */
40   const SDL_VideoInfo* info = NULL;
41   int bpp = 0;
42   /* Flags we will pass into SDL_SetVideoMode. */
43   int flags = 0;
44 
45 
46   /* Let's get some video information. */
47   info = SDL_GetVideoInfo( );
48   if( !info ) {
49     /* This should probably never happen. */
50     fprintf( stderr, "Video query failed: %s\n",
51              SDL_GetError( ) );
52     //    projectM_vtable.disable_plugin (&projectM_vtable);
53     return;
54   }
55 
56 //  printf("Screen Resolution: %d x %d\n", info->current_w, info->current_h);
57   *fvw = info->current_w;
58   *fvh = info->current_h;
59   bpp = info->vfmt->BitsPerPixel;
60   //SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
61   //SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
62   //SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
63 
64   // SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 8 );
65   //  SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 8 );
66   //  SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 8 );
67   SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
68   SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
69   SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
70   if (f==0)
71      flags = SDL_OPENGL|SDL_HWSURFACE|SDL_RESIZABLE;
72   else flags = SDL_OPENGL|SDL_HWSURFACE|SDL_FULLSCREEN;
73  screen= SDL_SetVideoMode( w, h, bpp, flags ) ;
74   if(screen == 0 ) {
75     /*
76      * This could happen for a variety of reasons,
77      * including DISPLAY not being set, the specified
78      * resolution not being available, etc.
79      */
80    fprintf( stderr, "Video mode set failed: %s\n",
81 	     SDL_GetError( ) );
82 
83    // projectM_vtable.disable_plugin (&projectM_vtable);
84     return;
85 
86   }
87 
88   // setup_opengl(w,h);
89   //gluOrtho2D(0, w, 0, h);
90 }
91 
92 
93