From 57348acc0257ee08583b524fa9321b477a4772b7 Mon Sep 17 00:00:00 2001 From: Thomas Friedel Date: Mon, 18 Feb 2019 11:29:12 +0100 Subject: [PATCH] added an optional alpha channel for offscreen canvas, and a DeleteOffscreen function --- canvas.go | 15 +++++++++++++-- canvas_test.go | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/canvas.go b/canvas.go index e26ea5b..8525dd4 100644 --- a/canvas.go +++ b/canvas.go @@ -152,13 +152,24 @@ func New(x, y, w, h int) *Canvas { // NewOffscreen creates a new canvas with the given size. It // does not render directly to the screen but renders to a -// texture instead -func NewOffscreen(w, h int) *Canvas { +// texture instead. If alpha is set to true, the offscreen +// canvas will have an alpha channel +func NewOffscreen(w, h int, alpha bool) *Canvas { cv := New(0, 0, w, h) cv.offscreen = true + cv.offscrBuf.alpha = alpha return cv } +func DeleteOffscreen(cv *Canvas) { + if !cv.offscreen { + return + } + gli.DeleteTextures(1, &cv.offscrBuf.tex) + gli.DeleteFramebuffers(1, &cv.offscrBuf.frameBuf) + gli.DeleteRenderbuffers(1, &cv.offscrBuf.renderStencilBuf) +} + // SetBounds updates the bounds of the canvas. This would // usually be called for example when the window is resized func (cv *Canvas) SetBounds(x, y, w, h int) { diff --git a/canvas_test.go b/canvas_test.go index 5416972..cf8bc19 100644 --- a/canvas_test.go +++ b/canvas_test.go @@ -22,7 +22,7 @@ func run(t *testing.T, fn func(cv *canvas.Canvas)) { } defer wnd.Destroy() - cv := canvas.NewOffscreen(100, 100) + cv := canvas.NewOffscreen(100, 100, false) gl.Disable(gl.MULTISAMPLE)