Skip to content

Commit

Permalink
Add SetFontTexture to RendererInterface.
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenDang committed May 13, 2021
1 parent e66cef9 commit cbc769f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions RendererInterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type Renderer interface {
SetTextureMinFilter(min uint) error
// Sets the texture magnifying filter.
SetTextureMagFilter(mag uint) error
// Set font texture
SetFontTexture(image *RGBA32Image)
// Load image and return the TextureID
LoadImage(image *image.RGBA) (TextureID, error)
// Release image
Expand Down
10 changes: 8 additions & 2 deletions RendererOpenGL3.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package imgui

import (
"errors"
"fmt"
"image"
"math"
Expand Down Expand Up @@ -323,6 +324,10 @@ func (renderer *OpenGL3) createFontsTexture() {

image := fonts.TextureDataRGBA32()

renderer.SetFontTexture(image)
}

func (renderer *OpenGL3) SetFontTexture(image *RGBA32Image) {
// Upload texture to graphics system
var lastTexture int32
gl.GetIntegerv(gl.TEXTURE_BINDING_2D, &lastTexture)
Expand All @@ -334,7 +339,7 @@ func (renderer *OpenGL3) createFontsTexture() {
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(image.Width), int32(image.Height), 0, gl.RGBA, gl.UNSIGNED_BYTE, image.Pixels)

// Store our identifier
io.Fonts().SetTextureID(TextureID(renderer.fontTexture))
CurrentIO().Fonts().SetTextureID(TextureID(renderer.fontTexture))

// Restore state
gl.BindTexture(gl.TEXTURE_2D, uint32(lastTexture))
Expand Down Expand Up @@ -394,8 +399,9 @@ func (renderer *OpenGL3) SetTextureMinFilter(min uint) error {
case textureFilterLinearMipmapLinear:
renderer.textureMinFilter = gl.LINEAR_MIPMAP_LINEAR
default:
return fmt.Errorf("invalid minifying filter")
return errors.New("invalid minifying filter")
}

return nil
}

Expand Down

0 comments on commit cbc769f

Please sign in to comment.