Пример #1
0
func (e *PU_Engine) Init() {
	//Create the window
	var err string
	e.window, err = sdl.CreateWindow("Pokemon Universe", WINDOW_WIDTH, WINDOW_HEIGHT)
	if err != "" {
		fmt.Printf("Error in CreateWindow: %v", err)
		return
	}

	//Find our available renderers
	openglIndex := -1
	d3dIndex := -1
	numRenderers := sdl.GetNumRenderDrivers()
	for i := 0; i < numRenderers; i++ {
		rendererName := sdl.GetRenderDriverName(i)
		if rendererName == "opengl" {
			openglIndex = i
		} else if rendererName == "direct3d" {
			d3dIndex = i
		}
	}

	rendererIndex := 0
	if openglIndex == -1 && d3dIndex == -1 {
		println("No OpenGL or D3D found! Using software renderer.")
	} else {
		//Default renderer is OpenGL
		rendererIndex = openglIndex
	}

	//If we found DirectX (on Windows), use that
	if d3dIndex != -1 {
		rendererIndex = d3dIndex
		if !e.TryD3D(rendererIndex) {
			e.renderer, err = sdl.CreateRenderer(e.window, rendererIndex)
			if err != "" {
				fmt.Printf("Error in CreateRenderer (tried D3D): %v", err)
				return
			}
		}
	} else {
		e.renderer, err = sdl.CreateRenderer(e.window, rendererIndex)
		if err != "" {
			fmt.Printf("Error in CreateRenderer: %v", err)
			return
		}
	}

	sdl.InitTTF()
}
Пример #2
0
//Internal initalization (executes when game starts)
func (game *Game) initialize() {
	//Create the window
	var err string
	game.window, err = sdl.CreateWindow(game.title, game.width, game.height)
	if err != "" {
		panic(fmt.Sprintf("Go2D Error: Creating window: %s", err))
	}

	//Create the renderer

	//Find our available renderers
	openglIndex := 0
	d3dIndex := -1
	numRenderers := sdl.GetNumRenderDrivers()
	for i := 0; i < numRenderers; i++ {
		rendererName := sdl.GetRenderDriverName(i)
		if rendererName == "opengl" {
			openglIndex = i
		} else if rendererName == "direct3d" {
			d3dIndex = i
		}
	}

	//Default renderer is OpenGL
	rendererIndex := openglIndex

	//If we want to use Direct3D and we found it, use it
	if game.d3d && d3dIndex != -1 {
		rendererIndex = d3dIndex
	}

	game.renderer, err = sdl.CreateRenderer(game.window, rendererIndex)
	if err != "" {
		panic(fmt.Sprintf("Go2D Error: Creating renderer: %s", err))
	}

	//initialize font rendering
	sdl.InitTTF()

	//Call the user-defined init function
	if game.initFun != nil {
		game.initFun()
	}

	g_running = true
}