Пример #1
0
//
// VID_ChangeVideoMode
// intended only as a callback for VID_Restart_f
//
static void VID_ChangeVideoMode (int newmode)
{
	int		stat, temp;

	if (!screen)
		return;

	temp = scr_disabled_for_loading;
	scr_disabled_for_loading = true;
	CDAudio_Pause ();
	MIDI_Pause (MIDI_ALWAYS_PAUSE);
	S_ClearBuffer ();

	stat = VID_SetMode (newmode, vid_curpal);
	if (!stat)
	{
		if (vid_modenum == newmode)
			Sys_Error ("Couldn't set video mode: %s", SDL_GetError());

		// failed setting mode, probably due to insufficient
		// memory. go back to previous mode.
		Cvar_SetValue ("vid_mode", vid_modenum);
		stat = VID_SetMode (vid_modenum, vid_curpal);
		if (!stat)
			Sys_Error ("Couldn't set video mode: %s", SDL_GetError());
	}

	CDAudio_Resume (); 
	MIDI_Pause (MIDI_ALWAYS_RESUME);
	scr_disabled_for_loading = temp;
}
Пример #2
0
/*
================
VID_Init
================
*/
void    VID_Init (unsigned char *palette)
{

	Cmd_AddCommand ("vid_testmode", VID_TestMode_f);
	Cmd_AddCommand ("vid_nummodes", VID_NumModes_f);
	Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
	Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f);
	Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f);

	SCR_StretchInit();

// set up the mode list; note that later inits link in their modes ahead of
// earlier ones, so the standard VGA modes are always first in the list. This
// is important because mode 0 must always be VGA mode 0x13
	if (!COM_CheckParm ("-stdvid"))
		VID_InitExtra ();
	VGA_Init ();

	vid_testingmode = 0;

	vid_modenum = vid_mode->value;

	VID_SetMode (vid_modenum, palette);

	vid_realmode = vid_modenum;

	vid_menudrawfn = VID_MenuDraw;
	vid_menukeyfn = VID_MenuKey;

	reflectavailable = 0;	// leilei - :(
#ifdef WATERREFLECTIONS
	if (vid.reflectbuffer)
		vid.reflectbuffer = NULL;
#endif
}
Пример #3
0
/*
==================
R_Init_OpenGL
==================
*/
qboolean R_Init_OpenGL( void )
{
	GL_SetupAttributes();

	if( SDL_GL_LoadLibrary( EGL_LIB ) )
	{
		MsgDev( D_ERROR, "Couldn't initialize OpenGL: %s\n", SDL_GetError());
		return false;
	}

	return VID_SetMode();
}
Пример #4
0
/*
==================
R_Init_OpenGL
==================
*/
qboolean R_Init_OpenGL( void )
{
	GL_SetupAttributes();
#ifdef XASH_SDL
	if( SDL_GL_LoadLibrary( NULL ) )
	{
		MsgDev( D_ERROR, "Couldn't initialize OpenGL: %s\n", SDL_GetError());
		return false;
	}
#endif
	return VID_SetMode();
}
Пример #5
0
// callback function to pass to windows for message management
// This will be called from within WinMain when a message is received.
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{

	LRESULT Result = 0;

	// catch any relevant messages here
	switch (uMsg)
	{

	case WM_ACTIVATE:
		break;

	case WM_CREATE:
		break;

	case WM_KEYDOWN:
	{
		if (wParam == 'A')
		{
			VID_SetMode(0);
		}
		else if (wParam == 'S')
		{
			VID_SetMode(1);
		}
		else if (wParam == 'D')
		{
			VID_SetMode(2);
		}
		else if (wParam == 'F')
		{
			VID_SetMode(3);
		}
		else if (wParam == 'Q')
		{
			Sys_Shutdown();
		}
		else if (wParam == '1')
		{
			VID_SetMode(FirstFullScreenMode);
		}
		else if (wParam == '2')
		{
			VID_SetMode(FirstFullScreenMode + 1);
		}

	} break;

	case WM_DESTROY:
		//Sys_Shutdown();
		break;

	default:
		Result = DefWindowProc(hWnd, uMsg, wParam, lParam);					// by default use the default message behaviour
	}

	return Result;

}
Пример #6
0
void
VID_Init(unsigned char *palette)
{
    int err;

    Q_SDL_InitOnce();
    err = SDL_InitSubSystem(SDL_INIT_VIDEO);
    if (err < 0)
	Sys_Error("VID: Couldn't load SDL: %s", SDL_GetError());

    VID_SetMode(0, palette);

    VID_SetPalette(palette);
}
Пример #7
0
/*
================
VID_Update
================
*/
void    VID_Update (vrect_t *rects)
{
	if (firstupdate && _vid_default_mode->value)
	{
		if(_vid_default_mode->value >= numvidmodes)
			Cvar_Set (_vid_default_mode, "0");

		firstupdate = 0;
		Cvar_SetValue (vid_mode, _vid_default_mode->value);
	}

	(*pcurrentmode->swapbuffers)(&vid, pcurrentmode, rects);

	if (!nomodecheck)
	{
		if (vid_testingmode)
		{
			if (realtime >= vid_testendtime)
			{
				VID_SetMode (vid_realmode, vid_current_palette);
				vid_testingmode = 0;
			}
		}
		else
		{
			if (vid_mode->value != vid_realmode)
			{
				VID_SetMode ((int)vid_mode->value, vid_current_palette);
				Cvar_SetValue (vid_mode, (float)vid_modenum);
									// so if mode set fails, we don't keep on
									//  trying to set that mode
				vid_realmode = vid_modenum;
			}
		}
	}
}
Пример #8
0
void VID_Init(void)
{
    WNDCLASSEX wc = { 0 };
    wc.cbSize = sizeof(wc);
    wc.lpfnWndProc = MainWndProc;
    wc.hInstance = GlobalInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.lpszClassName = "Module 3";

    if (!RegisterClassEx(&wc))
        exit(EXIT_FAILURE);

    VID_InitWindowedMode();
    VID_InitFullscreenMode();

    VID_SetMode(0);
}
Пример #9
0
/*
=================
VID_TestMode_f
=================
*/
void VID_TestMode_f (void)
{
	int		modenum;
	double	testduration;

	if (!vid_testingmode)
	{
		modenum = Q_atoi (Cmd_Argv(1));

		if (VID_SetMode (modenum, vid_current_palette))
		{
			vid_testingmode = 1;
			testduration = Q_atof (Cmd_Argv(2));
			if (testduration == 0)
				testduration = 5.0;
			vid_testendtime = realtime + testduration;
		}
	}
}
Пример #10
0
/*
================
VID_Init
================
*/
void    VID_Init (unsigned char *palette)
{
	vid_mode = Cvar_Get("vid_mode", "0", CVAR_NONE, "None");
	vid_wait = Cvar_Get("vid_wait", "0", CVAR_NONE, "None");
	vid_nopageflip = Cvar_Get("vid_nopageflip", "0", CVAR_ARCHIVE, "None");
	_vid_wait_override = Cvar_Get("_vid_wait_override", "0", CVAR_ARCHIVE, "None");
	_vid_default_mode = Cvar_Get("_vid_default_mode", "0", CVAR_ARCHIVE, "None");
	_vid_default_mode_win = Cvar_Get("_vid_default_mode_win", "3", CVAR_ARCHIVE, "None");
	vid_config_x = Cvar_Get("vid_config_x", "800", CVAR_ARCHIVE, "None");
	vid_config_y = Cvar_Get("vid_config_y", "600", CVAR_ARCHIVE, "None");
	vid_stretch_by_2 = Cvar_Get("vid_stretch_by_2", "1", CVAR_ARCHIVE, "None");
	_windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None");
	vid_fullscreen_mode = Cvar_Get("vid_fullscreen_mode", "3", CVAR_ARCHIVE, "None");
	vid_windowed_mode = Cvar_Get("vid_windowed_mode", "0", CVAR_ARCHIVE, "None");
	block_switch = Cvar_Get("block_switch", "0", CVAR_ARCHIVE, "None");

	Cmd_AddCommand ("vid_testmode", VID_TestMode_f);
	Cmd_AddCommand ("vid_nummodes", VID_NumModes_f);
	Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
	Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f);
	Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f);

