aboutsummaryrefslogtreecommitdiff
path: root/src/parsec/vsdl_inito.cpp
blob: cd2eb7223c1b554c0bf8193374bd71ea3573f92b (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
/*
 * PARSEC - Video Init 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 "vid_defs.h"

// local module header
#include "vsdl_inito.h"

// proprietary module headers
#include "con_aux.h"
#include "con_ext.h"
#include "e_color.h"
#include "vsdl_ogl.h"


static const char * initscript = "sys_gl";


// init display (video mode) using global vars --------------------------------
//
void VIDs_InitDisplay()
{
	// switch to desired video mode
	VSDL_InitOGLMode();

	// set gamma correction
	VIDs_SetGammaCorrection( GammaCorrection );

	// clear text mode flag
	TextModeActive = FALSE;
}


// restore display to text mode -----------------------------------------------
//
void VIDs_RestoreDisplay()
{
	// exit function if no graphics mode active
	if ( TextModeActive )
		return;

	// destroy canvas
	VSDL_ShutDownOGL();

	// set text mode flag once again
	TextModeActive = TRUE;
}


// calculate the global projective projection-matrix --------------------------
//
void VIDs_CalcProjectiveMatrix()
{
	VSDL_CalcProjectiveMatrix();
}


// calculate the global orthographic projection-matrix ------------------------
//
void VIDs_CalcOrthographicMatrix()
{
	VSDL_CalcOrthographicMatrix();
}


// execute subsystem initialization script ------------------------------------
//
PRIVATE
void SDL_ExecSubsysScript()
{
	//NOTE:
	// this function executes a script that can be
	// used to reload critical data on each video
	// subsystem switch.

	// only when non-initial subsystem init
	extern int console_init_done;
	if ( !console_init_done )
		return;

	if ( TextModeActive ) {
		MSGPUT( "Converting data for OpenGL rendering..." );
	}

	// put up conversion dialog
//	SM_ShowSplashScreen( TRUE );

	int oldstate_texture = AUX_ENABLE_TEXTURE_OVERLOADING;
	AUX_ENABLE_TEXTURE_OVERLOADING = 1;
	AUX_ALLOW_ONLY_TEXTURE_LOADING = 1;
	int oldstate_write = AUX_CMD_WRITE_DISABLE_OUTPUT;
	AUX_CMD_WRITE_DISABLE_OUTPUT = 1;

	// execute video subsystem init script
	int rc = ExecExternalFile( (char *) initscript );

	AUX_ENABLE_TEXTURE_OVERLOADING = oldstate_texture;
	AUX_ALLOW_ONLY_TEXTURE_LOADING = 0;
	AUX_CMD_WRITE_DISABLE_OUTPUT   = oldstate_write;

	if ( TextModeActive ) {
		if ( rc && AUX_CMD_WRITE_ACTIVE_IN_TEXTMODE ) {
			MSGOUT( "\nConversion finished." );
		} else {
			MSGOUT( "done." );
		}
	}
	
//	SM_DestroySplashScreen();
}


// tables for supported texture formats ---------------------------------------
//
static int texfmt_general[] = {

	FALSE,		// TEXFMT_STANDARD
	FALSE,		// TEXFMT_RGB_565
	FALSE,		// TEXFMT_RGBA_1555
	TRUE,		// TEXFMT_RGB_888
	TRUE,		// TEXFMT_RGBA_8888
	TRUE,		// TEXFMT_ALPHA_8
	TRUE,		// TEXFMT_INTENSITY_8
	TRUE,		// TEXFMT_LUMINANCE_8
};


// init internal video subsystem-specific flags -------------------------------
//
PRIVATE
void SDL_VideoFlagsSetup()
{
	// basic 32bpp conversion flags
	dword base32 = 0;
	base32 |= COLORSETUP_32BPP_PAL_SWAP_RGB;
	base32 |= COLORSETUP_32BPP_PAL_SET_ALPHA;
//	base32 |= COLORSETUP_32BPP_BITMAP_YINVERSE;
	base32 |= COLORSETUP_32BPP_FONT_YINVERSE;
	base32 |= COLORSETUP_32BPP_ENABLE_TRANSPARENCY;
	base32 |= COLORSETUP_32BPP_CONVERT_SCALE_BITMAPS;

	//NOTE:
	// COLORSETUP_32BPP_BITMAP_YINVERSE must be specified if
	// glDrawPixels() is used for bitmaps instead of textures.

	// texture conversion flags
	dword textures = 0;
	textures |= COLORSETUP_STANDARD_TO_RGB_888;
	textures |= COLORSETUP_GLIDE3DF_TO_RGB_888;		// RGB-only allowed
//	textures |= COLORSETUP_GLIDE3DF_TO_RGBA_8888;	// no RGB-only: use RGBA
	textures |= COLORSETUP_ALPHA_8_TO_RGBA_8888;	// no alpha-only textures

	// font conversion flags
	dword fonts = 0;
//	fonts |= COLORSETUP_FONT_TO_TEXTURE_ALPHA;		// alpha-only fonts
	fonts |= COLORSETUP_FONT_TO_TEXTURE_RGBA;		// no alpha-only fonts

	// color swapping flags
	dword colswap = 0;
	colswap |= COLORSETUP_SWAP_BITMAPS_32BPP;
	colswap |= COLORSETUP_SWAP_FONTS_32BPP;

	// set color translation for opengl
	ColorSetupFlags = base32 | textures | fonts | colswap;

	// set relevant vidinfo flags
	VidInfo_UseIterForDemoTexts = TRUE;				// demo texts as textures
	VidInfo_MaxTextureSize		= 2048;				// may decrease on mode init
	VidInfo_MaxTextureLod		= TEXLOD_2048;		// may decrease on mode init
	VidInfo_NumTextureUnits		= 16;

	// set supported texture formats
	VidInfo_SupportedTexFormats	= texfmt_general;
}


// init api responsible for frame buffer (wgl) --------------------------------
//
void VIDs_InitFrameBufferAPI()
{
	// init opengl and fill in available video modes
	if ( !VSDL_InitOGLInterface( PrintVidModeList ) ) {

		MSGOUT( "OpenGL could not be initialized.\n\n" );
		PANIC ( "OpenGL (SDL) init error." );
	}

	// set video flags (internal config)
	SDL_VideoFlagsSetup();

	// execute script if available
	SDL_ExecSubsysScript();
}