diff --git a/graphics/opengl/context.go b/graphics/opengl/context.go index 7df54f803..1edb872e1 100644 --- a/graphics/opengl/context.go +++ b/graphics/opengl/context.go @@ -60,6 +60,11 @@ func (context *Context) Init() { if err != nil { panic("initializing the offscreen failed: " + err.Error()) } + screen := context.renderTargets[context.screenId] + C.glBindTexture(C.GL_TEXTURE_2D, screen.Texture().Native().(C.GLuint)) + C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST) + C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_NEAREST) + C.glBindTexture(C.GL_TEXTURE_2D, 0) } func (context *Context) ToTexture(renderTargetId graphics.RenderTargetId) graphics.TextureId { diff --git a/graphics/opengl/device.go b/graphics/opengl/device.go index d79935e1b..5f2ce35e2 100644 --- a/graphics/opengl/device.go +++ b/graphics/opengl/device.go @@ -32,17 +32,12 @@ func (device *Device) Init() { func (device *Device) Update(draw func(graphics.Context)) { context := device.context C.glEnable(C.GL_TEXTURE_2D) - C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_NEAREST) - C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST) context.ResetOffscreen() context.Clear() draw(context) context.flush() - - C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_LINEAR) - C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_LINEAR) context.setMainFramebufferOffscreen() context.Clear() diff --git a/graphics/opengl/shader/program.go b/graphics/opengl/shader/program.go index ff459636d..8edb00fad 100644 --- a/graphics/opengl/shader/program.go +++ b/graphics/opengl/shader/program.go @@ -175,7 +175,7 @@ func DrawTexture(native Texture, projectionMatrix [16]float32, quads []texture.Q shaderProgram := use(projectionMatrix, geometryMatrix, colorMatrix) // This state affects the other functions, so can't disable here... C.glBindTexture(C.GL_TEXTURE_2D, C.GLuint(native)) - //defer C.glBindTexture(C.GL_TEXTURE_2D, 0) + defer C.glBindTexture(C.GL_TEXTURE_2D, 0) vertexAttrLocation := getAttributeLocation(shaderProgram, "vertex") textureAttrLocation := getAttributeLocation(shaderProgram, "texture") diff --git a/graphics/opengl/shader/shader.go b/graphics/opengl/shader/shader.go index 8751ba49b..585c7f137 100644 --- a/graphics/opengl/shader/shader.go +++ b/graphics/opengl/shader/shader.go @@ -69,7 +69,7 @@ var ( func (s *shader) compile() { csource := (*C.GLchar)(C.CString(s.source)) // TODO: defer? - //defer C.free(unsafe.Pointer(csource)) + // defer C.free(unsafe.Pointer(csource)) C.glShaderSource(s.id, 1, &csource, nil) C.glCompileShader(s.id) diff --git a/graphics/opengl/texture.go b/graphics/opengl/texture.go index 4c8d909b4..03d26c55d 100644 --- a/graphics/opengl/texture.go +++ b/graphics/opengl/texture.go @@ -20,6 +20,10 @@ func createNativeTexture(textureWidth, textureHeight int, pixels []uint8) C.GLui } C.glPixelStorei(C.GL_UNPACK_ALIGNMENT, 4) C.glBindTexture(C.GL_TEXTURE_2D, C.GLuint(nativeTexture)) + defer C.glBindTexture(C.GL_TEXTURE_2D, 0) + + C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_LINEAR) + C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_LINEAR) ptr := unsafe.Pointer(nil) if pixels != nil { @@ -29,10 +33,6 @@ func createNativeTexture(textureWidth, textureHeight int, pixels []uint8) C.GLui C.GLsizei(textureWidth), C.GLsizei(textureHeight), 0, C.GL_RGBA, C.GL_UNSIGNED_BYTE, ptr) - C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_LINEAR) - C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_LINEAR) - C.glBindTexture(C.GL_TEXTURE_2D, 0) - return nativeTexture }