Commit | Line | Data |
70fd0f8d |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
4 | |
5 | #ifndef aTHX_ |
6 | #define aTHX_ |
7 | #endif |
8 | |
9 | #include <SDL.h> |
10 | |
d345ba03 |
11 | #define WARNMSG "is unsupported in windows. Contact us at #sdl irc.perl.org or sdl-devel@perl.org for help." |
7b7e8017 |
12 | |
13 | static Uint16* av_to_uint16 (AV* av) |
14 | { |
15 | int len = av_len(av); |
16 | if( len != -1) |
17 | { |
18 | int i; |
19 | Uint16* table = (Uint16 *)safemalloc(sizeof(Uint16)*(len)); |
20 | //fprintf( stderr, "Expecting 1,2,5,6 \n Length is %d \n", len); |
21 | for ( i = 0; i < len+1 ; i++ ){ |
22 | SV ** temp = av_fetch(av,i,0); |
23 | if( temp != NULL) |
24 | { |
25 | table[i] = (Uint16 *) SvIV( *temp ) ; |
26 | /* fprintf( stderr, "table[%d] = ", i); |
27 | if (table[i] == NULL) { fprintf ( stderr, " NULL\n"); } |
28 | else{ fprintf(stderr, " %d \n", table[i]); } */ |
29 | } |
30 | else { table[i] =0; } |
31 | |
32 | } |
33 | // warn("Got %d %d %d %d \n", table[0], table[1], table[2], table[3] ); |
34 | |
35 | return table; |
36 | } |
37 | return NULL; |
38 | } |
39 | |
40 | |
41 | |
70fd0f8d |
42 | MODULE = SDL::Video PACKAGE = SDL::Video PREFIX = video_ |
43 | |
44 | =for documentation |
45 | |
46 | The Following are XS bindings to the Video category in the SDL API v2.1.13 |
47 | |
48 | Describe on the SDL API site. |
49 | |
50 | See: L<http://www.libsdl.org/cgi/docwiki.cgi/SDL_API#head-813f033ec44914f267f32195aba7d9aff8c410c0> |
51 | |
52 | =cut |
53 | |
54 | SDL_Surface * |
95f5be30 |
55 | video_get_video_surface() |
56 | PREINIT: |
57 | char* CLASS = "SDL::Surface"; |
70fd0f8d |
58 | CODE: |
59 | RETVAL = SDL_GetVideoSurface(); |
60 | OUTPUT: |
61 | RETVAL |
62 | |
63 | |
20f544ea |
64 | SDL_VideoInfo* |
95f5be30 |
65 | video_get_video_info() |
20f544ea |
66 | PREINIT: |
67 | char* CLASS = "SDL::VideoInfo"; |
95f5be30 |
68 | CODE: |
babb07ed |
69 | RETVAL = (SDL_VideoInfo *) SDL_GetVideoInfo(); |
8a2411d0 |
70 | |
71 | OUTPUT: |
babb07ed |
72 | RETVAL |
8a2411d0 |
73 | |
7fa192d4 |
74 | SV * |
75 | video_video_driver_name( ) |
76 | |
8a2411d0 |
77 | CODE: |
7fa192d4 |
78 | char buffer[1024]; |
79 | if ( SDL_VideoDriverName(buffer, 1024) != NULL ) |
80 | { |
81 | RETVAL = newSVpv(buffer, 0); |
82 | } |
83 | else |
84 | XSRETURN_UNDEF; |
8a2411d0 |
85 | OUTPUT: |
86 | RETVAL |
7dda1934 |
87 | |
88 | AV* |
89 | list_modes ( format, flags ) |
90 | Uint32 flags |
91 | SDL_PixelFormat *format |
4510df28 |
92 | |
7dda1934 |
93 | CODE: |
94 | SDL_Rect **mode; |
95 | RETVAL = newAV(); |
96 | mode = SDL_ListModes(format,flags); |
97 | if (mode == (SDL_Rect**)-1 ) { |
98 | av_push(RETVAL,newSVpv("all",0)); |
99 | } else if (! mode ) { |
100 | av_push(RETVAL,newSVpv("none",0)); |
101 | } else { |
102 | for (;*mode;mode++) { |
103 | av_push(RETVAL,newSViv(PTR2IV(*mode))); |
104 | } |
105 | } |
106 | OUTPUT: |
107 | RETVAL |
108 | |
109 | |
218b5471 |
110 | int |
111 | video_video_mode_ok ( width, height, bpp, flags ) |
112 | int width |
113 | int height |
114 | int bpp |
115 | Uint32 flags |
116 | CODE: |
117 | RETVAL = SDL_VideoModeOK(width,height,bpp,flags); |
118 | OUTPUT: |
119 | RETVAL |
7dda1934 |
120 | |
bbe5d2f5 |
121 | |
122 | SDL_Surface * |
123 | video_set_video_mode ( width, height, bpp, flags ) |
124 | int width |
125 | int height |
126 | int bpp |
127 | Uint32 flags |
128 | PREINIT: |
129 | char* CLASS = "SDL::Surface"; |
130 | CODE: |
131 | RETVAL = SDL_SetVideoMode(width,height,bpp,flags); |
132 | OUTPUT: |
133 | RETVAL |
134 | |
135 | |
eaf32d63 |
136 | void |
137 | video_update_rect ( surface, x, y, w ,h ) |
138 | SDL_Surface *surface |
139 | int x |
140 | int y |
141 | int w |
142 | int h |
143 | CODE: |
144 | SDL_UpdateRect(surface,x,y,w,h); |
145 | |
146 | void |
147 | video_update_rects ( surface, ... ) |
148 | SDL_Surface *surface |
149 | CODE: |
150 | SDL_Rect *rects; |
151 | int num_rects,i; |
152 | if ( items < 2 ) return; |
153 | num_rects = items - 1; |
154 | rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items); |
155 | for(i=0;i<num_rects;i++) { |
156 | rects[i] = *(SDL_Rect *)SvIV((SV*)SvRV( ST(i + 1) )); |
157 | } |
158 | SDL_UpdateRects(surface,num_rects,rects); |
159 | safefree(rects); |
160 | |
7dda1934 |
161 | |
19f3ee7b |
162 | int |
163 | video_flip ( surface ) |
164 | SDL_Surface *surface |
165 | CODE: |
166 | RETVAL = SDL_Flip(surface); |
167 | OUTPUT: |
168 | RETVAL |
169 | |
2739f940 |
170 | int |
171 | video_set_colors ( surface, start, ... ) |
172 | SDL_Surface *surface |
173 | int start |
174 | CODE: |
175 | SDL_Color *colors,*temp; |
176 | int i, length; |
69341787 |
177 | if ( items < 3 ) { RETVAL = 0;} |
178 | else |
179 | { |
2739f940 |
180 | length = items - 2; |
181 | colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1)); |
182 | for ( i = 0; i < length ; i++ ) { |
183 | temp = (SDL_Color *)SvIV(ST(i+2)); |
184 | colors[i].r = temp->r; |
185 | colors[i].g = temp->g; |
186 | colors[i].b = temp->b; |
187 | } |
188 | RETVAL = SDL_SetColors(surface, colors, start, length ); |
189 | safefree(colors); |
69341787 |
190 | } |
2739f940 |
191 | |
2739f940 |
192 | OUTPUT: |
193 | RETVAL |
0a01cb9e |
194 | |
69341787 |
195 | int |
196 | video_set_palette ( surface, flags, start, ... ) |
197 | SDL_Surface *surface |
198 | int flags |
199 | int start |
200 | |
201 | CODE: |
202 | SDL_Color *colors,*temp; |
203 | int i, length; |
204 | if ( items < 4 ) { |
205 | RETVAL = 0; |
206 | } |
207 | else |
208 | { |
209 | length = items - 3; |
210 | colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1)); |
211 | for ( i = 0; i < length ; i++ ){ |
212 | temp = (SDL_Color *)SvIV(ST(i+3)); |
213 | colors[i].r = temp->r; |
214 | colors[i].g = temp->g; |
215 | colors[i].b = temp->b; |
216 | } |
217 | RETVAL = SDL_SetPalette(surface, flags, colors, start, length ); |
218 | safefree(colors); |
219 | } |
220 | OUTPUT: |
221 | RETVAL |
0a01cb9e |
222 | |
5e9f2784 |
223 | int |
224 | video_set_gamma(r, g, b) |
225 | float r; |
226 | float g; |
227 | float b; |
228 | CODE: |
d345ba03 |
229 | RETVAL = -1; |
230 | #if defined WIN32 || WINDOWS |
231 | warn( "set_gamma: %s", WARNMSG ); |
232 | #else |
5e9f2784 |
233 | RETVAL = SDL_SetGamma(r,g,b); |
d345ba03 |
234 | #endif |
235 | |
5e9f2784 |
236 | OUTPUT: |
237 | RETVAL |
7b7e8017 |
238 | |
5e9f2784 |
239 | |
240 | int |
8b7c3ac8 |
241 | video_set_gamma_ramp( rt, gt, bt ) |
242 | AV* rt; |
243 | AV* gt; |
244 | AV* bt; |
5e9f2784 |
245 | CODE: |
d345ba03 |
246 | #if defined WIN32 || WINDOWS |
247 | warn( "set_gamma_ramp: %s", WARNMSG ); |
248 | #else |
7b7e8017 |
249 | Uint16 *redtable, *greentable, *bluetable; |
250 | redtable = av_to_uint16(rt); |
251 | greentable = av_to_uint16(gt); |
252 | bluetable = av_to_uint16(bt); |
253 | RETVAL = SDL_SetGammaRamp(redtable, greentable, bluetable); |
254 | if( redtable != NULL) { safefree(redtable); } |
255 | if( greentable != NULL) { safefree(greentable); } |
256 | if( bluetable != NULL) { safefree(bluetable); } |
d345ba03 |
257 | #endif |
5e9f2784 |
258 | OUTPUT: |
259 | RETVAL |
260 | |