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 8224249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:00:01+00:00 2026-06-07T15:00:01+00:00

I’ve just started learning about OpenGL/Glut and I’m facing some issues. I want to

  • 0

I’ve just started learning about OpenGL/Glut and I’m facing some issues. I want to print a string key: a whenever I click the key a, but it seems like I don’t know what I’m doing.

I’m calling glutKeyboardFunc() from the main() function, and I’m passing it keyinput(), which tests whether key is ESC or a. Another thing is, when I try to print something from inside scene1() it works just great! hmm wonder why?

void printstr(void* font, char* str, GLfloat x, GLfloat y, GLfloat z)
{
    char* c = str;

    // set the raster position
    glRasterPos3f(x, y, z);

    for(; *c != '\0'; c++)
            glutBitmapCharacter(font, *c);
}

void keyinput(unsigned char key, int x, int y)
{
    switch(key)
    {
    case 27:
        killsound();
        exit(0);
        break;

    case 'a':
        glLoadIdentity();
        glColor3f(0.0f, 1.0f, 0.0f);    // Green
        printstr(GLUT_BITMAP_8_BY_13, "Key: a", 0.0f, 0.9f, 0.0f);
        break;
    }
}

int main(int argc, char** argv)
{
    // initialization and stuff
    glutInit(&argc, argv);
    .
    .
    .
    glutDisplayFunc(scene1);
    glutIdleFunc(scene1);
    .
    .
    .
    glutKeyboardFunc(keyinput);
    .
    .
    .

    glutMainLoop();
}
  • 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-07T15:00:06+00:00Added an answer on June 7, 2026 at 3:00 pm

    It’s probably because GLUT is calling keyinput() outside of your rendering code.

    I’m assuming your drawing function (glutDisplayFunc or glutIdleFunc) starts by calling glClear() and ends by calling glutSwapBuffers()? If so then any draw calls that take place inside of keyinput() would be done before glClear() is called, so the drawing won’t be seen.

    On top of that, keyinput isn’t called continuously. It gets called when your key is pressed. So your text will only display for one instant, not all the time.

    I suggest you make a global variable,

    int aIsPressed=0;
    

    In keyinput, set aIsPressed to the number of frames you want your message to be displayed (if you’re limiting your framerate, try 60, if not, try 1000)

    Then, in your drawing function, do this along with your code for drawing everything else:

    if(aIsPressed>0)
    { 
        glLoadIdentity();
        glColor3f(0.0f, 1.0f, 0.0f);    // Green
        printstr(GLUT_BITMAP_8_BY_13, "Key: a", 0.0f, 0.9f, 0.0f);
        aIsPressed--; //this way aIsPressed will count down to zero, and the message will disappear again
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported

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.