diff --git a/internal/graphics/command.go b/internal/graphics/command.go index 49087d1cb..c9876e57e 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -122,11 +122,13 @@ func (c *drawImageCommand) Exec(context *opengl.Context) error { if n == 0 { return nil } + _, h := c.dst.Size() + proj := glMatrix(c.dst.framebuffer.projectionMatrix(h)) p := programContext{ state: &theOpenGLState, program: theOpenGLState.programTexture, context: context, - projectionMatrix: glMatrix(c.dst.framebuffer.projectionMatrix()), + projectionMatrix: proj, texture: c.src.texture.native, geoM: c.geo, colorM: c.color, @@ -275,8 +277,6 @@ func (c *newScreenFramebufferImageCommand) Exec(context *opengl.Context) error { } f := &framebuffer{ native: context.ScreenFramebuffer(), - width: c.width, - height: c.height, flipY: true, } c.result.framebuffer = f diff --git a/internal/graphics/framebuffer.go b/internal/graphics/framebuffer.go index 2dc63c023..8750b2d35 100644 --- a/internal/graphics/framebuffer.go +++ b/internal/graphics/framebuffer.go @@ -34,8 +34,6 @@ func orthoProjectionMatrix(left, right, bottom, top int) *[4][4]float64 { type framebuffer struct { native opengl.Framebuffer - width int - height int flipY bool proMatrix *[4][4]float64 } @@ -47,8 +45,6 @@ func newFramebufferFromTexture(context *opengl.Context, texture *texture) (*fram } return &framebuffer{ native: native, - width: texture.width, - height: texture.height, }, nil } @@ -60,16 +56,14 @@ func (f *framebuffer) setAsViewport(context *opengl.Context) error { return context.SetViewport(f.native, width, height) } -func (f *framebuffer) projectionMatrix() *[4][4]float64 { +func (f *framebuffer) projectionMatrix(height int) *[4][4]float64 { if f.proMatrix != nil { return f.proMatrix } - width := viewportSize - height := viewportSize - m := orthoProjectionMatrix(0, width, 0, height) + m := orthoProjectionMatrix(0, viewportSize, 0, viewportSize) if f.flipY { m[1][1] *= -1 - m[1][3] += float64(f.height) / float64(height) * 2 + m[1][3] += float64(height) / float64(viewportSize) * 2 } f.proMatrix = m return f.proMatrix diff --git a/internal/graphics/image.go b/internal/graphics/image.go index b010c077c..5b9426c6f 100644 --- a/internal/graphics/image.go +++ b/internal/graphics/image.go @@ -112,7 +112,7 @@ func (i *Image) Pixels(context *opengl.Context) ([]uint8, error) { return nil, err } f := i.framebuffer - return context.FramebufferPixels(f.native, f.width, f.height) + return context.FramebufferPixels(f.native, i.width, i.height) } func (i *Image) ReplacePixels(p []uint8) error {