Пример #1
0
func NewGLRenderer(view *View, title string) *GLRenderer {
	r := new(GLRenderer)
	r.View = view
	GL <- func() {
		if sdl.Init(sdl.INIT_VIDEO) < 0 {
			panic(sdl.GetError())
		}
		sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1)
		sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1)
		r.Screen = sdl.SetVideoMode(view.Width, view.Height, 32, sdl.OPENGL)
		if r.Screen == nil {
			panic(sdl.GetError())
		}
		sdl.WM_SetCaption(title, title)
		err := gl33.Init()
		if err != nil {
			panic(err)
		}
		gl33.Enable(gl33.BLEND)
		gl33.Enable(gl33.CULL_FACE)
		gl33.Enable(gl33.DEPTH_TEST)
		gl33.ClearColor(1.0, 1.0, 1.0, 1.0)
		gl33.BlendFunc(gl33.SRC_ALPHA, gl33.ONE_MINUS_SRC_ALPHA)
		gl33.DepthFunc(gl33.LEQUAL)
		gl33.Viewport(0, 0, gl33.Sizei(view.Width), gl33.Sizei(view.Height))
	}
	r.PerspectiveMatrix = s3dm.PerspectiveMatrix(view.Fovy, view.Aspect, view.Near, view.Far)
	r.OrthographicMatrix = s3dm.OrthographicMatrix(float64(view.Width), float64(view.Height), 0, 1)
	return r
}
Пример #2
0
func (r *GLRenderer) UpdatePerspective() {
	r.PerspectiveMatrix = s3dm.PerspectiveMatrix(r.View.Fovy, r.View.Aspect, r.View.Near, r.View.Far)
}