1 /* "SDL_2dgl.h" [Declarations]
2  *  _  _        _
3  * |_ | \|      _| _| _ |
4  *  _||_/|_ __ |_ |_||_||_      (c) 2004 Juan Pedro Bolivar Puente
5  *                    _|
6  *
7  * This project started on saturday 30 october 2004 at 11:11 A.M. in Huelva (Spain).
8  *
9  * This small library includes some tools to use OpenGL to render 2d games easily.
10  * This project started as part of the LuciferINO project.
11  *
12  */
13 
14 /*
15     Copyright (C) 2004, 2008, Juan Pedro Bolivar Puente
16 
17     This program is free software: you can redistribute it and/or modify
18     it under the terms of the GNU General Public License as published by
19     the Free Software Foundation, either version 3 of the License, or
20     (at your option) any later version.
21 
22     This program is distributed in the hope that it will be useful,
23     but WITHOUT ANY WARRANTY; without even the implied warranty of
24     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25     GNU General Public License for more details.
26 
27     You should have received a copy of the GNU General Public License
28     along with this program.  If not, see <http://www.gnu.org/licenses/>.
29 */
30 
31 #ifndef SDL_2DGL_H
32 #define SDL_2DGL_H
33 
34 #include <SDL/SDL.h>
35 #include <SDL/SDL_image.h>
36 #include <GL/gl.h>
37 #include <GL/glu.h>
38 
39 /*
40  * This is a GL texture thar can be used like if it were an SDL_Surface with this library.
41  * Remember that this mustn't be declared as a pointer.
42  */
43 typedef struct GL2D_SurfaceGL
44 {
45   GLuint tex;
46   Uint16 w;
47   Uint16 h;
48 }
49 GL2D_SurfaceGL;
50 
51 /*
52  * The same, but used for pictures larger than the maximum texture size.
53  */
54 typedef struct GL2D_LargeSurfaceGL
55 {
56   GL2D_SurfaceGL ***pics;
57   GLint partSize;
58   Uint8 hParts, vParts;
59   Uint16 w;
60   Uint16 h;
61 }
62 GL2D_LargeSurfaceGL;
63 
64 /*
65  * Draws a line.
66  */
67 void GL2D_DrawLine (Uint8 r, Uint8 g, Uint8 b, Uint8 a, int x0, int y0,
68 		    int x1, int y1);
69 
70 /*
71  * Frees a large surface.
72  */
73 void GL2D_FreeLargeSurfaceGL (GL2D_LargeSurfaceGL * src);
74 
75 /*
76  * "Blits" a large surface in the screen.
77  */
78 void GL2D_BlitLargeGL (GL2D_LargeSurfaceGL * src, float x, float y,
79 		       Uint8 alpha);
80 
81 /*
82  * Loads a large surface.
83  */
84 GL2D_LargeSurfaceGL *GL2D_CreateLargeSurfaceGL (SDL_Surface * surf,
85 						GLint filter);
86 
87 /*
88  * Large surface blitting but using SDL_Rect's
89  */
90 void GL2D_BlitLargeSurfaceGL (GL2D_LargeSurfaceGL * src, SDL_Rect * src_r,
91 			      SDL_Rect * dest_r, Uint8 alpha);
92 
93 /*
94  * Blits part of a large surface.
95  */
96 void GL2D_BlitLargeGLpart (GL2D_LargeSurfaceGL * src,
97 			   float sx, float sy, float x, float y, float w,
98 			   float h, Uint8 alpha);
99 
100 /*
101  * Frees a GL2D_SurfaceGL
102  */
103 void GL2D_FreeSurfaceGL (GL2D_SurfaceGL * src);
104 
105 /*
106  * Initializes the screen to work with 2D OpenGL rendering.
107  */
108 void GL2D_InitScreenGL (SDL_Surface * screen, int w, int h, int bpp,
109 			Uint8 use_fullscreen);
110 
111 /*
112  * Creates a GL texture from a SDL_Surface
113  */
114 void GL2D_CreateGL (SDL_Surface * surf, GLuint * tex, GLint filter);
115 
116 /*
117  * Creates a SDL_SurfaceGL from a SDL_Surface
118  */
119 GL2D_SurfaceGL *GL2D_CreateSurfaceGL (SDL_Surface * surf, GLint filter);
120 
121 /*
122  * "Blits" a surface using SDL_Rects as references. Specially usefull when working
123  * with both software and OpenGL rendering.
124  */
125 void GL2D_BlitSurfaceGL (GL2D_SurfaceGL * src, SDL_Rect * src_r,
126 			 SDL_Rect * dest_r, Uint8 alpha);
127 
128 /*
129  * "Blits" a SDL_SurfaceGL rotated. X and Y refers to the position where the center
130  * of the pic will be.
131  */
132 void GL2D_BlitGLrot (GL2D_SurfaceGL * src, float x, float y, float angle,
133 		     Uint8 alpha);
134 
135 /*
136  * "Blits" part of a surface.
137  */
138 void GL2D_BlitGLpart (GL2D_SurfaceGL * src,
139 		      float sx, float sy, float x, float y, float w, float h,
140 		      Uint8 alpha);
141 
142 /*
143  * "Blits" a whole surface.
144  */
145 void GL2D_BlitGL (GL2D_SurfaceGL * src, float x, float y, Uint8 alpha);
146 
147 /*
148  * Draws a square of the specified r-g-b-a color
149  */
150 void GL2D_DrawRect (Uint8 r, Uint8 g, Uint8 b, Uint8 a, int x, int y, int w,
151 		    int h);
152 
153 
154 #endif /* SDL_2DGL_H */
155