示例#1
0
func InitGL(width, height, msaa int, fullscreen bool) {
	C.SDL_Init(C.SDL_INIT_VIDEO)
	C.SDL_VideoInit( /*nil*/ C.SDL_GetVideoDriver(0))
	C.SDL_GL_SetAttribute(C.SDL_GL_CONTEXT_MAJOR_VERSION, 3)
	C.SDL_GL_SetAttribute(C.SDL_GL_CONTEXT_MINOR_VERSION, 2)

	if msaa != 0 {
		C.SDL_GL_SetAttribute(C.SDL_GL_MULTISAMPLEBUFFERS, 1)
		C.SDL_GL_SetAttribute(C.SDL_GL_MULTISAMPLESAMPLES, C.int(msaa))
	}

	C.SDL_GL_SetAttribute(C.SDL_GL_DEPTH_SIZE, 16)
	//win = C.SDL_CreateWindow(nil, C.SDL_WINDOWPOS_CENTERED, C.SDL_WINDOWPOS_CENTERED,C.int(width), C.int(height), C.SDL_WINDOW_OPENGL)
	if fullscreen {
		win = C.SDL_CreateWindow(nil, C.SDL_WINDOWPOS_CENTERED, C.SDL_WINDOWPOS_CENTERED, C.int(width), C.int(height), C.SDL_WINDOW_OPENGL|C.SDL_WINDOW_FULLSCREEN_DESKTOP)
	} else {
		win = C.SDL_CreateWindow(nil, C.SDL_WINDOWPOS_CENTERED, C.SDL_WINDOWPOS_CENTERED, C.int(width), C.int(height), C.SDL_WINDOW_OPENGL)
	}

	C.SDL_ShowWindow(win)
	wat := C.SDL_GL_CreateContext(win)
	fmt.Println(C.GoString(C.SDL_GetVideoDriver(0)))

	C.SDL_GL_MakeCurrent(win, wat)
	//C.SDL_GL_SetSwapInterval(1)

	C.glEnable(C.GL_DEPTH_TEST)
	C.glDepthFunc(C.GL_LEQUAL)

	C.glClearColor(0.3, 0.5, 1, 0)
	C.glClear(C.GL_COLOR_BUFFER_BIT | C.GL_DEPTH_BUFFER_BIT)
	printerr("failed to initialize openGL")

}
示例#2
0
// New returns a newly created Screen
func New(width int, height int, fullscreen bool, FSAA int, name string) *Screen {
	window := &Screen{}

	C.SDL_Init(C.SDL_INIT_VIDEO)
	C.setGlContextAttributes()

	C.SDL_GL_SetAttribute(C.SDL_GL_DOUBLEBUFFER, 1)

	// Force hardware accel
	C.SDL_GL_SetAttribute(C.SDL_GL_ACCELERATED_VISUAL, 1)

	if FSAA > 0 {
		// FSAA (Fullscreen antialiasing)
		C.SDL_GL_SetAttribute(C.SDL_GL_MULTISAMPLEBUFFERS, 1)
		C.SDL_GL_SetAttribute(C.SDL_GL_MULTISAMPLESAMPLES, C.int(FSAA)) // 2, 4, 8
	}

	flags := C.SDL_WINDOW_OPENGL | C.SDL_RENDERER_ACCELERATED
	if fullscreen {
		flags = flags | C.SDL_WINDOW_FULLSCREEN
	}

	C.SDL_CreateWindowAndRenderer(C.int(width), C.int(height), C.Uint32(flags), &window.sdlWindow, &window.renderer)
	C.SDL_SetWindowTitle(window.sdlWindow, C.CString(name))
	C.SDL_GL_CreateContext(window.sdlWindow)

	if err := gl.Init(); err != nil {
		panic(err)
	}
	version := gl.GoStr(gl.GetString(gl.VERSION))
	fmt.Println("OpenGL version", version)

	// Configure global settings
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	window.Width = width
	window.Height = height
	window.name = name
	window.shouldClose = false
	C.SDL_GL_SwapWindow(window.sdlWindow)

	window.startTime = time.Now()
	window.frameTime = time.Now()
	C.SDL_GL_SetSwapInterval(1)
	window.vsync = true

	return window
}
示例#3
0
文件: video.go 项目: DeedleFake/sdl
func GL_SetAttribute(attr GLattr, val int) error {
	if C.SDL_GL_SetAttribute(C.SDL_GLattr(attr), C.int(val)) != 0 {
		return getError()
	}

	return nil
}
示例#4
0
//Opens a window.
//Returns an indicator of success.
func OpenDisplay(width, height int, fullscreen bool) bool {
	if C.SDL_Init(C.SDL_INIT_VIDEO) != 0 {
		return false
	}
	C.TTF_Init()
	var flags C.Uint32 = C.SDL_DOUBLEBUF
	flags |= C.SDL_SWSURFACE
	flags |= C.SDL_HWACCEL

	if fullscreen {
		screen = C.openDisplayFullscreen(C.int(width), C.int(height))
	} else {
		screen = C.openDisplay(C.int(width), C.int(height))
	}
	if screen == nil {
		return false
	}
	C.SDL_WM_SetCaption(C.CString(displayTitle), C.CString(""))
	C.SDL_GL_SetAttribute(C.SDL_GL_SWAP_CONTROL, 1)

	return true
}
示例#5
0
文件: sdl.go 项目: kearsley/Go-SDL
func GL_SetAttribute(attr int, value int) int {
	GlobalMutex.Lock()
	status := int(C.SDL_GL_SetAttribute(C.SDL_GLattr(attr), C.int(value)))
	GlobalMutex.Unlock()
	return status
}
示例#6
0
文件: sdl.go 项目: gnanderson/Go-SDL
func GL_SetAttribute(attr int, value int) int {
	return int(C.SDL_GL_SetAttribute(C.SDL_GLattr(attr), C.int(value)))
}
示例#7
0
文件: video.go 项目: henkman/Go2D
func GL_SetAttribute(attribute GLattr, value int) (err error) {
	if C.SDL_GL_SetAttribute(C.SDL_GLattr(attribute), C.int(value)) != 0 {
		return errors.New(C.GoString(C.SDL_GetError()))
	}
	return nil
}
示例#8
0
文件: video.go 项目: krig/Go-SDL2
func GL_SetAttribute(attr int, value int) int {
	status := int(C.SDL_GL_SetAttribute(C.SDL_GLattr(attr), C.int(value)))
	return status
}
示例#9
0
func GL_SetAttribute(attribute uint32, value int) int {
	_attribute := (C.SDL_GLattr)(attribute)
	_value := (C.int)(value)
	return (int)(C.SDL_GL_SetAttribute(_attribute, _value))
}
示例#10
0
文件: video.go 项目: flazz/go-sdl2
// GL_SetAttribute (https://wiki.libsdl.org/SDL_GL_SetAttribute)
func GL_SetAttribute(attr GLattr, value int) error {
	if C.SDL_GL_SetAttribute(attr.c(), C.int(value)) != 0 {
		return GetError()
	}
	return nil
}
示例#11
0
文件: video.go 项目: JalfResi/go-sdl2
func GL_SetAttribute(attr GLattr, value int) int {
	return int(C.SDL_GL_SetAttribute(attr.c(), C.int(value)))
}