Bug fix: glfw's framebuffer might be lately changed after consuming some events

This commit is contained in:
Hajime Hoshi 2014-12-26 20:44:15 +09:00
parent ce81251730
commit 48f639db02
3 changed files with 22 additions and 4 deletions

View File

@ -66,10 +66,10 @@ func (c *graphicsContext) postUpdate() error {
}
scale := float64(c.screenScale)
option := &DrawImageOptions{
options := &DrawImageOptions{
GeometryMatrix: ScaleGeometry(scale, scale),
}
if err := c.defaultR.drawImage(c.screen, option); err != nil {
if err := c.defaultR.drawImage(c.screen, options); err != nil {
return err
}

View File

@ -36,6 +36,7 @@ type Matrix interface {
var initialized = false
const size = 10000
// TODO: Use unsafe.SizeOf?
const uint16Size = 2
const short32Size = 4
@ -48,8 +49,8 @@ func DrawTexture(native gl.Texture, projectionMatrix [4][4]float64, quads []Text
vertexBuffer := gl.GenBuffer()
vertexBuffer.Bind(gl.ARRAY_BUFFER)
vertices := make([]float32, stride*size)
gl.BufferData(gl.ARRAY_BUFFER, short32Size*len(vertices), vertices, gl.DYNAMIC_DRAW)
s := short32Size * stride * size
gl.BufferData(gl.ARRAY_BUFFER, s, nil, gl.DYNAMIC_DRAW)
indexBuffer := gl.GenBuffer()
indexBuffer.Bind(gl.ELEMENT_ARRAY_BUFFER)

17
ui.go
View File

@ -78,6 +78,23 @@ func startUI(width, height, scale int, title string) error {
window.SetPosition(x, y)
window.Show()
ch := make(chan struct{})
window.SetFramebufferSizeCallback(func(w *glfw.Window, width, height int) {
close(ch)
})
for {
done := false
glfw.PollEvents()
select {
case <-ch:
done = true
default:
}
if done {
break
}
}
ui := currentUI
ui.scale = scale