aboutsummaryrefslogtreecommitdiff
path: root/src/parsec/vsdl_suppo.cpp
blob: 73c7e498dd9270326686e6816ad8d225a3dee831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
 * PARSEC - Supporting Functions (SDL)
 *
 * $Author: uberlinuxguy $ - $Date: 2004/09/15 12:25:37 $
 *
 * Orginally written by:
 *   Copyright (c) Markus Hadwiger     <msh@parsec.org>   1999
 *   Copyright (c) Andreas Varga       <sid@parsec.org>   1999
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */ 
#include "config.h"

// C library
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


// compilation flags/debug support
#include "config.h"
#include "debug.h"

// general definitions
#include "general.h"
#include "objstruc.h"

// global externals
#include "globals.h"

// subsystem headers
#include "aud_defs.h"
#include "sys_defs.h"
#include "vid_defs.h"

// drawing subsystem
#include "d_iter.h"

// local module header
#include "vsdl_suppo.h"
#include "vsdl_ogl.h"


// opengl headers
#include "r_gl.h"


// draw colored and alpha-blended rectangle that covers the entire screen -----
//
PRIVATE
void VSDL_ScreenRectangle( colrgba_s color, word itertype )
{

	IterRectangle2 itrect;

	itrect.Vtxs[ 0 ].X = RASTV_0;
	itrect.Vtxs[ 0 ].Y = RASTV_0;
	itrect.Vtxs[ 0 ].Z = RASTV_1;
	itrect.Vtxs[ 0 ].R = color.R;
	itrect.Vtxs[ 0 ].G = color.G;
	itrect.Vtxs[ 0 ].B = color.B;
	itrect.Vtxs[ 0 ].A = color.A;

	itrect.Vtxs[ 1 ].X = INT_TO_RASTV( Screen_Width );
	itrect.Vtxs[ 1 ].Y = RASTV_0;
	itrect.Vtxs[ 1 ].Z = RASTV_1;
	itrect.Vtxs[ 1 ].R = itrect.Vtxs[ 0 ].R;
	itrect.Vtxs[ 1 ].G = itrect.Vtxs[ 0 ].G;
	itrect.Vtxs[ 1 ].B = itrect.Vtxs[ 0 ].B;
	itrect.Vtxs[ 1 ].A = itrect.Vtxs[ 0 ].A;

	itrect.Vtxs[ 2 ].X = INT_TO_RASTV( Screen_Width );
	itrect.Vtxs[ 2 ].Y = INT_TO_RASTV( Screen_Height );
	itrect.Vtxs[ 2 ].Z = RASTV_1;
	itrect.Vtxs[ 2 ].R = itrect.Vtxs[ 0 ].R;
	itrect.Vtxs[ 2 ].G = itrect.Vtxs[ 0 ].G;
	itrect.Vtxs[ 2 ].B = itrect.Vtxs[ 0 ].B;
	itrect.Vtxs[ 2 ].A = itrect.Vtxs[ 0 ].A;

	itrect.Vtxs[ 3 ].X = RASTV_0;
	itrect.Vtxs[ 3 ].Y = INT_TO_RASTV( Screen_Height );
	itrect.Vtxs[ 3 ].Z = RASTV_1;
	itrect.Vtxs[ 3 ].R = itrect.Vtxs[ 0 ].R;
	itrect.Vtxs[ 3 ].G = itrect.Vtxs[ 0 ].G;
	itrect.Vtxs[ 3 ].B = itrect.Vtxs[ 0 ].B;
	itrect.Vtxs[ 3 ].A = itrect.Vtxs[ 0 ].A;

	itrect.flags	 = ITERFLAG_NONE;
	itrect.itertype  = itertype;
	itrect.raststate = rast_default;
	itrect.rastmask  = rast_nomask;
	itrect.texmap	 = NULL;

	D_DrawIterRectangle2( &itrect );
}


// fade in screen (palette) from black ----------------------------------------
//
int VIDs_FadeScreenFromBlack( int palno )
{
	return 1;
}


// fade screen (palette) to black ---------------------------------------------
//
int VIDs_FadeScreenToBlack( int palno, int fademusic )
{
	if ( fademusic )
		AUDs_MaxMusicVolume();

	// use black rectangle
	colrgba_s color = { 0, 0, 0, 0 };

	float subval = 0;
	while ( subval <= 255 ) {

		if ( fademusic )
			AUDs_FadeMusicVolume();
		
		SYSs_Yield();

		// fade alpha of rectangle
		color.A = (byte) subval;
		VSDL_ScreenRectangle( color, iter_rgba | iter_alphablend );
		VIDs_CommitRenderBuffer();

		subval += 4; // FIXME: doesn't take framerate into account
	}

	return 1;
}


// fade screen (palette) to black (palette referenced via pointer) ------------
//
int VIDs_FadePaletteToBlack( char *palette, int fademusic )
{
	// since no actual palette is involved here,
	// just use preceding function.
	VIDs_FadeScreenToBlack( 0, fademusic );

	return 1;
}


// fade in screen (palette) from white ----------------------------------------
//
int VIDs_FadeScreenFromWhite( int palno )
{
	return 1;
}


// set entire screen to single color ------------------------------------------
//
int VIDs_SetScreenToColor( colrgba_s col )
{
	// draw alpha-blended rectangle
	VSDL_ScreenRectangle( col, iter_rgba | iter_alphablend );

	return 1;
}


// set screen to dazzling white (whiteness depending on strength) -------------
//
int VIDs_SetScreenDazzle( float strength )
{
	// determine alpha of rectangle
	byte fadeval = (byte) strength;

	// use white rectangle
	colrgba_s color = { fadeval, fadeval, fadeval, 255 };

	// draw additive-blended rectangle (should be multiplicative, but Parsec doesn't do HDR rendering)
	VSDL_ScreenRectangle( color, iter_rgba | iter_additiveblend );

	return 1;
}


// set color index zero to specified color ------------------------------------
//
int VIDs_SetColIndexZero( int color )
{
	// only check for blue
	if ( color == COL_BACKGROUND_BLUE ) {

		// use translucent blue rectangle
		colrgba_s color_rgba = { 0, 0, 255, 100 };

		// draw alpha-blended rectangle
		VSDL_ScreenRectangle( color_rgba, iter_rgba | iter_alphablend );
	}

	return 1;
}


// set gamma correction value -------------------------------------------------
//
int VIDs_SetGammaCorrection( float gamma )
{
	// disabled because it causes visual glitches, isn't well-supported, and leaks gamma changes onto the desktop
	
	/*
	 
#if SDL_VERSION_ATLEAST(2, 0, 0)
	Uint16 ramp[256];
	SDL_CalculateGammaRamp(gamma, ramp);
	SDL_SetWindowGammaRamp(curwindow, ramp, ramp, ramp);
#else
	 if ( !Op_WindowedMode ) {
		 SDL_SetGamma(gamma, gamma, gamma); // sets R G and B gamma to the same value.
	 }
#endif
	 
	 */

	return TRUE;
}