annotate src/projectm-1.0/video_init.cxx @ 3132:f8686c591e49

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