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

  • Home
  • SEARCH
  • 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 7747915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:38:56+00:00 2026-06-01T10:38:56+00:00

EDITED WITH SOLUTION So I am making a particle system in opengl. I am

  • 0

EDITED WITH SOLUTION

So I am making a particle system in opengl. I am working in Linux. I want to make it more interactive, so, for example, when the user presses the spacebar, a new firework shoots out.

I am using GLUT to capture keyboard input, and when the user hits the spacebar, it shoots a firework out, then goes in a loop that loops for a while, and if I press spacebar again, it has to wait til that loop (mentioned above) is done executing before it registers the keypress.

So my question is this:

Is there a way for me to, at the start of the loop, to check the buffer that glut stores the keypress in? I feel like there has to be some sort of a buffer that it stores keypresses in, because yeah, once that loop above is finished executing, it registers the keypress.

SOLUTION:

I do not actually do any loops now anywhere (except to loop through arrays to update locations of my fireworks, etc), I do something like

in main, add this:

int main(int argc, char** argv){

    //Usual glut initializations
    glutTimerFunc(30, update, -1);//says in 30miliseconds call update
    glutDisplayFunc(display);   
    glutMainLoop();

    return 0;   
}

Then in your update function (in the parameters for glutTimerFunc, so something like this:

void update(int k){

    //UPDATE POSITION OF FIREWORKS
    glutTimerFunc(30, update, -1);//it is important to add this
    glutPostRedisplay();//calls display() on the next iteration of glut's main loop
}

Then finally in your display function, do what ever you need to do to draw one frame (in my case, loop through each firework and draw it!)

Hope this helps 🙂

  • 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-01T10:38:58+00:00Added an answer on June 1, 2026 at 10:38 am

    You’re going about this the wrong way.

    Your keypress handler should not be looping over anything. Your keypress handler should simply set some variable and return.

    Your main display function (which should be driven by a timer function that calls glutPostRedisplay) should check this variable. If it is set, then it should be firing your firework and looping for some duration.

    During that time, your keypress handler should simply ignore any further pressing of the spacebar. Once the display function finishes with the firework, then it can respond to further key presses.

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

Sidebar

Related Questions

*edited 6/17/10 I'm trying to understand how to improve my code (make it more
Edited: SOLUTION FOUND. This is strange and not the best solution, but I just
SOLVED. Code has been edited to reflect solution. Given the following GridView : <asp:GridView
Edited to Add * I haven't found a solution for this one yet, can
I edited this question after i found a solution... i need to understand why
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
When I want to redirect a user to a specific page behind a login
We have a complex fabric BPM solution. We now want to expose the fabric
I'm trying to come up with a solution for working on my PhoneGap projects.
Edited to add more details: (originally asked nearly two months ago...still haven't found a

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.