Exemplo n.º 1
0
// NewWebGlWindow tries to initialize the WebGL environment and returns a
// new window instance.
func NewWebGlWindow(canvas *js.Object) (window *WebGlWindow, err error) {
	attrs := webgl.DefaultAttributes()
	attrs.Alpha = false

	glContext, err := webgl.NewContext(canvas, attrs)
	if err == nil {
		window = &WebGlWindow{
			AbstractOpenGlWindow: env.InitAbstractOpenGlWindow(),

			canvas:    canvas,
			glWrapper: NewWebGl(glContext)}

		window.registerMouseListener()
		window.startRenderLoop()
	}

	return
}
Exemplo n.º 2
0
// NewOpenGlWindow tries to initialize the OpenGL environment and returns a
// new window instance.
func NewOpenGlWindow() (window *OpenGlWindow, err error) {
	if err = glfw.Init(); err == nil {
		glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLAPI)
		glfw.WindowHint(glfw.ContextVersionMajor, 3)
		glfw.WindowHint(glfw.ContextVersionMinor, 2)
		glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
		glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
		var glfwWindow *glfw.Window
		glfwWindow, err = glfw.CreateWindow(320, 200, "shocked", nil, nil)
		if err == nil {
			glfwWindow.MakeContextCurrent()

			window = &OpenGlWindow{
				AbstractOpenGlWindow: env.InitAbstractOpenGlWindow(),
				glfwWindow:           glfwWindow,
				glWrapper:            NewOpenGl()}

			glfwWindow.SetCursorPosCallback(window.onCursorPos)
			glfwWindow.SetMouseButtonCallback(window.onMouseButton)
			glfwWindow.SetScrollCallback(window.onMouseScroll)
		}
	}
	return
}