Comments (3)
Hi, yes that is how it works. Currently there isn't any caching mechanism. It might be worth considering since it can be a common use case to draw the same strings every frame, but for now I have not planned it.
One thing you can try is to use separate canvases for text caching. Here is an example:
package main
import (
"github.com/tfriedel6/canvas"
"github.com/tfriedel6/canvas/backend/goglbackend"
"github.com/tfriedel6/canvas/sdlcanvas"
)
func main() {
wnd, cv, err := sdlcanvas.CreateWindow(1280, 720, "Canvas Test")
if err != nil {
panic(err)
}
defer wnd.Destroy()
backend, err := goglbackend.NewOffscreen(110, 60, true, nil)
if err != nil {
panic(err)
}
cv2 := canvas.New(backend)
cv2.SetFillStyle("#FFF")
cv2.SetFont("_testapp/Roboto-Light.ttf", 40)
cv2.FillText("hello", 10, 50)
wnd.MainLoop(func() {
cv.ClearRect(0, 0, 1280, 720)
cv.DrawImage(cv2, 50, 50)
cv.DrawImage(cv2, 50, 100)
})
}
The offscreen canvas should be used directly in the DrawImage call, so it should be quite fast. However if you need to render different strings every frame it will not work.
from canvas.
Thanks, that's very helpful! Most of my text is static but not all of it, and zoom levels change pretty frequently -- I think I'm going to see if I can look into drawing text using a font atlas.
If I start interspersing calls to opengl (e.g., changing current texture, vertex lists, and shaders), what do I need to do to play nicely with and not step on any state that your library depends on?
from canvas.
The shaders, textures, and buffers should be set as they are needed, so that shouldn't be a problem, I think. The stencil buffer settings are also set as needed, but stencil testing needs to be enabled for it to work. Similarly, the blend modes need to be kept, the depth buffer and depth testing should be disabled, and back face culling as well. Otherwise I can't think of anything right now. I think it should work, but I keep getting surprised by some aspects of OpenGL, so I might be missing something.
from canvas.
Related Issues (20)
- Hello, world demo inconsistent HOT 2
- [suggestion] gomobile display RegisterFilter HOT 1
- Is there any plan to support Ellipse for Path2D? HOT 1
- Flickering when using glfwcanvas HOT 3
- Memory Leak in DrawImage() HOT 1
- How to convert canvas to png? HOT 2
- MacOs canvas ratio problem HOT 2
- Blank red screen macOS HOT 1
- Pixelated text HOT 4
- Improper canvas size when using scaled resolutions on macOS HOT 1
- What's the proper way to use RGBA for something like SetFillStyle? HOT 2
- how I should compile on windows? HOT 2
- Failed to compile vertex shader HOT 7
- How to save canvas as png with transparent background HOT 1
- Call CreateWindow function failed on WSL2 HOT 3
- Is there a plan for when the missing features will be supported?
- support font.Face drawing // font fallbacks
- Combined keyboard touch don't trigger wnd.Event
- More Examples?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from canvas.