// set up the mode list; note that later inits link in their modes ahead of
// earlier ones, so the standard VGA modes are always first in the list. This
// is important because mode 0 must always be VGA mode 0x13
	if (!COM_CheckParm ("-stdvid"))
		VID_InitExtra ();
	VGA_Init ();

	vid_testingmode = 0;

	vid_modenum = vid_mode->int_val;

	VID_SetMode (vid_modenum, palette);

	vid_realmode = vid_modenum;
	
	vid_menudrawfn = VID_MenuDraw;
	vid_menukeyfn = VID_MenuKey;
}
Пример #11
0
/*
================
VID_Init
================
*/
void    VID_Init (unsigned char *palette)
{
	Cvar_RegisterVariable (&vid_mode);
	Cvar_RegisterVariable (&vid_wait);
	Cvar_RegisterVariable (&vid_nopageflip);
	Cvar_RegisterVariable (&_vid_wait_override);
	Cvar_RegisterVariable (&_vid_default_mode);
	Cvar_RegisterVariable (&_vid_default_mode_win);
	Cvar_RegisterVariable (&vid_config_x);
	Cvar_RegisterVariable (&vid_config_y);
	Cvar_RegisterVariable (&vid_stretch_by_2);
	Cvar_RegisterVariable (&_windowed_mouse);
	Cvar_RegisterVariable (&vid_fullscreen_mode);
	Cvar_RegisterVariable (&vid_windowed_mode);
	Cvar_RegisterVariable (&block_switch);

	Cmd_AddCommand ("vid_testmode", VID_TestMode_f);
	Cmd_AddCommand ("vid_nummodes", VID_NumModes_f);
	Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
	Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f);
	Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f);

