annotate src/projectm-1.0/video_init.cxx @ 2080:f915d43db0dc

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