Esempio n. 1
0
func Initialize(window egl.NativeWindowType, configAttr, contextAttr []int32) {
	platform.Display = egl.GetDisplay(egl.DEFAULT_DISPLAY)
	if ok := egl.Initialize(platform.Display, nil, nil); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.ChooseConfig(platform.Display, configAttr, &platform.Config, 1, &platform.NumConfig); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.GetConfigAttrib(platform.Display, platform.Config, egl.NATIVE_VISUAL_ID, &platform.VisualId); !ok {
		egl.LogError(egl.GetError())
	}
	egl.BindAPI(egl.OPENGL_ES_API)
	platform.Context = egl.CreateContext(platform.Display, platform.Config, egl.NO_CONTEXT, &contextAttr[0])
	platform.Surface = egl.CreateWindowSurface(platform.Display, platform.Config, window, nil)
	if ok := egl.MakeCurrent(platform.Display, platform.Surface, platform.Surface, platform.Context); !ok {
		egl.LogError(egl.GetError())
	}
	var val int32
	if ok := egl.QuerySurface(platform.Display, &val, egl.WIDTH, platform.Surface); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.QuerySurface(platform.Display, &val, egl.HEIGHT, platform.Surface); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.GetConfigAttrib(platform.Display, platform.Config, egl.SURFACE_TYPE, &val); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.GetConfigAttrib(platform.Display, platform.Config, egl.SURFACE_TYPE, &val); !ok {
		egl.LogError(egl.GetError())
	}
	if (val & egl.WINDOW_BIT) == 0 {
		panic("No WINDOW_BIT")
	}
}
Esempio n. 2
0
func initialize() {
	var err error
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}
	mousebind.Initialize(X)
	newWindow(X)
	go xevent.Main(X)

	display = egl.GetDisplay(egl.DEFAULT_DISPLAY)
	if ok := egl.Initialize(display, nil, nil); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.ChooseConfig(display, attr, &config, 1, &numConfig); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.GetConfigAttrib(display, config, egl.NATIVE_VISUAL_ID, &vid); !ok {
		egl.LogError(egl.GetError())
	}
	egl.BindAPI(egl.OPENGL_ES_API)
	context = egl.CreateContext(display, config, egl.NO_CONTEXT, nil)
	surface = egl.CreateWindowSurface(display, config,
		egl.NativeWindowType(uintptr(X.RootWin())), nil)

	var val egl.Int
	if ok := egl.QuerySurface(display, &val, egl.WIDTH, surface); !ok {
		egl.LogError(egl.GetError())
	}

	if ok := egl.QuerySurface(display, &val, egl.HEIGHT, surface); !ok {
		egl.LogError(egl.GetError())
	}
	if ok := egl.GetConfigAttrib(display, config, egl.SURFACE_TYPE, &val); !ok {
		egl.LogError(egl.GetError())
	}
	gl.ClearColor(0.0, 0, 0, 1.0)

	p := Program(FragmentShader(fsh), VertexShader(vsh))
	gl.UseProgram(p)
	gl.BindAttribLocation(p, gl.Uint(attrPos), "pos")
	gl.BindAttribLocation(p, gl.Uint(attrColor), "color")
	uMatrix = gl.Int(gl.GetUniformLocation(p, "modelviewProjection"))

}