示例#1
0
/**************************
 * Sets up Dialogs
 * as well as GUI code
 **************************/
int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int iCmdShow)
{
    WNDCLASS wc;
    HWND hWnd;
    HDC hDC;
    HGLRC hRC;        
    MSG msg;
    BOOL bQuit = FALSE;
    /* register window class */
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "GLTEST";
    RegisterClass (&wc);
    hWnd = CreateWindow ("GLTEST", "", WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
    0, 0, 0,0, //a quick kludge to stop a window being shown, only main DLG is shown
    NULL, NULL, hInstance, NULL); //as we need a OpenGL window
    EnableOpenGL ();
	LoadBASS();
	InitSoundSystem(hWnd);
    DialogBox (hInstance, MAKEINTRESOURCE(IDD_DLG1 ), hWnd, TestDlgProc);
	return true;
}
示例#2
0
///////////////////
// Initialize the standard Auxiliary Library
int InitializeAuxLib(const std::string& config, int bpp, int vidflags)
{
	// We have already loaded all options from the config file at this time.

#ifdef linux
	//XInitThreads();	// We should call this before any SDL video stuff and window creation
#endif


	ConfigFile=config;

	if(getenv("SDL_VIDEODRIVER"))
		notes << "SDL_VIDEODRIVER=" << getenv("SDL_VIDEODRIVER") << endl;

	// Solves problem with FPS in fullscreen
#ifdef WIN32
	if(!getenv("SDL_VIDEODRIVER")) {
		notes << "SDL_VIDEODRIVER not set, setting to directx" << endl;
		putenv((char*)"SDL_VIDEODRIVER=directx");
	}
#endif

	// Initialize SDL
	int SDLflags = SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE;
	if(!bDedicated) {
		SDLflags |= SDL_INIT_VIDEO;
	} else {
		hints << "DEDICATED MODE" << endl;
		bDisableSound = true;
		bJoystickSupport = false;
	}

	if(SDL_Init(SDLflags) == -1) {
		errors << "Failed to initialize the SDL system!\nErrorMsg: " << std::string(SDL_GetError()) << endl;
#ifdef WIN32
		// retry it with any available video driver
		unsetenv("SDL_VIDEODRIVER");
		if(SDL_Init(SDLflags) != -1)
			hints << "... but we have success with the any driver" << endl;
		// retry with windib
		else if(putenv((char*)"SDL_VIDEODRIVER=windib") == 0 && SDL_Init(SDLflags) != -1)
			hints << "... but we have success with the windib driver" << endl;
		else
#endif
		return false;
	}

#ifndef DISABLE_JOYSTICK
	if(bJoystickSupport) {
		if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0) {
			warnings << "WARNING: couldn't init joystick subystem: " << SDL_GetError() << endl;
			bJoystickSupport = false;
		}
	}
#endif

	if(!bDedicated && !SetVideoMode())
		return false;

    // Enable the system events
    SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
	SDL_EventState(SDL_VIDEOEXPOSE, SDL_ENABLE);

	// Enable unicode and key repeat
	SDL_EnableUNICODE(1);
	SDL_EnableKeyRepeat(200,20);

	
	/*
	Note about the different sound vars:
	  bDisableSound - if the sound system+driver is disabled permanentely
	  tLXOptions->bSoundOn - if the sound is enabled temporarely (false -> volume=0, nothing else)

	I.e., even with tLXOptions->bSoundOn=false (Audio.Enabled=false in config), the sound system
	will be loaded. To start OLX without the sound system, use the -nosound parameter.

	The console variable Audio.Enabled links to tLXOptions->bSoundOn.
	The console command 'sound' also wraps around tLXOptions->bSoundOn.

	tLXOptions->iSoundVolume will never be touched by OLX itself, only the user can modify it.
	tLXOptions->bSoundOn will also not be touched by OLX itself, only user actions can modify it.
	(Both points were somewhat broken earlier and kind of annoying.)
	*/
	
    if( !bDisableSound ) {
	    // Initialize sound
		//if(!InitSoundSystem(22050, 1, 512)) {
		if(!InitSoundSystem(44100, 1, 512)) {
		    warnings << "Failed the initialize the sound system" << endl;
			bDisableSound = true;
		}
    }
	if(bDisableSound) {
		notes << "soundsystem completly disabled" << endl;
		// NOTE: Don't change tLXOptions->bSoundOn here!
	}

	if( tLXOptions->bSoundOn ) {
		StartSoundSystem();
	}
	else
		StopSoundSystem();


	// Give a seed to the random number generator
	srand((unsigned int)time(NULL));

	if(!bDedicated) {
		SmartPointer<SDL_Surface> bmpIcon = LoadGameImage("data/icon.png", true);
		if(bmpIcon.get())
			SDL_WM_SetIcon(bmpIcon.get(), NULL);
	}

	InitEventQueue();
	
	// Initialize the keyboard & mouse
	InitEventSystem();

	// Initialize timers
	InitializeTimers();

#ifdef DEBUG
	// Cache
	InitCacheDebug();
#endif


	return true;
}