Lachee / raylib-goplus

A newer version of the Go bindings for Raylib
zlib License
76 stars 6 forks source link

[BUG] LoadFontEx doesn't take pointer to ints #16

Open SolarLune opened 4 years ago

SolarLune commented 4 years ago

Hello!

Describe the bug LoadFontEx() should be able to take a pointer to an array of ints for the fontChars argument; instead it just accepts a single integer. This prevents you from specifying a range of characters to load when loading the font, I believe. See the cheatsheet.

Lachee commented 4 years ago

Yup, validated this bug. The translations does its best but cant always determine the context of pointers. I will spend some more time and investigate futher.

Lachee commented 4 years ago

Can you please test that this is the correct solution?

SolarLune commented 4 years ago

Hello!

No, this isn't working; I'm getting:


goroutine 1 [running, locked to thread]:
github.com/lachee/raylib-goplus/raylib.LoadFontEx(0xc000022140, 0x41, 0xa, 0x7e, 0x0, 0x0, 0x0, 0x0)
        /home/solarlune/Documents/Projects/Go/raylib-goplus/raylib/text_gen.go:47 +0x3d4
main.main()
        /home/solarlune/Documents/Projects/Go/MasterPlan/main.go:35 +0x265
exit status 2

I'm also getting the same error regardless of what number I pass in, just with a different index out of range number.

Lachee commented 4 years ago

hmm, alright I will revisit what I have done.

SolarLune commented 4 years ago

I believe what it's supposed to take is an array of integers (probably int32's), indicating which specific Unicode code points (character symbols, like a, Q, or ) to load out of the font. This is probably done because some languages, like Japanese, have too many characters to load all of them at the same time on the same texture (or at least, one can't load them all along with all other characters for all other languages in the spaces reserved between those and Latin characters). See this rather helpful Unicode block article on Wikipedia. In the article, they're represented using hex ranges.

So to work around this, one should be able to specify which symbols to load into the font structure, using an array. See Raysan's comment here. I don't believe raylib-go currently does this correctly either, just for the record.

Ambez05 commented 4 years ago

Hi, I compared this with raylib-go and it passes a pointer to int for fontChars. This changes the behaviour of this function in raylib

CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, int type)

If fontChars is null it will auto generate the array.

I have tested using similar logic that raylib go uses and if this value is null a valid font will be returned. This however only returns a point to font and not the number of font characters returned.

DankFC commented 4 years ago

You can copy the raylib-go binding and add a pointer to the returned Font type.

https://github.com/gen2brain/raylib-go/blob/13ca6365b5245b4c27266429bebe671d129f07d0/raylib/text.go#L36

Then load the font like so: font := *LoadFontEx(filename, fontSize, nil, charCount)

This solved the compile issues for me.

Lachee commented 4 years ago

You can copy the raylib-go binding and add a pointer to the returned Font type.

https://github.com/gen2brain/raylib-go/blob/13ca6365b5245b4c27266429bebe671d129f07d0/raylib/text.go#L36

Then load the font like so: font := *LoadFontEx(filename, fontSize, nil, charCount)

This solved the compile issues for me.

Yes, however I am trying to "Goificate" this function to something that makes sense. Behind the scenes raylib treats it as an array of ints. Because of this, this library should allow you to pass a slice of ints to it.