Sign in to follow this  
endlessvoid

Show text even when partly out of screen

Recommended Posts

I'm trying to create an "input box", where the user can type something like a name. When the name is short enough to display, all is fine. When the user types too much data, the text scrolls so that the last part is visible and the first part disappears. The text is just moved to the left, and I'm using the GL_SCISSORS test to show only the data that is drawn inside the inputbox. It acts like this (simplified): - start Ortho mode: glOrtho(0, 639, 479, 0, 0, 1) - Draw some box as border for this input box - Get the width of the text to draw in the input box If the width is smaller than the input box: --- use glRasterpos2i to set the position to the position of the input box (box.x, box.y); --- Print the text using (among other calls): glCallLists(strlen(box.text), GL_UNSIGNED_BYTE, box.text); If the width is higher than the input box: --- Set the glScissor mode to update everything in the inputbox: glScissor(box.x, box.y, box.width, box.height); --- Enable scissor test --- use glRasterpos2i to set the position to the position of the input box, but subtract the size of the text we don't want displayed (box.x + box.width - text_width, box.y); --- Print the text using (among other calls): glCallLists(strlen(box.text), GL_UNSIGNED_BYTE, box.text); --- Disable scissor test Now, everything works fine, except when the raster position is set to a negative value, that is, when the text is only partly out of the screen. What I want it to do, however, is to just print the text and show only the part in the scissor box. box.x can be 0, so I can't just display the letters that are visible, because even half a visible character can get a negative position, resulting in not displaying the text. I've tried NeHe tutorial 13, with bitmap fonts, where the same method is used to move some text around the screen. This text also reaches the edge of the screen, and disappears for a bit. So my questions: - How can I make the text be displayed, even if it is partly out of the screen? What is the best solution? Or do I have to use templates as font? - Is this video card/driver specific? I'm using an NVidia GForce 2, with the NVidia driver for Linux version 1.0.7667. Thanks

Share this post


Link to post
Share on other sites
The problem with glRasterPos is that when the raster position ends up outside the viewport, the raster position is marked as invalid, and all operations involving the raster position is ignored.

If you intend to set the raster position in window coordinates, then you should use glWindowPos instead (ARB_window_pos or OpenGL 1.4 and later), which directly sets the raster position in window coordinates and always keeps it valid even if it's outside the viewport. It also removes the need to properly setup the modelview and projection matrices, the last which I believe you got wrong anyway. If your window is 640x480 pixels, the call to glOrtho should have been glOrtho(0, 640, 480,0, 0, 1) or you won't get a correct 1:1 mapping to widnow coordinates.

Share this post


Link to post
Share on other sites
Thanks :)
glWindowPos worked.
And about the matrices: They are fine, but I didn't copy all the code, only that what seemed important to me. Because the code is spread over a lot of functions, I couldn't just copy it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this