Skip to content
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

Text Rendering Support via SDL2_ttf #307

Closed
indiv0 opened this issue Jun 11, 2014 · 14 comments
Closed

Text Rendering Support via SDL2_ttf #307

indiv0 opened this issue Jun 11, 2014 · 14 comments
Assignees
Labels
Milestone

Comments

@indiv0
Copy link
Member

indiv0 commented Jun 11, 2014

Are there any plans to support TrueType font rendering in Piston via sdl2_ttf?

Current text implementations involve either drawing textures or using polygons, both of which seem inefficient and are definitely overcomplicated.

@bvssvni
Copy link
Member

bvssvni commented Jun 11, 2014

I want this.

@bvssvni bvssvni added this to the v0.2 milestone Jun 11, 2014
@indiv0
Copy link
Member Author

indiv0 commented Jun 11, 2014

I'd love to try implementing this as a collaborator, but I don't really know where to start in regards to extending Piston.

I think that I should add rust-sdl2_ttf as a submodule then begin writing the wrapper class in Piston, yes? Or would including it in the project be enough?

Let me know if you'd like me to try and what approach I should start with.

@bvssvni
Copy link
Member

bvssvni commented Jun 11, 2014

We use symlinks. You can set them up with ln -s <from> <to> to the target/cpu-vendor-os/lib folder.

I added you as collaborator.

Fork the rust-sdl2_ttf repository and build it locally. When you have written the wrapper class we will add it as a submodule in Piston-Workspace and modify the scripts to set up the symlinks.

@indiv0
Copy link
Member Author

indiv0 commented Jun 12, 2014

I've begin work on the wrapper, and you can see my current progress here.

Let me know if I'm on the right track.

Currently I'm stuck because I'm trying to implement the generic backend and write the SDL2 implementation from that (like Coeuvre did for the AudioBackEnd), but unlike for Audio, TextBackEnd needs to be passed a sdl2::video::Window during construction.

This is because sdl2_ttf::Font has a method render_str_solid(text, color), which I'm trying to use to render a text string into a sdl2::surface::Surface with the text in the given Font. Because Piston cannot yet draw Surfaces, I'm trying to convert it to an sdl2::texture::Texture and then into a Piston Texture.

Therefore, TextBackEnd uses sdl2::render::Renderer.create_texture_from_surface(&surface) to create the sdl2::texture::Texture. The Renderer object itself is constructed from a sdl2::video::Window with Renderer::from_window(window, sdl2::render::DriverAuto, sdl2::render::Accelerated), so TextBackEnd needs access to the Window, which I can't figure out how to do. How do you suggest I go about doing this?

@indiv0
Copy link
Member Author

indiv0 commented Jun 12, 2014

Also, am I converting from sdl2::texture::Texture to the Piston Texture correctly in sdl2_text_back_end.rs? I'm not quite sure on how exactly how to get the id from the sdl2::texture::Texture.

@bvssvni
Copy link
Member

bvssvni commented Jun 12, 2014

Just make it work and we'll figure out this later.

https://github.com/Indiv0/piston/blob/add-ttf/src/game_window_sdl2.rs#L18

You can take a GameWindowSDL2 and implement a method get_window that gives you what you need.

@bvssvni
Copy link
Member

bvssvni commented Jun 12, 2014

Perhaps you can render to a SDL2 surface without using the Piston graphics API?

This wouldn't be too different from how 'hgl-rs' renders OpenGL without using Rust-Graphics.

@bvssvni
Copy link
Member

bvssvni commented Jun 12, 2014

We could try adding text support to Rust-Graphics, but that requires a bit of planning.

http://www.piston.rs/docs/rust-sdl2/sdl2/render/type.TextureAccess.html

  • You are converting the 'access' field into an OpenGL id, which is bad.

@bvssvni
Copy link
Member

bvssvni commented Jun 12, 2014

Perhaps you could write an example https://github.com/Indiv0/piston/tree/master/examples
checking that you can combine the APIs (in their current state).

  1. Draw an image.
  2. Draw some text.
  3. Draw an image.

@bvssvni
Copy link
Member

bvssvni commented Jun 12, 2014

Or, just add an example drawing some text without using Rust-Graphics, so we can add the dependency to Piston-Workspace and take it step by step from there.

@bvssvni
Copy link
Member

bvssvni commented Jun 12, 2014

It might happen that we need to do some changes to Rust-Graphics or the OpenGL back-end to make this work correctly.

We probably need to split this issue into several ones and discuss the details closer.

@indiv0
Copy link
Member Author

indiv0 commented Jun 12, 2014

Ok so what's the next step for me then?

Because I could try rendering text without Rust-Graphics, but I don't have much OpenGL experience. Additionally, I don't think OpenGL supports TTF rendering.

Maybe use something like FTGL?

@coeuvre
Copy link
Member

coeuvre commented Jun 27, 2014

I've bound FreeType2 to Rust, and integrated with Piston.
Here is an example.

@bvssvni
Copy link
Member

bvssvni commented Jun 28, 2014

Since we can use freetype-rs I'm closing this.

@bvssvni bvssvni closed this as completed Jun 28, 2014
bvssvni added a commit to bvssvni/piston that referenced this issue Jun 16, 2015
Added `_args` methods to use with if let
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants