예제 #1
0
bool BaseApp::Init()
{
	
	m_gameTimer.Reset();
	GetEntityRoot()->SetName("root");

	if (m_bInitted)	
	{
		LogMsg("Why are we initting more than once?");
		return true;
	}

	m_bInitted = true;

	CHECK_GL_ERROR();

	PrintGLString("Version", GL_VERSION);
	PrintGLString("Vendor", GL_VENDOR);
	PrintGLString("Renderer", GL_RENDERER);
	PrintGLString("Extensions", GL_EXTENSIONS);

	InitializeGLDefaults();
	
	GLint depthbits;
	glGetIntegerv(GL_DEPTH_BITS, &depthbits);
	LogMsg("GL depth buffer: %d bit", depthbits);

	CHECK_GL_ERROR();

	if (GetAudioManager())
	{
		GetAudioManager()->Init();
	}

	return true;
}
예제 #2
0
bool App::Init( bool bFullScreen, unsigned int displayWidth, unsigned int displayHeight )
{
	if( SDL_Init( SDL_INIT_EVERYTHING ) != 0)
	{
		fprintf( stderr, "SDL failed to initialise: %s\n",SDL_GetError() );
		return false;
	}

	printf( "SDL initialised\n" );

	SDL_version compiledVersion;
	SDL_version linkedVersion;
	SDL_VERSION( &compiledVersion );
	SDL_GetVersion( &linkedVersion );
	print_SDL_version( "Compiled against SDL version", compiledVersion );
	print_SDL_version( "Linking against SDL version", linkedVersion );
	SDL_assert_release( (compiledVersion == linkedVersion) );

	int numDisplays = SDL_GetNumVideoDisplays();
	printf( "%d video displays\n", numDisplays );
	for( int i = 0; i < numDisplays; ++i )
	{
		SDL_DisplayMode displayMode;
		if( SDL_GetCurrentDisplayMode(i, &displayMode) != 0 )
		{
			fprintf( stderr, "Failed to get display mode for video display %d: %s", i, SDL_GetError() );
			continue;
		}

		printf( "Display %d: w=%d, h=%d refresh_rate=%d\n", i, displayMode.w, displayMode.h, displayMode.refresh_rate );
   	}

#ifdef GL_ES_VERSION_2_0
	SetGLAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
	SetGLAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
	SetGLAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
#endif

	const char* title = "SDL Window";
	if( bFullScreen )
	{
	  HP_FATAL_ERROR("Just checking");
		m_pWindow = SDL_CreateWindow( title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP );
	}
	else
	{
	  m_pWindow = SDL_CreateWindow( title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, displayWidth, displayHeight, SDL_WINDOW_SHOWN /*| SDL_WINDOW_OPENGL*/ );
	}

	if( !m_pWindow )
	{
		printf( "Failed to create SDL window: %s\n", SDL_GetError() );
		return false;
	}

#ifdef GL_ES_VERSION_2_0
	// Let's see if we can use OpenGL ES 2 on Raspberry Pi
	SDL_GLContext gl_context = SDL_GL_CreateContext(m_pWindow);
	printf("GL_VERSION: "); 
	PrintGLString(GL_VERSION);
	printf("GL_RENDERER: ");
	PrintGLString(GL_RENDERER);
	printf("GL_SHADING_LANGUAGE_VERSION: ");
	PrintGLString(GL_SHADING_LANGUAGE_VERSION);
	printf("GL_EXTENSIONS: ");
	PrintGLString(GL_EXTENSIONS);
	SDL_GL_DeleteContext(gl_context);
#endif

	// SDL2_ttf

	if( TTF_Init() == -1 )
	{
		fprintf( stderr, "Failed to initialise SDL2_ttf: %s\n", TTF_GetError() );
		return false;
	}

	printf( "SDL_ttf initialised\n" );

	SDL_TTF_VERSION( &compiledVersion );
	const SDL_version *pLinkedVersion = TTF_Linked_Version();
	print_SDL_version( "Compiled against SDL_ttf version", compiledVersion );
	print_SDL_version( "Linking against SDL_ttf version", *pLinkedVersion );

	unsigned int logicalWidth = 1280;
	unsigned int logicalHeight = 720;
	m_pRenderer = new Renderer( *m_pWindow, logicalWidth, logicalHeight );

	m_pGame = new Game();

	if( !m_pGame->Init() )
	{
		fprintf( stderr, "ERROR - Game failed to initialise\n" );
		return false;
	}

	return true;
}