faiface / pixel

A hand-crafted 2D game library in Go
MIT License
4.46k stars 245 forks source link

Adding new triangles type: TrianglesClipped #284

Closed dusk125 closed 3 years ago

dusk125 commented 3 years ago

This new triangle type replaces the first pass at clipping rectangles in favor for a shader-based approach that works better with pixelui's (imgui's) rendering.

zergon321 commented 3 years ago

Hi. Thank you for the PR, but I found an issue with drawing text on the screen.

On the first screenshot you can see my game using the current release of Pixel (v0.10.0). Screenshot from 2021-06-22 20-44-18

On the second screenshot there is my game using the version of Pixel from your PR (with TrianglesClipped). Screenshot from 2021-06-22 20-41-39

As you can see, my debug console got off screen for some reason. I use pixel/text for writing to it and drawing its contents each frame. Here's the code:

console.go ```go package debug import ( "fmt" "image/color" "danmaku/resources" "danmaku/system" "github.com/faiface/pixel" "github.com/faiface/pixel/text" "github.com/golang/freetype/truetype" colors "golang.org/x/image/colornames" ) var ( txt *text.Text ) // ConsoleInitialize initializes the debug console. func ConsoleInitialize() error { // Load a new font. resourceLoader, err := resources.NewResourceLoader("common.res") if err != nil { return err } defer resourceLoader.Close() fnt, err := resourceLoader.LoadFont("debug") if err != nil { return err } face := truetype.NewFace(fnt, &truetype.Options{ Size: 20, GlyphCacheEntries: 1, }) // Initialize the debug console. atlas := text.NewAtlas(face, text.ASCII) txt = text.New(pixel.V(20, 1040), atlas) txt.Color = colors.White return nil } // ConsoleClear clears the debug console. func ConsoleClear() { if txt == nil { return } txt.Clear() } // ConsolePrintln prints a new line to the debug console. func ConsolePrintln(args ...interface{}) { if txt == nil { return } fmt.Fprintln(txt, args...) } // ConsolePrintf performs a formatted print to the debug console. func ConsolePrintf(message string, args ...interface{}) { if txt == nil { return } fmt.Fprintf(txt, message, args...) } // ConsolePrint prints the arguments in the console. func ConsolePrint(args ...interface{}) { if txt == nil { return } fmt.Fprint(txt, args...) } // ConsoleSetColor sets the text color // in the debug console. func ConsoleSetColor(cl color.RGBA) { if txt == nil { return } txt.Color = cl } // ConsoleColor returns the text color in the console. func ConsoleColor() color.RGBA { if txt == nil { return colors.White } return txt.Color.(color.RGBA) } // ConsoleOutput outputs the console contents // to the game window. func ConsoleOutput() { if txt == nil { return } txt.Draw(system.Window(), pixel.IM) } ```
cebarks commented 3 years ago

is the text on the right side of the play area not draw with pixel/text?

zergon321 commented 3 years ago

@cebarks Yeah, it's drawn with pixel/text too but moved not as much for some reason.

papr8ka commented 3 years ago

I've got the same kind of behaviours, that was introduced by the PR #252 related to anchors. That only happens with text rendering.

In my case, it broke my text centering system, while from my understanding, with the default anchor it should have changed nothing.

Without anchor

withoutAnchor

With anchor

withAnchor

dusk125 commented 3 years ago

@zergon321 out of curiosity, had you tested after the anchor changes and before these changes? I'm trying to figure out if this issue is in Triangles changes or anchors. Thanks

zergon321 commented 3 years ago

@dusk125 I did more research. Nevermind, your PR works fine. What's really faulty is the latest version of Pixel which I downloaded using git clone (don't know which commit introduces the issue though). The version 0.10.0 that can be obtained from Google mirrors via go get works fine too. I think your PR even fixes the issue with the moved text.

But what really concerns me is that I get slightly less FPS when the code from your PR is being used (depending on the situation, there is 10-100 FPS decrease in average). Is there a way to optimize it?

dusk125 commented 3 years ago

@zergon321 I re-reviewed the gl triangles changes, and nothing stands out to me as to why you'd be getting fewer frames. I'm going to take a look at previous merges to see if I can find anything that might point to a performance loss.