|
Hello! I have this pipeline like var hud *ggcanvas.Canvas
// ...
gpuApp.OnDraw(func(dc *gogpu.Context) {
// ...
if hud == nil {
var err error
if hud, err = ggcanvas.New(gpuApp.GPUContextProvider(), hudWidth, hudHeight); err != nil {
log.Fatalf("create HUD canvas: %v", err)
}
}
// ... draw some stuff with wgpu
if err = hud.Draw(func(ctx *gg.Context) {
ctx.Clear()
ctx.SetRGB(1, 1, 1)
ctx.SetFont(face)
ctx.DrawString(fmt.Sprintf("FPS: %d", fps), 24, 36)
ctx.DrawString("GPU: "+gpuApp.GPUContextProvider().AdapterInfo().Name, 24, 60)
ctx.DrawString(fmt.Sprintf("Cam: %.1f %.1f %.1f", cam.Position.X, cam.Position.Y, cam.Position.Z), 24, 84)
}); err != nil {
log.Errorf("draw HUD: %v", err)
}
hud.RenderTo(dc.AsTextureDrawer())
//...
})My issue is that no matter what I've tried, the |
Replies: 2 comments 1 reply
|
Hi! Good question.
A couple of things to check: 1. Don't use // ❌ This makes the entire HUD opaque black:
ctx.ClearWithColor(gg.Black)
// ✅ This is transparent (Clear() does this by default):
ctx.Clear()2. Check that // ✅ White text on transparent background:
ctx.SetRGBA(1, 1, 1, 1) // or ctx.SetRGB(1, 1, 1)3. Surface format: If your swapchain uses a format without alpha (e.g., 4. Render order: Make sure If |
|
Great solution! Your pattern ( We also found and fixed the root cause of the black background with So both approaches now work:
|
Hi! My solution ended up being not using the canvas, but just a context as a composite.