Comments (4)
This is something I wanted to do for a while, I just haven't gotten around to it yet.
But for the meantime, I can at least give you these tips:
- To display a glyph, you have to first draw it into a buffer in CPU memory with
sft_render()
and then upload that buffer into a GL Texture in GPU memory. You will also have to keep some additional information for each glyph around in CPU memory that tells you how big to render it and where to put the following glyphs etc. Simply storing the glyph'sSFT_GMetrics
should suffice, since all of that data is in there. - To get things off the ground, you can initially put each glyph in a separate texture. Once it's working, you can optimize it by
putting them all next to each other into a singleGL_TEXTURE_2D
(this is called a texture atlas).
Alternatively, you could use a singleGL_TEXTURE_2D_ARRAY
, which is often easier to work with for these sorts of things. - To upload libschrift-generated images to GL Textures, you can use
glTexImage2D()
orglTexSubImage2D()
withformat=GL_RED
andtype=GL_UNSIGNED_BYTE
. - OpenGL wants all its textures to have side lengths that are powers of two. The easiest way to achieve this with libschrift is
to round up the glyph's width and height to powers of two before allocating theSFT_Image
that you pass intosft_render()
. - Since OpenGL expects its textures to have their first row at the bottom and their last row at the top, you should not set
SFT_DOWNWARD_Y
. - To display text, you will of course need some kind of vertex and fragment shader (I'm assuming you're not using the old GL1.x fixed function pipeline since it's incredibly outdated). Since the texture is monochrome, it will have only a single color channel, which happens to be red. This means that your fragment shader will have to do something like
gl_FragColor = texture(glyph_texture, my_texcoords).r * glyph_color;
.
from libschrift.
@tomolt Why not do a GLUT/FreeGLUT example so a demo can be crossplatform and not just X11?
from libschrift.
Related Issues (17)
- more examples HOT 3
- Darwin compilation HOT 8
- support anti-aliasing? HOT 7
- Add travis CI or any other CI HOT 1
- How Can I Compile For Windows? [Question] HOT 2
- Does libschrift support colored emojis? HOT 1
- linkers needs the libraries *after* the files HOT 2
- Stack overflow in render_outline due to 256KB stack allocation HOT 3
- demos depend on graphics environment HOT 1
- draw_line function algorithm HOT 2
- Review usage of intenal csearch() function
- Whitespaces are not being rendered HOT 2
- Insufficiently wide char code on some platforms HOT 2
- background is not completely black HOT 5
- C++ support HOT 2
- Support for RTL languages HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libschrift.