Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8634473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:44:01+00:00 2026-06-12T09:44:01+00:00

I am using this code to draw a text in openGL with GLUT: Code

  • 0

I am using this code to draw a text in openGL with GLUT:

Code (init part) which sets my origin (0,0) into top-left corner and maintains proper screen-resolution based coordination system :

    glViewport(0, 0, x, y);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, x, y, 0, -1, 1);
    glMatrixMode(GL_MODELVIEW);

Code (printing part) :

void drawtext(GLfloat x, GLfloat y, const char* string )
{
    glRasterPos2f(x,y);
    while ( *string != '\0' )
         glutBitmapCharacter(p_glutfont,static_cast<int>(*string++));
}

And everything would be perfect if not only the fact that when X and Y starts at negative coordinations (due to the fact that objects with text printed as a tag are partially outside of the view, then the whole text is not being drawn. lets imagine that I have a object with text tag on top of it and it enters the view from left top corner at x = -40, y = 40 :

         X axis      window
 axis Y  ----------------------------
        | y=40                       |
 x=-40__|_________                   |
    |Text to print|                  |
    |_____________|                  |
        |                            |
        |                            |
        |____________________________|

The text is not being printed until is drawn from exactly X => 0 coordination. Also this problem doesn’t exist when text has to be clipped on RIGHT side – then it is printed properly – this is where I I realized that it has to do with initial position of the text.

My question is – how can I EXTEND properly my viewport / screen mapping to :

1) preserve screen coordinations from top-left corner (0,0) to bottom-right (height,width) 2) with internally extended those values just during the printing the text – so the text would get clipped instead of disappearing ?

Although I did my research, I couldn’t for 2 days now come to any solution. I tried to play with glViewport and glOrtho but none of changes and approaches I tried (like for example setting glViewport to -x,-y,x*2,y*2) would do the trick – those always mess with my screen coordination system which is essential to keep at window-resolution based.

PS: I did further research and I came across this article http://www.opengl.org/archives/resources/faq/technical/clipping.htm.

10.070 How do I draw glBitmap() or glDrawPixels() primitives that have an initial glRasterPos() outside the window’s left or bottom edge?

When the raster position is set outside the window, it’s often outside
the view volume and subsequently marked as invalid. Rendering the
glBitmap and glDrawPixels primitives won’t occur with an invalid
raster position. Because glBitmap/glDrawPixels produce pixels up and
to the right of the raster position, it appears impossible to render
this type of primitive clipped by the left and/or bottom edges of the
window.

However, here’s an often-used trick: Set the raster position to a valid value inside the view volume. Then make the following call:

 glBitmap (0, 0, 0, 0, xMove, yMove, NULL); 

This tells OpenGL to render a no-op bitmap, but move the current
raster position by (xMove,yMove). Your application will supply
(xMove,yMove) values that place the raster position outside the view
volume. Follow this call with the glBitmap() or glDrawPixels() to do
the rendering you desire.

Sadly – I can’t put this advice in work – and once I use it – the text is completely missing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:44:02+00:00Added an answer on June 12, 2026 at 9:44 am

    this is where I I realized that it has to do with initial position of the text.

    Almost. glRasterPos is a raster drawing operation command and whatever position you put into it goes through the transformation pipeline. If the point falls outside the clip volume (not the viewport!) it gets discarded and all further raster drawing operations are disabled until a new glRasterPos specified that is not clipped.

    The easy and recommended solution would be not to use raster drawing operations at all, because they’re slow, poorly supported and have been removed from later OpenGL alltogether. glutBitmapCharacter is using raster drawing ops.

    Use texture mapped fonts or stroked characters instead. Google finds uncountable amounts of information on these.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code to set a DB(sqlite)text into my view.i just draw the
Hi I'm using this code below to let a user draw their signature on
I'm using the following code to draw an SVG text box, and then change
I'm using this code to create text in ArcMap. But I can't seem to
I'm using this code to generate an UIImage from the text How do I
I am using this code to creating images with text written in it with
I am using the following code to draw text onto a jpg image but
Using this code, i am able to send a notification to my own device.
Using this code to zip a folder and it works perfect on small files
Using this code var html='<div class=somediv></div>'; var target=document.getElementById('contentArea'); target.appendChild(html); I'm getting Uncaught Error: NOT_FOUND_ERR:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.