I suggest you to setup the 2D part, that it matches the screen resolution, so that the coordinates will be the pixels.
And I don't see the problem with the thing, everybody suggest.
Please tell, why do you think it is a bad solution, or give us more details what you want.
Bitmap font text positioning
Quote:Original post by Ivan Mandic
@SuperVGA
I'm working on a Game engine. And my goal is to make things work in any cases,doing things that way isn't so smart.
Which of the mentioned ways are you referring to? It's common practice to try different sorts of input while the behavior of a specific function is unclear.
It won't hurt, and in the long run, you can make things work in any case either way.
I did setup glOrtho on the right way, so if I translate 2D object on the position (0,0) he will be renderd in the upper left corner of the screen. That isn't the problem.
The problem is that when I set a position Y (with glTranslatef) text sets just above that position,and not underneath.
I could make offset but the problem is that I do not know how to calculate the hight of letters in pixels.
The problem is that when I set a position Y (with glTranslatef) text sets just above that position,and not underneath.
I could make offset but the problem is that I do not know how to calculate the hight of letters in pixels.
If you locate the text above the position in the upper-left corner, it wouldn't be visible.
Sorry for sounding obvious. I might not have understood your question.
glTranslatef won't change where the text is drawn relatively to your text-function it will just translate whatever the function draws.
So if you go with (0, -24.0f, 0), it will be placed where you request.
I believe the text is 24 units high.
Sorry for sounding obvious. I might not have understood your question.
glTranslatef won't change where the text is drawn relatively to your text-function it will just translate whatever the function draws.
So if you go with (0, -24.0f, 0), it will be placed where you request.
I believe the text is 24 units high.
Use a constant value. It's a very bad practice, to make it depend on the text, because if the text changes, it will be rendered in an other y position, so the whole text will "shake". Or you can measure the same letter every time.
with:
SIZE size;
GetTextExtentPoint32(hDC,string_to_measure,number_of_letters_to_measure,(LPSIZE)&size); //will be in pixels
//size.cx, and size.cy
But you have to make the font current with
SelectObject(win_state.hDC, Your_Font_Created_with_CreateFont);
I hope that helps.
And maybe I misunderstood something, but this text uses glRasterPos, so translation don't have effect (or does it?, I'm not sure)
with:
SIZE size;
GetTextExtentPoint32(hDC,string_to_measure,number_of_letters_to_measure,(LPSIZE)&size); //will be in pixels
//size.cx, and size.cy
But you have to make the font current with
SelectObject(win_state.hDC, Your_Font_Created_with_CreateFont);
I hope that helps.
And maybe I misunderstood something, but this text uses glRasterPos, so translation don't have effect (or does it?, I'm not sure)
Quote:Original post by SuperVGA
If you locate the text above the position in the upper-left corner, it wouldn't be visible.
Exactly. So one way to make it work is to calculete offset(font high in pixels).
A problem is in the fact that I do not know how to calculate right font high in pixels.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement