|
[A5+OpenGL] How to prevent al_draw_text from resetting the viewport? |
wqking
Member #16,641
February 2017
|
I only need OpenGL. So, how can I render text without reset the viewport? Thanks |
Elias
Member #358
May 2000
|
Which version are you using? -- |
wqking
Member #16,641
February 2017
|
The latest 5.2.2 from the download page. |
Elias
Member #358
May 2000
|
I see: https://github.com/liballeg/allegro5/blob/master/src/opengl/ogl_draw.c#L531 I think that only gets called when you change the target bitmap. al_draw_text has to change the target bitmap when it draws into the texture with the glyph pictures. When it switches back to the original target, it will reset the viewport to 0/0/w/h and not what it was before. You can completely avoid the target bitmap switch by pre-rendering your glyphs. You can try something like this (with a display created and active on the current thread): font = al_load_font(...); int ranges[100 * 2]; int n = al_get_font_ranges(font, 100, ranges); for (int i = 0; i < n; i++) { for (int j = ranges[i * 2 + 0]; j <= ranges[i * 2 + 1]; j++) { int s = al_utf8_encode(text, j); text[s] = 0; al_draw_text(text); } } Alternatively, a patch to preserve the viewport probably could be applied to Allegro. We do have some functions to support mixing Allegro with OpenGL, and this sounds like something that would make sense. -- |
SiegeLord
Member #7,827
October 2006
|
Can't you just reset the viewport to what you expect after the text is drawn? Or is the issue that you expect the text drawing to actually use your viewport setting? "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
wqking
Member #16,641
February 2017
|
@Elias: @SiegeLord: |
|