Mercurial > audlegacy-plugins
comparison src/projectm-1.0/video_init.cxx @ 1929:64bcd7c9c705
Automated merge with ssh://hg.atheme.org//hg/audacious-plugins
author | Kiyoshi Aman <kiyoshi.aman@gmail.com> |
---|---|
date | Mon, 01 Oct 2007 05:56:16 -0500 |
parents | a6d84a2cfaa7 |
children | 47a4e93ed7ce |
comparison
equal
deleted
inserted
replaced
1928:b68bcc6a39c7 | 1929:64bcd7c9c705 |
---|---|
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 | |
13 extern SDL_Surface *screen; | |
14 extern int texsize; | |
15 void setup_opengl( int w, int h ); | |
16 | |
17 void close_display() { | |
18 printf("quitting\n"); | |
19 SDL_Quit(); | |
20 } | |
21 | |
22 void resize_display(int w, int h, int f) { | |
23 int flags; | |
24 if (f) flags = SDL_OPENGL|SDL_HWSURFACE|SDL_FULLSCREEN; | |
25 else flags = SDL_OPENGL|SDL_HWSURFACE|SDL_RESIZABLE; | |
26 // SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); | |
27 screen = SDL_SetVideoMode( w, h, 0, flags ) ; | |
28 if(screen == 0 ) { | |
29 fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) ); | |
30 return; | |
31 } | |
32 setup_opengl(w,h); | |
33 SDL_ShowCursor(f ? SDL_DISABLE : SDL_ENABLE); | |
34 } | |
35 | |
36 //init_display | |
37 // | |
38 //Sets screen to new width and height (w,h) | |
39 //Also switches between fullscreen and windowed | |
40 //with the boolean f (fullscreen) | |
41 void init_display(int w, int h, int *fvw, int *fvh, int f) | |
42 { | |
43 | |
44 /* Information about the current video settings. */ | |
45 const SDL_VideoInfo* info = NULL; | |
46 int bpp = 0; | |
47 /* Flags we will pass into SDL_SetVideoMode. */ | |
48 int flags = 0; | |
49 /* First, initialize SDL's video subsystem. */ | |
50 if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 ) { | |
51 /* Failed, exit. */ | |
52 fprintf( stderr, "Video initialization failed: %s\n", | |
53 SDL_GetError( ) ); | |
54 //projectM_vtable.disable_plugin (&projectM_vtable); | |
55 return; | |
56 | |
57 } | |
58 /* Let's get some video information. */ | |
59 info = SDL_GetVideoInfo( ); | |
60 if( !info ) { | |
61 /* This should probably never happen. */ | |
62 fprintf( stderr, "Video query failed: %s\n", | |
63 SDL_GetError( ) ); | |
64 // projectM_vtable.disable_plugin (&projectM_vtable); | |
65 return; | |
66 } | |
67 | |
68 printf("Screen Resolution: %d x %d\n", info->current_w, info->current_h); | |
69 *fvw = info->current_w; | |
70 *fvh = info->current_h; | |
71 printf("set fvw and fvw\n"); | |
72 bpp = info->vfmt->BitsPerPixel; | |
73 printf("set bpp\n"); | |
74 //SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); | |
75 //SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); | |
76 //SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); | |
77 | |
78 // SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 8 ); | |
79 // SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 8 ); | |
80 // SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 8 ); | |
81 SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 ); | |
82 SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); | |
83 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); | |
84 printf("set gl attributes\n"); | |
85 if (f==0) | |
86 flags = SDL_OPENGL|SDL_HWSURFACE|SDL_RESIZABLE; | |
87 else flags = SDL_OPENGL|SDL_HWSURFACE|SDL_FULLSCREEN; | |
88 printf("set gl attributes2\n"); | |
89 screen= SDL_SetVideoMode( w, h, bpp, flags ) ; | |
90 printf("set screen\n"); | |
91 if(screen == 0 ) { | |
92 /* | |
93 * This could happen for a variety of reasons, | |
94 * including DISPLAY not being set, the specified | |
95 * resolution not being available, etc. | |
96 */ | |
97 fprintf( stderr, "Video mode set failed: %s\n", | |
98 SDL_GetError( ) ); | |
99 | |
100 // projectM_vtable.disable_plugin (&projectM_vtable); | |
101 return; | |
102 | |
103 } | |
104 | |
105 printf("video init done\n"); | |
106 // setup_opengl(w,h); | |
107 //gluOrtho2D(0, w, 0, h); | |
108 } | |
109 | |
110 | |
111 void setup_opengl( int w, int h ) | |
112 { | |
113 | |
114 /* Our shading model--Gouraud (smooth). */ | |
115 glShadeModel( GL_SMOOTH); | |
116 /* Culling. */ | |
117 // glCullFace( GL_BACK ); | |
118 // glFrontFace( GL_CCW ); | |
119 // glEnable( GL_CULL_FACE ); | |
120 /* Set the clear color. */ | |
121 glClearColor( 0, 0, 0, 0 ); | |
122 /* Setup our viewport. */ | |
123 glViewport( 0, 0, w, h ); | |
124 /* | |
125 * Change to the projection matrix and set | |
126 * our viewing volume. | |
127 */ | |
128 glMatrixMode(GL_TEXTURE); | |
129 glLoadIdentity(); | |
130 | |
131 // gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height); | |
132 glMatrixMode(GL_PROJECTION); | |
133 glLoadIdentity(); | |
134 | |
135 // glFrustum(0.0, height, 0.0,width,10,40); | |
136 glMatrixMode(GL_MODELVIEW); | |
137 glLoadIdentity(); | |
138 | |
139 glDrawBuffer(GL_BACK); | |
140 glReadBuffer(GL_BACK); | |
141 glEnable(GL_BLEND); | |
142 | |
143 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
144 // glBlendFunc(GL_SRC_ALPHA, GL_ONE); | |
145 glEnable(GL_LINE_SMOOTH); | |
146 glEnable(GL_POINT_SMOOTH); | |
147 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | |
148 glClear(GL_COLOR_BUFFER_BIT); | |
149 | |
150 // glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,texsize,texsize,0); | |
151 //glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,texsize,texsize); | |
152 glLineStipple(2, 0xAAAA); | |
153 | |
154 | |
155 } | |
156 |