From 4480f61a0ad79bab9f9fa74de135ba2ad8f06542 Mon Sep 17 00:00:00 2001 From: faiface Date: Wed, 23 Nov 2016 23:25:45 +0100 Subject: [PATCH] fixes --- pixelgl/shader.go | 3 +++ pixelgl/texture.go | 3 +++ pixelgl/vertex.go | 3 +++ window.go | 29 +++++++++++++++++++++-------- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/pixelgl/shader.go b/pixelgl/shader.go index bcd0d94..bd03373 100644 --- a/pixelgl/shader.go +++ b/pixelgl/shader.go @@ -17,6 +17,9 @@ type Shader struct { // // Note that vertexShader and fragmentShader parameters must contain the source code, they're not filenames. func NewShader(parent BeginEnder, vertexShader, fragmentShader string) (*Shader, error) { + parent.Begin() + defer parent.End() + shader := &Shader{ parent: parent, } diff --git a/pixelgl/texture.go b/pixelgl/texture.go index 0218730..b2ba8ce 100644 --- a/pixelgl/texture.go +++ b/pixelgl/texture.go @@ -14,6 +14,9 @@ type Texture struct { // NewTexture creates a new texture with the specified width and height. // The pixels must be a sequence of RGBA values. func NewTexture(parent BeginEnder, width, height int, pixels []uint8) (*Texture, error) { + parent.Begin() + defer parent.End() + texture := &Texture{parent: parent} err := DoGLErr(func() { gl.GenTextures(1, &texture.tex) diff --git a/pixelgl/vertex.go b/pixelgl/vertex.go index db021c5..e25fad7 100644 --- a/pixelgl/vertex.go +++ b/pixelgl/vertex.go @@ -100,6 +100,9 @@ type VertexArray struct { // NewVertexArray creates a new vertex array and wraps another BeginEnder around it. func NewVertexArray(parent BeginEnder, format VertexFormat, mode VertexDrawMode, usage VertexUsage, data []float64) (*VertexArray, error) { + parent.Begin() + defer parent.End() + va := &VertexArray{ parent: parent, format: format, diff --git a/window.go b/window.go index 25ef5b4..d725ebd 100644 --- a/window.go +++ b/window.go @@ -2,6 +2,7 @@ package pixel import ( "github.com/faiface/pixel/pixelgl" + "github.com/go-gl/gl/v3.3-core/gl" "github.com/go-gl/glfw/v3.2/glfw" "github.com/pkg/errors" ) @@ -59,26 +60,38 @@ func NewWindow(config WindowConfig) (*Window, error) { return w, nil } -func (w *Window) Update() { +func (w *Window) Clear(r, g, b, a float64) { + w.Begin() + pixelgl.Do(func() { + gl.ClearColor(float32(r), float32(g), float32(b), float32(a)) + gl.Clear(gl.COLOR_BUFFER_BIT) + }) + w.End() +} + +func (w *Window) Update() { + w.Begin() pixelgl.Do(func() { - w.Begin() if w.config.VSync { glfw.SwapInterval(1) } w.window.SwapBuffers() glfw.PollEvents() - w.End() }) + w.End() } var currentWindow *Window = nil func (w *Window) Begin() { - if currentWindow != w { - w.window.MakeContextCurrent() - pixelgl.Init() - currentWindow = w - } + pixelgl.Do(func() { + if currentWindow != w { + w.window.MakeContextCurrent() + pixelgl.Init() + currentWindow = w + } + }) + } func (w *Window) End() {