PDA

View Full Version : RenderText



Atomic_Sheep
14th September 2017, 13:23
Hi,

I'm trying to render text in my glwidget:


QString text;
text = "TEST test";

float x, y, z;
x = 0;
y = 0;
z = 0;

float red, green, blue;
red = 1;
green = 0;
blue = 1;

QFont font;
font.setFamily("algerian");
font.setPointSize(25);

glPushMatrix();
glColor3f(red, green, blue);
renderText(x, y, z, text, font);
glPopMatrix();

All my experimenting is resulting in clipping of the text:

1.) If I increase setPointSize beyond a certain point, clipping starts to happen.

2.) If I change x y z coordinates, clipping happens (this one appears to change the size of the viewport for the text box)

3.) If I setPointSize to around 15, I get what I'm going to call natural clipping i.e. half of "TEST test" is clipped i.e. you can only see "TEST".

So it looks like there's like two viewing ports, one for whatever I want to display in paintGL() and one that gets created and pasted on top of the background viewport that contains the text (I'm going to call this 'display box').

Two questions:

1.) How do manipulate the 'display box' that contains the text so that I can resize it to any size I want and have it not get clipped?

2.) How do I move the text around in my window because X Y Z seems to change the dimensions of the 'display box' not actually move the text around in my gl viewing box?

Atomic_Sheep
15th September 2017, 03:58
Figured it out, nothing to do with Qt but my lack of knowledge of OpenGL, just needed to play around with OpenGL commands to get it all to work!

d_stranz
15th September 2017, 04:41
So you're going to keep it a secret?

Atomic_Sheep
15th September 2017, 07:22
No secret, just needed to add:


void glwidget::resizeGL(int iWidth, int iHeight)
{
glViewport(0, 0, iWidth, iHeight);
}