1  /*
2   * Copyright (C) 2003 Ryan McGuigan <ryan@tempestgames.com>
3   *
4   * Licensed under the Academic Free License version 1.2
5   *
6   */
7 
8 #ifndef __SDL_PRIM_H
9 #define __SDL_PRIM_H		1
10 
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <math.h>
14 
15 #include "glSDL.h"
16 
17 /*
18  * SDL_prim drawing flags
19  */
20 #define SDL_TG_ALPHA   		0x01
21 #define SDL_TG_ANTIALIAS		0x02
22 #define SDL_TG_FILL	   		0x04
23 #define SDL_TG_LOCK	   		0x08
24 
25 #define __SDL_PRIM_LOCKSURFACE(screen) \
26 { \
27 	if ( SDL_MUSTLOCK((screen)) ) { \
28 		if ( SDL_LockSurface((screen)) < 0 ) { \
29 			fprintf(stderr, "Can't lock video surface: %s\n", SDL_GetError()); \
30 		} \
31 	} \
32 }
33 
34 #define __SDL_PRIM_UNLOCKSURFACE(screen) \
35 { \
36 	if ( SDL_MUSTLOCK((screen)) ) { \
37 		SDL_UnlockSurface((screen)); \
38 	} \
39 }
40 
41 inline void SDL_putPixel(SDL_Surface*, int x, int y, Uint32 clr);
42 inline void SDL_blendPixel(SDL_Surface*, int x, int y, Uint32 clr, Uint8 alpha);
43 inline Uint8* SDL_getPixel(SDL_Surface*, int x, int y);
44 inline void __slow_SDL_blendPixel(SDL_Surface*, int, int, Uint32, Uint8);
45 
46 void SDL_drawLine_TG( SDL_Surface*, int x, int y, int x2, int y2, Uint32 clr,
47                       Uint8 alpha, Uint8 flags );
48 /*
49 void SDL_drawBrokenLine_TG( SDL_Surface*, int x, int y, int x2, int y2,
50                             int seglen, int breaklen, Uint32 clr, Uint8 alpha,
51                             Uint32 flags );
52 */
53 void SDL_drawCircle_TG( SDL_Surface*, int x, int y, int r, Uint32 clr,
54                         Uint8 alpha, Uint8 flags );
55 void SDL_drawTriangle_TG( SDL_Surface*, int x, int y, int x2, int y2, int x3,
56                           int y3, Uint32 clr, Uint8 alpha, Uint8 flags );
57 
58 #define SDL_drawLine(surf, x1, y1, x2, y2, clr) \
59 	SDL_drawLine_TG((surf), (x1), (y1), (x2), (y2), (clr), 0, 0)
60 
61 #define SDL_drawLine_Alpha(surf, x1, y1, x2, y2, clr, alpha) \
62 	SDL_drawLine_TG( (surf), (x1), (y1), (x2), (y2), (clr),\
63 	                 (alpha), SDL_TG_ALPHA )
64 
65 #define SDL_drawLine_AA(surf, x1, y1, x2, y2, clr) \
66 	SDL_drawLine_TG( (surf), (x1), (y1), (x2), (y2), (clr), 0,\
67 	                 SDL_TG_ANTIALIAS )
68 
69 #define SDL_drawLine_Alpha_AA(surf, x1, y1, x2, y2, clr, alpha) \
70 	SDL_drawLine_TG( (surf), (x1), (y1), (x2), (y2), (clr),\
71 	                 (alpha), SDL_TG_ALPHA | SDL_TG_ANTIALIAS )
72 
73 #define SDL_drawCircle(surf, x, y, r, clr) \
74 	SDL_drawCircle_TG((surf), (x), (y), (r), (clr), 0, 0)
75 
76 #define SDL_drawCircle_AA(surf, x, y, r, clr) \
77 	SDL_drawCircle_TG((surf), (x), (y), (r), (clr), 0, SDL_TG_ANTIALIAS)
78 
79 #define SDL_drawCircle_Alpha(surf, x, y, r, clr, alpha) \
80 	SDL_drawCircle_TG((surf), (x), (y), (r), (clr), (alpha), SDL_TG_ALPHA)
81 
82 #define SDL_drawCircle_Alpha_AA(surf, x, y, r, clr, alpha) \
83 	SDL_drawCircle_TG((surf), (x), (y), (r), (clr), (alpha),\
84 	                  SDL_TG_ALPHA | SDL_TG_ANTIALIAS)
85 
86 #define SDL_fillCircle(surf, x, y, r, clr) \
87 	SDL_drawCircle_TG((surf), (x), (y), (r), (clr), 0, SDL_TG_FILL)
88 
89 #define SDL_fillCircle_AA(surf, x, y, r, clr) \
90 	SDL_drawCircle_TG((surf), (x), (y), (r), (clr), 0,\
91 	                  SDL_TG_ANTIALIAS | SDL_TG_FILL)
92 
93 #define SDL_fillCircle_Alpha(surf, x, y, r, clr, alpha) \
94 	SDL_drawCircle_TG((surf), (x), (y), (r), (clr), (alpha),\
95 	                  SDL_TG_ALPHA | SDL_TG_FILL)
96 
97 #define SDL_fillCircle_Alpha_AA(surf, x, y, r, clr, alpha) \
98 	SDL_drawCircle_TG((surf), (x), (y), (r), (clr), (alpha),\
99 	                  SDL_TG_ALPHA | SDL_TG_ANTIALIAS | SDL_TG_FILL)
100 
101 #define SDL_drawTriangle(surf, x1,y1, x2,y2, x3,y3, clr) \
102 	SDL_drawTriangle_TG((surf), (x1),(y1), (x2),(y2), (x3),(y3), (clr), 0, \
103 	                    0)
104 
105 #define SDL_drawTriangle_AA(surf, x1,y1, x2,y2, x3,y3, clr) \
106 	SDL_drawTriangle_TG((surf), (x1),(y1), (x2),(y2), (x3),(y3), (clr), 0, \
107 	                    SDL_TG_ANTIALIAS)
108 
109 #define SDL_drawTriangle_Alpha(surf, x1,y1, x2,y2, x3,y3, clr, alpha) \
110 	SDL_drawTriangle_TG((surf), (x1),(y1), (x2),(y2), (x3),(y3), (clr), \
111 	                    (alpha), SDL_TG_ALPHA)
112 
113 #define SDL_drawTriangle_Alpha_AA(surf, x1,y1, x2,y2, x3,y3, clr, alpha) \
114 	SDL_drawTriangle_TG((surf), (x1),(y1), (x2),(y2), (x3),(y3), (clr), \
115 	                    (alpha), SDL_TG_ALPHA | SDL_TG_ANTIALIAS)
116 
117 #define SDL_fillTriangle(surf, x1,y1, x2,y2, x3,y3, clr) \
118 	SDL_drawTriangle_TG((surf), (x1),(y1), (x2),(y2), (x3),(y3), (clr), 0, \
119 	                    SDL_TG_FILL)
120 
121 #define SDL_fillTriangle_AA(surf, x1,y1, x2,y2, x3,y3, clr) \
122 	SDL_drawTriangle_TG((surf), (x1),(y1), (x2),(y2), (x3),(y3), (clr), 0, \
123 	                    SDL_TG_ANTIALIAS|SDL_TG_FILL)
124 
125 #define SDL_fillTriangle_Alpha(surf, x1,y1, x2,y2, x3,y3, clr, alpha) \
126 	SDL_drawTriangle_TG((surf), (x1),(y1), (x2),(y2), (x3),(y3), (clr), \
127 	                    (alpha), SDL_TG_ALPHA|SDL_TG_FILL)
128 
129 #define SDL_fillTriangle_Alpha_AA(surf, x1,y1, x2,y2, x3,y3, clr, alpha) \
130 	SDL_drawTriangle_TG((surf), (x1),(y1), (x2),(y2), (x3),(y3), (clr), \
131 	                    (alpha), SDL_TG_ALPHA|SDL_TG_ANTIALIAS|SDL_TG_FILL)
132 
133 #endif
134