// set up the mode list; note that later inits link in their modes ahead of
// earlier ones, so the standard VGA modes are always first in the list. This
// is important because mode 0 must always be VGA mode 0x13
	if (!COM_CheckParm ("-stdvid"))
		VID_InitExtra ();
	VGA_Init ();

	vid_testingmode = 0;

	vid_modenum = vid_mode.value;

	VID_SetMode (vid_modenum, palette);

	vid_realmode = vid_modenum;
	
	vid_menudrawfn = VID_MenuDraw;
	vid_menukeyfn = VID_MenuKey;
}
Пример #12
0
void VID_Init(void)
{

	WNDCLASSEX wc = { 0 };
	wc.cbSize = sizeof(wc);

	wc.lpfnWndProc = MainWndProc;											// message handling callback function
	wc.hInstance = GlobalInstance;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.lpszClassName = L"Module 3";

	//RegisterClassEx(&wc);

	if (!RegisterClassEx(&wc))
		exit(EXIT_FAILURE);

	int32 PaletteLength = 0;
	int8  *PaletteData = COM_FindFile("gfx/palette.lmp", &PaletteLength);
	
	uint8 *PaletteWalker = PaletteData;
	for (int i = 0; i < 256; i++)
	{
		uint8 Red = *PaletteWalker++;
		uint8 Green = *PaletteWalker++;
		uint8 Blue = *PaletteWalker++;

		uint32 Color = ((Red << 16) | (Green << 8) | Blue);
		ColorArray[i] = Color;
	}
	free(PaletteData);

	Vid.ColorPointer = ColorArray;
	
	VID_InitWindowedMode();
	VID_InitFullScreenMode();

	VID_SetMode(0);
}
Пример #13
0
long WINAPI WndProc (HWND	hWnd,
		     UINT	uMsg,
		     WPARAM	wParam,
		     LPARAM	lParam)
{
	switch (uMsg)
	{
	case WM_PAINT:
	{
		HGLRC hglrc = wglGetCurrentContext();
		char buf[200];
		static int frame_count = 0;
		static float	fps = 0;

		if (time == 0)
		{
			QueryPerformanceCounter(&time);
		}

		QueryPerformanceCounter(&new_time);

		if ((new_time - last_time) >= freq)
		{
			fps = frame_count*freq/(new_time - last_time);
			last_time = new_time;
			frame_count = 0;
		}

/*		do
		{
			QueryPerformanceCounter(&time);
		}
		while(time <= new_time + (freq / 30.0));*/

		glClear(GL_COLOR_BUFFER_BIT);

		glColor3f(1.0f, 1.0f, 1.0f);
		sprintf(buf, "FPS: %.1f", fps);
		hgl_print(20, 20, buf);

		Game_ProcessObjects((new_time - time)*30/freq*10);
		time = time + ((new_time - time)*30/freq)*freq/30;

		Hcommon_Frame();
		Game_DrawObjects();

		frame_count++;
		SwapBuffers(glw_state.hDC);

		return 0;
	}

	case WM_LBUTTONDOWN:
	{
		point_t p = {LOWORD(lParam), HIWORD(lParam)};
		shoot(&p);
		return 0;
	}

	case WM_KEYDOWN:
/*		printf("%i %i", wParam, lParam);*/

		switch(wParam)
		{
		case VK_ESCAPE:
			SendMessage(glw_state.hWnd, WM_CLOSE, 0, 0);
			break;
		case VK_SPACE:
			Con_Printf("polygon_tesselate() returned %i\n", polygon_tessellate(map));
			break;
		case VK_UP:
			fup();
			break;
		case VK_DOWN:
			down = 1;
			break;
		case VK_RETURN:
			{
				int		style;
				int		exstyle;

				gl_state.fullscreen = !gl_state.fullscreen;
				if (gl_state.fullscreen)
				{
					exstyle = WS_EX_TOPMOST;
					style = WS_POPUP | WS_VISIBLE;
					if (!VID_SetMode(gl_state.width, gl_state.height, 32))
						return false;
				}
				else
				{
					ChangeDisplaySettings(NULL, 0);
					exstyle = 0;
					style = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_VISIBLE;
				}
				SetWindowLong(glw_state.hWnd, GWL_STYLE, style);
				SetWindowLong(glw_state.hWnd, GWL_EXSTYLE, exstyle);
				SetWindowPos(glw_state.hWnd, NULL, 0, 0, gl_state.width, gl_state.height, 0);
				break;
			}
		}
		return 0;
	case WM_KEYUP:
		switch(wParam)
		{
		case VK_DOWN:
			down = 0;
			break;
		}
		return 0;

	case WM_SYSCOMMAND:
		if ((wParam == SC_SCREENSAVE) || (wParam == SC_MONITORPOWER))
			return 0;
		break;

	case WM_SIZE:
		hgl_reshape(LOWORD(lParam), HIWORD(lParam));
		return 0;

	case WM_CHAR:
		switch (wParam)
		{
		case 27:
			break;
		}
		return 0;

	case WM_CLOSE:
		PostQuitMessage(0);
		return 0;

	default:
		return DefWindowProc (hWnd, uMsg, wParam, lParam);
	}
	return DefWindowProc (hWnd, uMsg, wParam, lParam);
}
Пример #14
0
/*
===================
VID_Init
===================
*/
void	VID_Init (void)
{
	static char vid_center[] = "SDL_VIDEO_CENTERED=center";
	const SDL_VideoInfo *info;
	int		width, height, bpp;
	qboolean	fullscreen;
	const char	*read_vars[] = { "vid_fullscreen",
					 "vid_width",
					 "vid_height",
					 "vid_bpp",
					 "vid_vsync" };
#define num_readvars	( sizeof(read_vars)/sizeof(read_vars[0]) )

	Cvar_RegisterVariable (&vid_fullscreen); //johnfitz
	Cvar_RegisterVariable (&vid_width); //johnfitz
	Cvar_RegisterVariable (&vid_height); //johnfitz
	Cvar_RegisterVariable (&vid_bpp); //johnfitz
	Cvar_RegisterVariable (&vid_vsync); //johnfitz
	Cvar_SetCallback (&vid_fullscreen, VID_Changed_f);
	Cvar_SetCallback (&vid_width, VID_Changed_f);
	Cvar_SetCallback (&vid_height, VID_Changed_f);
	Cvar_SetCallback (&vid_bpp, VID_Changed_f);
	Cvar_SetCallback (&vid_vsync, VID_Changed_f);

	Cmd_AddCommand ("vid_unlock", VID_Unlock); //johnfitz
	Cmd_AddCommand ("vid_restart", VID_Restart); //johnfitz
	Cmd_AddCommand ("vid_test", VID_Test); //johnfitz
	Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
	Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f);

	putenv (vid_center);	/* SDL_putenv is problematic in versions <= 1.2.9 */

	if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
		Sys_Error("Could not initialize SDL Video");

	info = SDL_GetVideoInfo();
	Cvar_SetValueQuick (&vid_bpp, (float)info->vfmt->BitsPerPixel);

	if (CFG_OpenConfig("config.cfg") == 0)
	{
		CFG_ReadCvars(read_vars, num_readvars);
		CFG_CloseConfig();
	}
	CFG_ReadCvarOverrides(read_vars, num_readvars);

	VID_InitModelist();

	width = (int)vid_width.value;
	height = (int)vid_height.value;
	bpp = (int)vid_bpp.value;
	fullscreen = (int)vid_fullscreen.value;

	if (COM_CheckParm("-current"))
	{
		width = info->current_w;
		height = info->current_h;
		bpp = info->vfmt->BitsPerPixel;
		fullscreen = true;
	}
	else
	{
		int p;

		p = COM_CheckParm("-width");
		if (p && p < com_argc-1)
		{
			width = Q_atoi(com_argv[p+1]);

			if(!COM_CheckParm("-height"))
				height = width * 3 / 4;
		}

		p = COM_CheckParm("-height");
		if (p && p < com_argc-1)
		{
			height = Q_atoi(com_argv[p+1]);

			if(!COM_CheckParm("-width"))
				width = height * 4 / 3;
		}

		p = COM_CheckParm("-bpp");
		if (p && p < com_argc-1)
			bpp = Q_atoi(com_argv[p+1]);

		if (COM_CheckParm("-window") || COM_CheckParm("-w"))
			fullscreen = false;
		else if (COM_CheckParm("-fullscreen") || COM_CheckParm("-f"))
			fullscreen = true;
	}

	if (!VID_ValidMode(width, height, bpp, fullscreen))
	{
		width = (int)vid_width.value;
		height = (int)vid_height.value;
		bpp = (int)vid_bpp.value;
		fullscreen = (int)vid_fullscreen.value;
	}

	if (!VID_ValidMode(width, height, bpp, fullscreen))
	{
		width = 640;
		height = 480;
		bpp = info->vfmt->BitsPerPixel;
		fullscreen = false;
	}

	vid_initialized = true;

	vid.maxwarpwidth = WARP_WIDTH;
	vid.maxwarpheight = WARP_HEIGHT;
	vid.colormap = host_colormap;
	vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));

	// set window icon
	PL_SetWindowIcon();

	VID_SetMode (width, height, bpp, fullscreen);

	GL_Init ();
	GL_SetupState ();
	Cmd_AddCommand ("gl_info", GL_Info_f); //johnfitz

	//johnfitz -- removed code creating "glquake" subdirectory

	vid_menucmdfn = VID_Menu_f; //johnfitz
	vid_menudrawfn = VID_MenuDraw;
	vid_menukeyfn = VID_MenuKey;

	VID_Gamma_Init(); //johnfitz
	VID_Menu_Init(); //johnfitz

	//QuakeSpasm: current vid settings should override config file settings.
	//so we have to lock the vid mode from now until after all config files are read.
	vid_locked = true;
}
Пример #15
0
/*
===================
VID_Restart -- johnfitz -- change video modes on the fly
===================
*/
static void VID_Restart (void)
{
	int width, height, bpp;
	qboolean fullscreen;

	if (vid_locked || !vid_changed)
		return;

	if (r_oculusrift.value) { // phoboslab
		R_ReleaseHMDRenderer();
	}

	width = (int)vid_width.value;
	height = (int)vid_height.value;
	bpp = (int)vid_bpp.value;
	fullscreen = vid_fullscreen.value ? true : false;

//
// validate new mode
//
	if (!VID_ValidMode (width, height, bpp, fullscreen))
	{
		Con_Printf ("%dx%dx%d %s is not a valid mode\n",
				width, height, bpp, fullscreen? "fullscreen" : "windowed");
		return;
	}

//
// set new mode
//
	VID_SetMode (width, height, bpp, fullscreen);

	GL_Init ();
	TexMgr_ReloadImages ();
	GL_SetupState ();

	//warpimages needs to be recalculated
	TexMgr_RecalcWarpImageSize ();

	//conwidth and conheight need to be recalculated
	vid.conwidth = (scr_conwidth.value > 0) ? (int)scr_conwidth.value : (scr_conscale.value > 0) ? (int)(vid.width/scr_conscale.value) : vid.width;
	vid.conwidth = CLAMP (320, vid.conwidth, vid.width);
	vid.conwidth &= 0xFFFFFFF8;
	vid.conheight = vid.conwidth * vid.height / vid.width;
//
// keep cvars in line with actual mode
//
	VID_SyncCvars();
//
// update mouse grab
//
	if (key_dest == key_console || key_dest == key_menu)
	{
		if (modestate == MS_WINDOWED)
			IN_Deactivate(true);
		else if (modestate == MS_FULLSCREEN)
			IN_Activate();
	}

	if (r_oculusrift.value) { // phoboslab
		R_InitHMDRenderer();
	}
}
Пример #16
0
/*
========================
Android_RunEvents

Execute all events from queue
========================
*/
void Android_RunEvents()
{
	int i;

	// enter events read
	Android_Lock();
	pthread_mutex_unlock( &events.framemutex );

	for( i = 0; i < events.count; i++ )
	{
		switch( events.queue[i].type )
		{
		case event_touch_down:
		case event_touch_up:
		case event_touch_move:
			IN_TouchEvent( events.queue[i].type, events.queue[i].arg,
						   events.queue[i].touch.x, events.queue[i].touch.y,
						   events.queue[i].touch.dx, events.queue[i].touch.dy );
			break;

		case event_key_down:
			Key_Event( events.queue[i].arg, true );
			break;
		case event_key_up:
			Key_Event( events.queue[i].arg, false );
			break;

		case event_set_pause:
			// destroy EGL surface when hiding application
			if( !events.queue[i].arg )
			{
				host.state = HOST_FRAME;
				S_Activate( true );
				(*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 1 );
				Android_UpdateSurface();
				Android_SwapInterval( Cvar_VariableInteger( "gl_swapinterval" ) );
			}
			if( events.queue[i].arg )
			{
				host.state = HOST_NOFOCUS;
				S_Activate( false );
				(*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 0 );
				negl.valid = false;
			}
			break;

		case event_resize:
			// reinitialize EGL and change engine screen size
			if( host.state == HOST_NORMAL && ( scr_width->integer != jni.width || scr_height->integer != jni.height ) )
			{
				(*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 0 );
				(*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 1 );
				Android_UpdateSurface();
				Android_SwapInterval( Cvar_VariableInteger( "gl_swapinterval" ) );
				VID_SetMode();
			}
			break;
		case event_joyadd:
			Joy_AddEvent( events.queue[i].arg );
			break;
		case event_joyremove:
			Joy_RemoveEvent( events.queue[i].arg );
			break;
		case event_joyball:
			Joy_BallMotionEvent( events.queue[i].arg, events.queue[i].ball.ball,
								 events.queue[i].ball.xrel, events.queue[i].ball.yrel );
			break;
		case event_joyhat:
			Joy_HatMotionEvent( events.queue[i].arg, events.queue[i].hat.hat, events.queue[i].hat.key );
			break;
		case event_joyaxis:
			Joy_AxisMotionEvent( events.queue[i].arg, events.queue[i].axis.axis, events.queue[i].axis.val );
			break;
		case event_joybutton:
			Joy_ButtonEvent( events.queue[i].arg, events.queue[i].button.button, (byte)events.queue[i].button.down );
			break;
		}
	}

	events.count = 0; // no more events

	// text input handled separately to allow unicode symbols
	for( i = 0; events.inputtext[i]; i++ )
	{
		int ch;

		// if engine does not use utf-8, we need to convert it to preferred encoding
		if( !Q_stricmp( cl_charset->string, "utf-8" ) )
			ch = (unsigned char)events.inputtext[i];
		else
			ch = Con_UtfProcessCharForce( (unsigned char)events.inputtext[i] );

		if( !ch )
			continue;

		// otherwise just push it by char, text render will decode unicode strings
		Con_CharEvent( ch );
		if( cls.key_dest == key_menu )
			UI_CharEvent ( ch );
	}
	events.inputtext[0] = 0; // no more text

	//end events read
	Android_Unlock();
	pthread_mutex_lock( &events.framemutex );
}
Пример #17
0
/*
===================
VID_Init
===================
*/
void VID_Init (unsigned char *palette)
{
	int		width, height, i, temp;
	SDL_Rect	**enumlist;
	const char	*read_vars[] = {
				"vid_config_fscr",
				"vid_config_swx",
				"vid_config_swy" };
#define num_readvars	( sizeof(read_vars)/sizeof(read_vars[0]) )

	temp = scr_disabled_for_loading;
	scr_disabled_for_loading = true;

	Cvar_RegisterVariable (&vid_config_fscr);
	Cvar_RegisterVariable (&vid_config_swy);
	Cvar_RegisterVariable (&vid_config_swx);
	Cvar_RegisterVariable (&vid_config_gly);
	Cvar_RegisterVariable (&vid_config_glx);
	Cvar_RegisterVariable (&vid_mode);
	Cvar_RegisterVariable (&_enable_mouse);
	Cvar_RegisterVariable (&vid_showload);

	Cmd_AddCommand ("vid_showinfo", VID_ShowInfo_f);
	Cmd_AddCommand ("vid_listmodes", VID_ListModes_f);
	Cmd_AddCommand ("vid_nummodes", VID_NumModes_f);
	Cmd_AddCommand ("vid_restart", VID_Restart_f);

	// init sdl
	// the first check is actually unnecessary
	if ( (SDL_WasInit(SDL_INIT_VIDEO)) == 0 )
	{
		if (SDL_Init(SDL_INIT_VIDEO) < 0)
			Sys_Error("VID: Couldn't load SDL: %s", SDL_GetError());
	}

	// this will contain the "best bpp" for the current display
	// make sure to re-retrieve it if you ever re-init sdl_video
	vid_info = SDL_GetVideoInfo();

	// retrieve the list of fullscreen modes
	enumlist = SDL_ListModes(NULL, SDL_SWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN);
	// prepare the modelists, find the actual modenum for vid_default
	VID_PrepareModes(enumlist);

	// set vid_mode to our safe default first
	Cvar_SetValue ("vid_mode", vid_default);

	// perform an early read of config.cfg
	CFG_ReadCvars (read_vars, num_readvars);

	// windowed mode is default
	// see if the user wants fullscreen
	if (COM_CheckParm("-fullscreen") || COM_CheckParm("-f"))
	{
		Cvar_SetValue("vid_config_fscr", 1);
	}
	else if (COM_CheckParm("-window") || COM_CheckParm("-w"))
	{
		Cvar_SetValue("vid_config_fscr", 0);
	}

	if (vid_config_fscr.integer && !num_fmodes) // FIXME: see below, as well
		Sys_Error ("No fullscreen modes available at this color depth");

	width = vid_config_swx.integer;
	height = vid_config_swy.integer;

	// user is always right ...
	i = COM_CheckParm("-width");
	if (i && i < com_argc-1)
	{	// FIXME: this part doesn't know about a disaster case
		// like we aren't reported any fullscreen modes.
		width = atoi(com_argv[i+1]);

		i = COM_CheckParm("-height");
		if (i && i < com_argc-1)
			height = atoi(com_argv[i+1]);
		else	// proceed with 4/3 ratio
			height = 3 * width / 4;
	}

	// user requested a mode either from the config or from the
	// command line
	// scan existing modes to see if this is already available
	// if not, add this as the last "valid" video mode and set
	// vid_mode to it only if it doesn't go beyond vid_maxwidth
	i = 0;
	while (i < *nummodes)
	{
		if (modelist[i].width == width && modelist[i].height == height)
			break;
		i++;
	}
	if (i < *nummodes)
	{
		Cvar_SetValue ("vid_mode", i);
	}
	else if ( (width <= vid_maxwidth && width >= MIN_WIDTH &&
		   height <= vid_maxheight && height >= MIN_HEIGHT) ||
		  COM_CheckParm("-force") )
	{
		modelist[*nummodes].width = width;
		modelist[*nummodes].height = height;
		modelist[*nummodes].halfscreen = 0;
		modelist[*nummodes].fullscreen = 1;
		modelist[*nummodes].bpp = 8;
		q_snprintf (modelist[*nummodes].modedesc, MAX_DESC, "%d x %d (user mode)", width, height);
		Cvar_SetValue ("vid_mode", *nummodes);
		(*nummodes)++;
	}
	else
	{
		Con_SafePrintf ("ignoring invalid -width and/or -height arguments\n");
	}

	vid.maxwarpwidth = WARP_WIDTH;
	vid.maxwarpheight = WARP_HEIGHT;
	vid.colormap = host_colormap;
	vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));

	i = VID_SetMode(vid_mode.integer, palette);
	if ( !i )
	{
		if (vid_mode.integer == vid_default)
			Sys_Error ("Couldn't set video mode: %s", SDL_GetError());

		// just one more try before dying
		Con_SafePrintf ("Couldn't set video mode %d\n"
				"Trying the default mode\n", vid_mode.integer);
		//Cvar_SetValue("vid_config_fscr", 0);
		Cvar_SetValue ("vid_mode", vid_default);
		i = VID_SetMode(vid_default, palette);
		if ( !i )
			Sys_Error ("Couldn't set video mode: %s", SDL_GetError());
	}

	// lock the early-read cvars until Host_Init is finished
	for (i = 0; i < (int)num_readvars; i++)
		Cvar_LockVar (read_vars[i]);

	scr_disabled_for_loading = temp;
	vid_initialized = true;

	vid_menudrawfn = VID_MenuDraw;
	vid_menukeyfn = VID_MenuKey;
}
Пример #18
0
/*
================
VID_MenuKey
================
*/
void VID_MenuKey (int key)
{
	if (vid_testingmode)
		return;

	switch (key)
	{
	case K_ESCAPE:
		S_LocalSound ("misc/menu1.wav");
		M_Menu_Options_f ();
		break;

	case K_UPARROW:
		S_LocalSound ("misc/menu1.wav");
		vid_line--;

		if (vid_line < 0)
			vid_line = vid_wmodes - 1;
		break;

	case K_DOWNARROW:
		S_LocalSound ("misc/menu1.wav");
		vid_line++;

		if (vid_line >= vid_wmodes)
			vid_line = 0;
		break;

	case K_LEFTARROW:
		S_LocalSound ("misc/menu1.wav");
		vid_line -= vid_column_size;

		if (vid_line < 0)
		{
			vid_line += ((vid_wmodes + (vid_column_size - 1)) /
					vid_column_size) * vid_column_size;

			while (vid_line >= vid_wmodes)
				vid_line -= vid_column_size;
		}
		break;

	case K_RIGHTARROW:
		S_LocalSound ("misc/menu1.wav");
		vid_line += vid_column_size;

		if (vid_line >= vid_wmodes)
		{
			vid_line -= ((vid_wmodes + (vid_column_size - 1)) /
					vid_column_size) * vid_column_size;

			while (vid_line < 0)
				vid_line += vid_column_size;
		}
		break;

	case K_ENTER:
		S_LocalSound ("misc/menu1.wav");
		VID_SetMode (modedescs[vid_line].modenum, vid_current_palette);
		break;

	case 'T':
	case 't':
		S_LocalSound ("misc/menu1.wav");
		if (VID_SetMode (modedescs[vid_line].modenum, vid_current_palette))
		{
			vid_testingmode = 1;
			vid_testendtime = realtime + 5.0;
		}
		break;

	case 'D':
	case 'd':
		S_LocalSound ("misc/menu1.wav");
		firstupdate = 0;
		Cvar_SetValue (_vid_default_mode, vid_modenum);
		break;

	default:
		break;
	}
}
Пример #19
0
/*
VID_Init

This routine is responsible for initializing the OS specific portions
of OpenGL.  Under Win32 this means dealing with the pixelformats and
doing the wgl interface stuff.
*/
qboolean VID_Init(void)
{
    const char *extensions;
    int ret;

    gl_driver = Cvar_Get("gl_driver", "opengl32", CVAR_ARCHIVE | CVAR_REFRESH);
    gl_drawbuffer = Cvar_Get("gl_drawbuffer", "GL_BACK", 0);
    gl_swapinterval = Cvar_Get("gl_swapinterval", "1", CVAR_ARCHIVE);
    gl_allow_software = Cvar_Get("gl_allow_software", "0", 0);
    gl_colorbits = Cvar_Get("gl_colorbits", "0", CVAR_REFRESH);
    gl_depthbits = Cvar_Get("gl_depthbits", "0", CVAR_REFRESH);
    gl_stencilbits = Cvar_Get("gl_stencilbits", "8", CVAR_REFRESH);
    gl_multisamples = Cvar_Get("gl_multisamples", "0", CVAR_REFRESH);

    // don't allow absolute or relative paths
    FS_SanitizeFilenameVariable(gl_driver);

    // load and initialize the OpenGL driver
    ret = LoadGL(gl_driver->string);

    // attempt to recover if this was a minidriver
    if (ret == FAIL_SOFT && glw.minidriver) {
        Com_Printf("...falling back to opengl32\n");
        Cvar_Reset(gl_driver);
        ret = LoadGL(gl_driver->string);
    }

    // it failed, abort
    if (ret)
        return qfalse;

    // initialize WGL extensions
    WGL_InitExtensions(QWGL_ARB_extensions_string);

    if (qwglGetExtensionsStringARB)
        extensions = qwglGetExtensionsStringARB(win.dc);
    else
        extensions = NULL;

    // fall back to GL_EXTENSIONS for legacy drivers
    if (!extensions || !*extensions)
        extensions = (const char *)qwglGetString(GL_EXTENSIONS);

    glw.extensions = WGL_ParseExtensionString(extensions);

    if (glw.extensions & QWGL_EXT_swap_control) {
        if (glw.extensions & QWGL_EXT_swap_control_tear)
            Com_Printf("...enabling WGL_EXT_swap_control(_tear)\n");
        else
            Com_Printf("...enabling WGL_EXT_swap_control\n");
        WGL_InitExtensions(QWGL_EXT_swap_control);
        gl_swapinterval->changed = gl_swapinterval_changed;
        gl_swapinterval_changed(gl_swapinterval);
    } else {
        Com_Printf("WGL_EXT_swap_control not found\n");
        Cvar_Set("gl_swapinterval", "0");
    }

    gl_drawbuffer->changed = gl_drawbuffer_changed;
    gl_drawbuffer_changed(gl_drawbuffer);

    VID_SetMode();

    return qtrue;
}
Пример #20
0
/*
================
VID_SetMode
================
*/
int VID_SetMode (int modenum, unsigned char *palette)
{
	int		stat;
	vmode_t	*pnewmode, *poldmode;

	if ((modenum >= numvidmodes) || (modenum < 0))
	{
		Cvar_SetValue (vid_mode, (float)vid_modenum);

		nomodecheck = true;
		Con_Printf ("No such video mode: %d\n", modenum);
		nomodecheck = false;

		if (pcurrentmode == NULL)
		{
			modenum = 0;	// mode hasn't been set yet, so initialize to base
							//  mode since they gave us an invalid initial mode
		}
		else
		{
			return 0;
		}
	}

	pnewmode = VID_GetModePtr (modenum);

	if (pnewmode == pcurrentmode)
		return 1;	// already in the desired mode

// initialize the new mode
	poldmode = pcurrentmode;
	pcurrentmode = pnewmode;

	vid.width = pcurrentmode->width;
	vid.height = pcurrentmode->height;
	if (!yeahimconsoled){
	vid.vconheight = pcurrentmode->width;
	vid.vconwidth = pcurrentmode->height;}	
	SCR_StretchRefresh();
	SCR_CvarCheck();	

	vid.aspect = pcurrentmode->aspect;
	vid.rowbytes = pcurrentmode->rowbytes;

	stat = (*pcurrentmode->setmode) (&vid, pcurrentmode);

	if (stat < 1)
	{
		if (stat == 0)
		{
		// real, hard failure that requires resetting the mode
			if (!VID_SetMode (vid_modenum, palette))	// restore prior mode
				Sys_Error ("VID_SetMode: Unable to set any mode, probably "
						   "because there's not enough memory available");
			Con_Printf ("Failed to set mode %d\n", modenum);
			return 0;
		}
		else if (stat == -1)
		{
		// not enough memory; just put things back the way they were
			pcurrentmode = poldmode;
			vid.width = pcurrentmode->width;
			vid.height = pcurrentmode->height;
			if (!yeahimconsoled){
			vid.vconheight = pcurrentmode->width;
			vid.vconwidth = pcurrentmode->height;}
			vid.aspect = pcurrentmode->aspect;
			vid.rowbytes = pcurrentmode->rowbytes;
			return 0;
		}
		else
		{
			Sys_Error ("VID_SetMode: invalid setmode return code %d");
		}
	}

	(*pcurrentmode->setpalette) (&vid, pcurrentmode, palette);

	vid_modenum = modenum;
	Cvar_SetValue (vid_mode, (float)vid_modenum);

	nomodecheck = true;
	Con_Printf ("%s\n", VID_ModeInfo (vid_modenum, NULL));
	nomodecheck = false;

	vid.recalc_refdef = 1;

	return 1;
}
Пример #21
0
void SCR_SetMode(void)
{
	if (dedicated)
		return;

	if (!setmodeneeded || WipeInAction)
		return; // should never happen and don't change it during a wipe, BAD!

	VID_SetMode(--setmodeneeded);

	V_SetPalette(0);

	//
	//  setup the right draw routines for either 8bpp or 16bpp
	//
	if (true)//vid.bpp == 1) //Always run in 8bpp. todo: remove all 16bpp code?
	{
		spanfunc = basespanfunc = R_DrawSpan_8;
		splatfunc = R_DrawSplat_8;
		transcolfunc = R_DrawTranslatedColumn_8;
		transtransfunc = R_DrawTranslatedTranslucentColumn_8;

		colfunc = basecolfunc = R_DrawColumn_8;
		shadecolfunc = R_DrawShadeColumn_8;
		fuzzcolfunc = R_DrawTranslucentColumn_8;
		walldrawerfunc = R_DrawWallColumn_8;
		twosmultipatchfunc = R_Draw2sMultiPatchColumn_8;
		twosmultipatchtransfunc = R_Draw2sMultiPatchTranslucentColumn_8;
#ifdef RUSEASM
		if (R_ASM)
		{
			if (R_MMX)
			{
				colfunc = basecolfunc = R_DrawColumn_8_MMX;
				//shadecolfunc = R_DrawShadeColumn_8_ASM;
				//fuzzcolfunc = R_DrawTranslucentColumn_8_ASM;
				walldrawerfunc = R_DrawWallColumn_8_MMX;
				twosmultipatchfunc = R_Draw2sMultiPatchColumn_8_MMX;
				spanfunc = basespanfunc = R_DrawSpan_8_MMX;
			}
			else
			{
				colfunc = basecolfunc = R_DrawColumn_8_ASM;
				//shadecolfunc = R_DrawShadeColumn_8_ASM;
				//fuzzcolfunc = R_DrawTranslucentColumn_8_ASM;
				walldrawerfunc = R_DrawWallColumn_8_ASM;
				twosmultipatchfunc = R_Draw2sMultiPatchColumn_8_ASM;
			}
		}
#endif
	}
/*	else if (vid.bpp > 1)
	{
		I_OutputMsg("using highcolor mode\n");
		spanfunc = basespanfunc = R_DrawSpan_16;
		transcolfunc = R_DrawTranslatedColumn_16;
		transtransfunc = R_DrawTranslucentColumn_16; // No 16bit operation for this function

		colfunc = basecolfunc = R_DrawColumn_16;
		shadecolfunc = NULL; // detect error if used somewhere..
		fuzzcolfunc = R_DrawTranslucentColumn_16;
		walldrawerfunc = R_DrawWallColumn_16;
	}*/
	else
		I_Error("unknown bytes per pixel mode %d\n", vid.bpp);
/*#if !defined (DC) && !defined (WII)
	if (SCR_IsAspectCorrect(vid.width, vid.height))
		CONS_Alert(CONS_WARNING, M_GetText("Resolution is not aspect-correct!\nUse a multiple of %dx%d\n"), BASEVIDWIDTH, BASEVIDHEIGHT);
#endif*/
	// set the apprpriate drawer for the sky (tall or INT16)
	setmodeneeded = 0;
}
Пример #22
0
// *************************************************************************************
// VID_Init
// Initialize Video modes subsystem
// *************************************************************************************
static VOID VID_Init(VOID)
{
#ifdef _DEBUG
    vmode_t *pv;
    int iMode;
#endif

    // if '-win' is specified on the command line, do not add DirectDraw modes
    bWinParm = M_CheckParm("-win");

    COM_AddCommand("vid_nummodes", VID_Command_NumModes_f);
    COM_AddCommand("vid_modeinfo", VID_Command_ModeInfo_f);
    COM_AddCommand("vid_modelist", VID_Command_ModeList_f);
    COM_AddCommand("vid_mode", VID_Command_Mode_f);

    CV_RegisterVar(&cv_vidwait);
    CV_RegisterVar(&cv_stretch);
    CV_RegisterVar(&cv_ontop);

    // setup the videmodes list,
    // note that mode 0 must always be VGA mode 0x13
    pvidmodes = pcurrentmode = NULL;
    numvidmodes = 0;

    //DisableAero();

    // store the main window handle in viddef struct
    SetWindowPos(hWndMain, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOSENDCHANGING|SWP_NOSIZE|SWP_NOMOVE);
    vid.WndParent = hWndMain;
    vid.buffer = NULL;

    // we startup in windowed mode using DIB bitmap
    // we will use DirectDraw when switching fullScreen and entering main game loop
    bDIBMode = TRUE;
    bAppFullScreen = FALSE;

#ifdef HWRENDER
    // initialize the appropriate display device
    if (rendermode != render_soft)
    {
        const char *drvname = NULL;

        switch (rendermode)
        {
        case render_opengl:
            drvname = "r_opengl.dll";
            break;
        default:
            I_Error("Unknown hardware render mode");
        }

        // load the DLL
        if (drvname && Init3DDriver(drvname))
        {
            int hwdversion = HWD.pfnGetRenderVersion();
            if (hwdversion != VERSION)
                CONS_Printf("%s", M_GetText("WARNING: This r_opengl version is not supported, use it at your own risk.\n"));

            // perform initialisations
            HWD.pfnInit(I_Error);
            // get available display modes for the device
            HWD.pfnGetModeList(&pvidmodes, &numvidmodes);
        }
        else
        {
            switch (rendermode)
            {
            case render_opengl:
                I_Error("Error initializing OpenGL");
            default:
                break;
            }
            rendermode = render_soft;
        }
    }

    if (rendermode == render_soft)
#endif
        if (!bWinParm)
        {
            if (!CreateDirectDrawInstance())
                bWinParm = TRUE;
            else // get available display modes for the device
                VID_GetExtraModes();
        }

    // the game boots in 320x200 standard VGA, but
    // we need a highcolor mode to run the game in highcolor
    if (highcolor && !numvidmodes)
        I_Error("Cannot run in highcolor - No 15bit highcolor DirectX video mode found.");

    // add windowed mode at the start of the list, very important!
    WindowMode_Init();

    if (!numvidmodes)
        I_Error("No display modes available.");

#ifdef _DEBUG // DEBUG
    for (iMode = 0, pv = pvidmodes; pv; pv = pv->pnext, iMode++)
        DEBPRINT(va("#%02d: %dx%dx%dbpp (desc: '%s')\n", iMode, pv->width, pv->height, pv->bytesperpixel, pv->name));
#endif

    // set the startup screen in a window
    VID_SetMode(0);
}
Пример #23
0
void SCR_SetMode(void)
{
	if (dedicated)
		return;

	if (!setmodeneeded || WipeInAction)
		return; // should never happen and don't change it during a wipe, BAD!

	VID_SetMode(--setmodeneeded);

	V_SetPalette(0);

	//
	//  setup the right draw routines for either 8bpp or 16bpp
	//
	if (true)//vid.bpp == 1) //Always run in 8bpp. todo: remove all 16bpp code?
	{
		basespanfunc = R_DrawSpan_8;
		spanfunc = basespanfunc;
		splatfunc = R_DrawSplat_8;
		transcolfunc = R_DrawTranslatedColumn_8;
		transtransfunc = R_DrawTranslatedTranslucentColumn_8;

		colfunc = basecolfunc = R_DrawColumn_8;
		shadecolfunc = R_DrawShadeColumn_8;
		fuzzcolfunc = R_DrawTranslucentColumn_8;
		walldrawerfunc = R_DrawWallColumn_8;
#ifdef RUSEASM
		if (R_ASM)
		{
			//colfunc = basecolfunc = R_DrawColumn_8_ASM;
			shadecolfunc = R_DrawShadeColumn_8_ASM;
//			fuzzcolfunc = R_DrawTranslucentColumn_8_ASM;
			//walldrawerfunc = R_DrawWallColumn_8_ASM;
		}
/*		if (R_486)
		{
			colfunc = basecolfunc = R_DrawColumn_8_NOMMX;
			CONS_Printf("using 486 code\n");
		}
		if (R_586)
		{
			colfunc = basecolfunc = R_DrawColumn_8_Pentium;
			CONS_Printf("upgrading to 586 code\n");
		}
		if (R_MMX)
		{
			colfunc = basecolfunc = R_DrawColumn_8_K6_MMX;
			CONS_Printf("now using cool MMX code\n");
		}*/
#endif
	}
/*	else if (vid.bpp > 1)
	{
		CONS_Printf("using highcolor mode\n");
		spanfunc = basespanfunc = R_DrawSpan_16;
		transcolfunc = R_DrawTranslatedColumn_16;
		transtransfunc = R_DrawTranslucentColumn_16; // No 16bit operation for this function

		colfunc = basecolfunc = R_DrawColumn_16;
		shadecolfunc = NULL; // detect error if used somewhere..
		fuzzcolfunc = R_DrawTranslucentColumn_16;
		walldrawerfunc = R_DrawWallColumn_16;
	}*/
	else
		I_Error("unknown bytes per pixel mode %d\n", vid.bpp);
#ifndef DC
	if (vid.width % BASEVIDWIDTH || vid.height % BASEVIDHEIGHT)
		CONS_Printf("WARNING: Resolution is not aspect-correct!\n"
			"Use a multiple of %dx%d\n", BASEVIDWIDTH, BASEVIDHEIGHT);
#endif
	// set the apprpriate drawer for the sky (tall or INT16)
	setmodeneeded = 0;
}