fixes
This commit is contained in:
parent
eb316e5126
commit
4480f61a0a
|
@ -17,6 +17,9 @@ type Shader struct {
|
||||||
//
|
//
|
||||||
// Note that vertexShader and fragmentShader parameters must contain the source code, they're not filenames.
|
// Note that vertexShader and fragmentShader parameters must contain the source code, they're not filenames.
|
||||||
func NewShader(parent BeginEnder, vertexShader, fragmentShader string) (*Shader, error) {
|
func NewShader(parent BeginEnder, vertexShader, fragmentShader string) (*Shader, error) {
|
||||||
|
parent.Begin()
|
||||||
|
defer parent.End()
|
||||||
|
|
||||||
shader := &Shader{
|
shader := &Shader{
|
||||||
parent: parent,
|
parent: parent,
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,9 @@ type Texture struct {
|
||||||
// NewTexture creates a new texture with the specified width and height.
|
// NewTexture creates a new texture with the specified width and height.
|
||||||
// The pixels must be a sequence of RGBA values.
|
// The pixels must be a sequence of RGBA values.
|
||||||
func NewTexture(parent BeginEnder, width, height int, pixels []uint8) (*Texture, error) {
|
func NewTexture(parent BeginEnder, width, height int, pixels []uint8) (*Texture, error) {
|
||||||
|
parent.Begin()
|
||||||
|
defer parent.End()
|
||||||
|
|
||||||
texture := &Texture{parent: parent}
|
texture := &Texture{parent: parent}
|
||||||
err := DoGLErr(func() {
|
err := DoGLErr(func() {
|
||||||
gl.GenTextures(1, &texture.tex)
|
gl.GenTextures(1, &texture.tex)
|
||||||
|
|
|
@ -100,6 +100,9 @@ type VertexArray struct {
|
||||||
|
|
||||||
// NewVertexArray creates a new vertex array and wraps another BeginEnder around it.
|
// 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) {
|
func NewVertexArray(parent BeginEnder, format VertexFormat, mode VertexDrawMode, usage VertexUsage, data []float64) (*VertexArray, error) {
|
||||||
|
parent.Begin()
|
||||||
|
defer parent.End()
|
||||||
|
|
||||||
va := &VertexArray{
|
va := &VertexArray{
|
||||||
parent: parent,
|
parent: parent,
|
||||||
format: format,
|
format: format,
|
||||||
|
|
19
window.go
19
window.go
|
@ -2,6 +2,7 @@ package pixel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/faiface/pixel/pixelgl"
|
"github.com/faiface/pixel/pixelgl"
|
||||||
|
"github.com/go-gl/gl/v3.3-core/gl"
|
||||||
"github.com/go-gl/glfw/v3.2/glfw"
|
"github.com/go-gl/glfw/v3.2/glfw"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
@ -59,26 +60,38 @@ func NewWindow(config WindowConfig) (*Window, error) {
|
||||||
return w, nil
|
return w, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) Update() {
|
func (w *Window) Clear(r, g, b, a float64) {
|
||||||
pixelgl.Do(func() {
|
|
||||||
w.Begin()
|
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() {
|
||||||
if w.config.VSync {
|
if w.config.VSync {
|
||||||
glfw.SwapInterval(1)
|
glfw.SwapInterval(1)
|
||||||
}
|
}
|
||||||
w.window.SwapBuffers()
|
w.window.SwapBuffers()
|
||||||
glfw.PollEvents()
|
glfw.PollEvents()
|
||||||
w.End()
|
|
||||||
})
|
})
|
||||||
|
w.End()
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentWindow *Window = nil
|
var currentWindow *Window = nil
|
||||||
|
|
||||||
func (w *Window) Begin() {
|
func (w *Window) Begin() {
|
||||||
|
pixelgl.Do(func() {
|
||||||
if currentWindow != w {
|
if currentWindow != w {
|
||||||
w.window.MakeContextCurrent()
|
w.window.MakeContextCurrent()
|
||||||
pixelgl.Init()
|
pixelgl.Init()
|
||||||
currentWindow = w
|
currentWindow = w
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) End() {
|
func (w *Window) End() {
|
||||||
|
|
Loading…
Reference in New Issue