-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
switching font #100
Comments
Currently, deleting a layer isn't a great idea (not all of the back-ends handle that very well at all). I hope to fix that soon. I've typically gone with a layer per font, but I can see why run-time font switches would be attractive. I'll include an interface for doing that in the |
Ok, great ! I've got a similar issue with another doryen-rs example about dynamically updating a console. The idea is that the console adds columns/lines when the window is resized (instead of scaling the characters, there are more of them when the window is bigger). bracket-lib consoles size, as returned by That would require something like |
…cefully handle choosing a font with a different pixel size, yet.
Another issue I'm foreseeing with window resizing : the current |
Resizing is a whole other bundle of pain. It's actually a really complicated one (I've looked at it before and held off):
Last time I looked at it, I said "this is going to be painful" and backed it out. I could do another push on it, when fonts work. |
Also, allowing There's also the fun case: say you have a bunch of layers. Resize one, and they all have to resize. |
yeah, it's definitely an opt-in option. I'm supporting it only on native target in doryen-rs because you're not supposed to resize the canvas in web mode (and resizing the browser window doesn't affect the canvas size). I guess a native-only feature would be enough to provide backward compatibility for doryen-rs users. |
as for issues with multi-layers and preservation of the console content, I think it should be up to the user to deal with that. Some applications might want to change the layout depending on the window size anyway so I think it's not up to bracket-lib to decide what to do. But the basic building block for all of this is being able to resize the char_size of a specific console. |
…there, so try the squishy example to see a simple console resize and squish itself down. It's a start. Never going to be super performant, since it is doing a bunch of copy/reallocate. I still get 400 FPS on release (debug = don't ask).
Great! the resize example works with this branch. I've still have an issue with font switching (screen turns black when trying to change the font. Might be an issue on my side. Investigating) |
I'm not pre-registering the font in the terminal builder. Instead, I register it live like this : let cur_font = ctx.register_font(font).unwrap();
ctx.set_active_font(cur_font); Is that supported? All I get is a black screen |
The backend builds the font in GL at initialization time, so that will get you a blank screen. |
Ok I think the register_font function should be private then. Having to know the font at initialization time is a reasonable requirement. I'll change the doryen-rs API to reflect that. |
Forgot to tag the commit, but I've made register_font pub(crate). |
Run into a funny one. |
I'm also getting regressions (black screen) in some examples. Might be on my side. |
I can't get the default scaling behavior to work. I'm using |
I'm not seeing any black screens with the current build (just ran through examples). Definitely need to dampen key input once more (it's hard to press a key just once, messing up some examples). |
More info on regression : it seems background colors are not rendered anymore, only the font on black background. Still don't know if it's in my wrapper or in bracket |
Oh it works in bracket bench_scalable example so it's definitely on my side |
I haven't a clue why, but scaling and background rendering is broken on my side. I'll come back to it tomorrow. |
I just had a thought (untested): the font files are RGBA, with alpha backgrounds. I haven't tested to see what happens if you load one with a regular black background and no alpha content. |
The alpha fonts have been working so far but I guess the support of alpha transparency in the engine broke something |
I confirm bracketlib's textblock example doesn't show background color when using the terminal_8x8.png font from doryen-rs (the all white font in the comment above). |
ok the HiDPI issue is due to doryen-rs not having the scale factor value. See my comment above : #100 (comment) Still trying to figure out why all my examples are resized instead of scaled when I change the window size |
I think fonts should be pre-processed during loading so that the shader only handles one format. It would make it simpler and faster. This is how I'm doing it in doryen-rs : This works with the popular "pink fonts" format (see DF tileset for example), but also a font with any opaque background color. |
I'd previously looked at how you were doing the file scan. I deliberately didn't do that: if you're using a complicated tileset, you may well have a color in your (0,0) pixel. It's generally a bad idea to require that the user embed meta-data in their actual data files for that reason: they may need that pixel! (I've debugged people's projects with this very problem in the past) Ok, I'm going through the Based on what I'm finding so far:
If you change the fn render(&mut self, api: &mut dyn DoryenApi) {
let con = api.con();
let console_width = con.get_width();
let console_height = con.get_height();
con.rectangle(
0,
0,
console_width,
console_height,
Some((128, 128, 128, 255)),
Some((0, 0, 0, 255)),
Some('.' as u16),
);
con.area(
10,
10,
5,
5,
Some((255, 64, 64, 255)),
Some((128, 32, 32, 255)),
Some('&' as u16),
);
con.ascii(self.player_pos.0, self.player_pos.1, '@' as u16);
con.fore(self.player_pos.0, self.player_pos.1, (255, 255, 255, 255));
con.print_color(
(console_width / 2) as i32,
(console_height - 1) as i32,
"#[red]arrows#[white] : move - #[red]CTRL-S#[white] : save screenshot",
TextAlign::Center,
None,
);
con.print_color(
(console_width / 2) as i32,
(console_height - 3) as i32,
&format!(
"#[white]Mouse coordinates: #[red]{}, {}",
self.mouse_pos.0, self.mouse_pos.1
),
TextAlign::Center,
None,
);
con.print_color(
5,
5,
"#[blue]This blue text contains a #[red]red#[] word",
TextAlign::Left,
None,
);
con.back(
self.mouse_pos.0 as i32,
self.mouse_pos.1 as i32,
(255, 255, 255, 255),
);
} And the resize event in BEvent::Resized { new_size, dpi_scale_factor: _ } => {
self.new_size = (new_size.x as u32, new_size.y as u32)
} The basic example now works well and resizes on my machine. (I tried with 100% and 125% scale factors). |
Concerning pot_width and pot_height, some (old) opengl drivers only support power-of-two texture sizes. doryen-rs console data is stored in textures and accessed directly by the shader so I have to know the actual console size versus the logical size. But all of this should disappear with bracketlib. |
…ion in the initializer to specify an explicit background color to have converted to black/transparent.
With the last commit, you can specify |
Well I think everything is looking quite good right now. Also there's a different behavior in font switching between doryen and bracket. doryen was scaling the console to keep the same window/character size : while bracketlib doesn't change scale nor window size : I don't know what default behavior is the best or what should be controllable by the user. There are three ways to handle a change of font character size :
|
…. WASM honors font changes, correctly rebuilding the back-ends (it has issues with tiny fonts still; investigating). It's a lot more careful about scaling, so you can change font in fontswitch example and resize the window and it still scales.
… describe what the option does. #100
That flipping upside down is trippy. I'll see what I can find. The "change window size" option above isn't going to work until Changing scale to keep the original size is default I'll rename that option to: |
Ok I still have an issue with automatic console resizing. I reproduce the issue on the latest fonts branch version by running the benchmark_scalable example. This is what I get, a much bigger console than the requested 80x45 : |
What happens is that there is a Resized event in the window initialization so bracketlib consider the window was resized from 1.0 scale factor to 1.5 and it increases the console size accordingly. I don't know if this initial Resize event happens on every platform |
This is not the behavior I observe with the fontswitch example. When the font characters are bigger, there are less columns/lines visible in the console. |
… ignores the first 'resize' that makes Linux so happy.
The last couple of commits should help:
I have to admit, I'm now thoroughly confused by what you're wanting regarding scale.
|
…e the huge font to obtain unicode characters. Still needs work.
Looking at the doryen |
…want to resize the console to the natural size or retain the size and scale the font. #100
Alright, with that commit if you set the |
Ok I have my answer, the solution was |
The split between those needs to be better documented. It overrides the library's guess as to what the pixel size should be, originally a workaround for layers with multiple tile sets in play. I'll make a note to clean that up. |
Well this is looking pretty good. The only remaining features/issues are really minor I'm tracking them here on doryen side. |
There's a full sprite system planned for a future release, if it's any help! |
The |
I'm trying to port this doryen-rs example to bracket-lib. A few versions ago I was able to do it with this code :
but the consoles field is now private (which is a good thing). Is there a way to change the font index of a console or do I have to register a new console, but in that case how can I get rid of the previous console ?
The text was updated successfully, but these errors were encountered: