Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros Groups
n_gfx.c
Go to the documentation of this file.
1
8 #include "n_gfx.h"
9
10 #ifndef NOISOENGINE
11
18 int gfx_status( int ACTION , int value )
19 {
20
21 static int STATUS = MODE_DX;
22
23 if ( ACTION == SET ) {
24 if ( value == MODE_DX )
25 STATUS = MODE_DX;
26
27 if ( value == MODE_OGL )
28 STATUS = MODE_OGL;
29 }
30 return STATUS;
31 } /* gfx_status(...) */
32
33
34
49 int gfx_mode( int card , int W , int H , int VW , int VH , int depth , float r , float g , float b , float alpha )
50 {
51 set_color_depth( depth );
52 /*set_color_conversion( COLORCONV_KEEP_TRANS );*/
53
54 if ( card == GFX_OPENGL || card == GFX_OPENGL_FULLSCREEN || card == GFX_OPENGL_WINDOWED )
55 {
56 install_allegro_gl();
57 allegro_gl_clear_settings();
58 allegro_gl_set ( AGL_COLOR_DEPTH , depth );
59 allegro_gl_set ( AGL_DOUBLEBUFFER , 1 );
60 allegro_gl_set ( AGL_RENDERMETHOD , 1 );
61 allegro_gl_set ( AGL_REQUIRE, AGL_RENDERMETHOD | AGL_COLOR_DEPTH | AGL_DOUBLEBUFFER );
62 if( set_gfx_mode( card, W, H, VW, VH ) < 0 )
63 {
64 n_log( LOG_ERR , "Error setting %d mode in %d / %d / %d !\n" , card , W , H , depth );
65 exit( EXIT_FAILURE );
66 }
67 allegro_gl_use_alpha_channel( TRUE );
68 allegro_gl_use_mipmapping( TRUE );
69 glClearColor( r, g, b, alpha );
70 glDisable( GL_DEPTH_TEST );
71 glDisable( GL_LIGHTING );
72 glMatrixMode( GL_PROJECTION );
73 glLoadIdentity();
74 glOrtho( 0, W, H, 0, -1, 1 );
75 glMatrixMode( GL_MODELVIEW );
76 glLoadIdentity();
77 glBlendFunc( GL_SRC_ALPHA, GL_ONE );
78 /* Skip pixels which alpha channel is lower than 0.5*/
79 /*glAlphaFunc( GL_GREATER , 0.5 );*/
80 glEnable( GL_TEXTURE_2D );
81 /* setting gfx_status to MODE_OGL */
82 gfx_status( SET , MODE_OGL );
83 allegro_font = allegro_gl_convert_allegro_font_ex( font, AGL_FONT_TYPE_TEXTURED, 16.0, GL_ALPHA8 );
84 }
85 else
86 { if ( set_gfx_mode( card, W, H, VW, VH ) < 0 )
87 {
88 n_log( LOG_ERR , "Error setting %d mode in %d / %d / %d !\n" , card , W , H , depth );
89 exit( EXIT_FAILURE );
90 }
91 /* setting gfx_status to MODE_DIRECTX */
92 gfx_status( SET , MODE_DX );
93
94 }
95
96 if( set_display_switch_mode( SWITCH_BACKGROUND ) != 0 )
97 {
98 n_log( LOG_ERR , "Warning: can not change switch mode to SWITCH_BACKGROUND" );
99 if( set_display_switch_mode( SWITCH_BACKAMNESIA ) !=0)
100 {
101 n_log( LOG_ERR , "Error: can not change switch mode to BACKAMNESIA" );
102 return FALSE;
103 }
104 }
105 n_log( LOG_INFO , "background running allowed" );
106
107 return TRUE;
108 } /* gfx_mode(...) */
109
110
111
112
118 int Force32BitBmpToAlpha( BITMAP *bmp )
119 {
120 int x, y;
121 int r, g, b, alpha;
122 int col, mask;
123
124 _assert( bmp , return FALSE );
125
126 acquire_bitmap( bmp );
127 mask = bitmap_mask_color( bmp );
128
129 /* First check if an alpha channel already exists */
130 for ( y = 0; y < bmp->h; ++y ) {
131 for ( x = 0; x < bmp->w; ++x ) {
132 col = getpixel( bmp, x, y );
133 alpha = geta( col );
134
135 if ( alpha != 0 && col != mask ) {
136 release_bitmap( bmp );
137 return FALSE;
138 }
139 }
140 }
141
142 for ( y = 0; y < bmp->h; ++y ) {
143 for ( x = 0; x < bmp->w; ++x ) {
144 col = getpixel( bmp, x, y );
145 r = getr( col );
146 g = getg( col );
147 b = getb( col );
148 putpixel( bmp, x, y, makeacol( r, g, b, 255 ) );
149 }
150 }
151 release_bitmap( bmp );
152 return TRUE ;
153 } /* Force32BitBmpToAlpha */
154
155
156
163 void force_color_to_be( BITMAP *bmp , int oldcolor , int newcolor )
164 {
165 int x , y ;
166 if ( bmp ) {
167 for ( x = 0 ; x < bmp -> w ; x ++ )
168 for ( y = 0 ; y < bmp -> h ; y ++ )
169 if ( getpixel( bmp , x , y ) == oldcolor )
170 putpixel( bmp, x, y, newcolor );
171 }
172 } /* force color_to_be(...) */
173
174
175
190 void ogl_blit( GLuint mytexture , int x , int y , int r , int g , int b , int alpha , int w , int h , int mode )
191 {
192 if( mode == 1 )
193 {
194 glBindTexture( GL_TEXTURE_2D, mytexture );
195
196 glBegin( GL_QUADS );
197 /*Draw our four points, clockwise.*/
198 glColor4f( r, g, b, alpha );
199 glTexCoord2f( 0, 1 );
200 glVertex3f( x, y, 0 );
201 glTexCoord2f( 1, 1 );
202 glVertex3f( x + w, y, 0 );
203 glTexCoord2f( 1, 0 );
204 glVertex3f( x + w, y + h, 0 );
205 glTexCoord2f( 0, 0 );
206 glVertex3f( x, y + h , 0 );
207 glEnd();
208
209 /*binding the default texture*/
210 glBindTexture( GL_TEXTURE_2D, 0 );
211 }
212 else
213 {
214 /* binding the texture */
215 glBindTexture( GL_TEXTURE_2D, mytexture );
216
217 glEnable( GL_BLEND );
218
219 glBegin( GL_QUADS );
220 /*If we set the color to white here, then the textured quad won't be*/
221 /*tinted red or half-see-through or something when we draw it based on*/
222 /*the last call to glColor*().*/
223 glColor3f( r, g, b );
224
225 /*Draw our four points, clockwise.*/
226 glTexCoord2f( 0, 1 );
227 glVertex3f( x, y, 0 );
228 glTexCoord2f( 1, 1 );
229 glVertex3f( x + w, y, 0 );
230 glTexCoord2f( 1, 0 );
231 glVertex3f( x + w, y + h, 0 );
232 glTexCoord2f( 0, 0 );
233 glVertex3f( x, y + h , 0 );
234 glEnd();
235
236 glDisable( GL_BLEND );
237
238
239 /*binding the default texture*/
240 glBindTexture( GL_TEXTURE_2D, 0 );
241 }
242 } /* ogl_blit(...) */
243
244 #endif /* #ifndef NOISOENGINE */
245