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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:00:52+00:00 2026-06-08T01:00:52+00:00

I have the following code int i = 0; void display(void) { glLoadIdentity(); glColor3f(1.0f,

  • 0

I have the following code

int i = 0;

void display(void)
{
    glLoadIdentity();
    glColor3f(1.0f, 0.0f, 0.0f);
    glPushMatrix();
    glTranslatef(20.0f, 20.0f, -40.f);
    glRotatef(180.f, 0.0, 0.0, 1.0);

    glBegin(GL_TRIANGLES);
    glVertex3f(pts[tri[i]], (pts[ptsLength/2 + tri[i]] - maximum) * -1, 0);
    glVertex3f(pts[tri[i+1]], (pts[ptsLength/2 + tri[i+1]] - maximum) * -1, 0);
    glVertex3f(pts[tri[i+2]], (pts[ptsLength/2 + tri[i+2]] - maximum) * -1, 0);
    glEnd();

    i+=3;
    glPopMatrix();
    glutSwapBuffers();
}

How can I make this method pause and wait for a keystroke before rendering the next triangle?

  • 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-08T01:00:53+00:00Added an answer on June 8, 2026 at 1:00 am

    Is this the glutIdleFunc, or the one called when you glutPostRedisplay?

    In either case, you need to first setup a glutKeyboardFunc, in which you detect whether a certain key is pressed or not.

    In the case you update the screen only on certain events:

    ... inside the keyboard function
    if (key_pressed == THE_KEY_YOU_WANT)
        glutPostRedisplay();
    

    In the case you are using display as the idle function, you can do:

    global:
    bool go_next = false;
    
    ... inside the keyboard function
    if (key_pressed == THE_KEY_YOU_WANT)
        go_next = true;
    
    ... inside display:
    void display(void)
    {
        if (go_next)
        {
            go_next = false;
            glLoadIdentity();
            glColor3f(1.0f, 0.0f, 0.0f);
            glPushMatrix();
            ... etc
            glPopMatrix();
        }
        glutSwapBuffers();
    }
    

    Side note: It is best to keep the logic and rendering separate. So perhaps a code like this is best:

    int triangles_to_draw = 0;
    
    ... inside the keyboard function
    if (key_pressed == THE_KEY_YOU_WANT)
        process_event_next_triangle();
    
    void process_event_next_triangle()
    {
        if (triangles_to_draw < maximum)
            ++triangles_to_draw;
    }
    
    void display(void)
    {
        go_next = false;
        glLoadIdentity();
        glColor3f(1.0f, 0.0f, 0.0f);
        glPushMatrix();
        glTranslatef(20.0f, 20.0f, -40.f);
        glRotatef(180.f, 0.0, 0.0, 1.0);
    
        glBegin(GL_TRIANGLES);
        for (int i = 0; i < 3*triangles_to_draw; i += 3)
        {
            glVertex3f(pts[tri[i]], (pts[ptsLength/2 + tri[i]] - maximum) * -1, 0);
            glVertex3f(pts[tri[i+1]], (pts[ptsLength/2 + tri[i+1]] - maximum) * -1, 0);
            glVertex3f(pts[tri[i+2]], (pts[ptsLength/2 + tri[i+2]] - maximum) * -1, 0);
        }
        glEnd();
    
        glPopMatrix();
        glutSwapBuffers();
    }
    

    Note that this way, you can make the process_event_next_triangle as complicated as you want without affecting the display function. This makes life much easier when you have many keys doing different stuff.

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

Sidebar

Related Questions

I have the following code int main() { int a=6; void *p; p=&a; p++;
I have the following code: int a = 0; protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
i have the following code: #include <stdio.h> int main(void) { float a[4] __attribute__((aligned(0x1000))) =
I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int
I have the following code: #include<iostream> using namespace std; typedef void (*HandlerFunc)(int, int); HandlerFunc
I have the following code: Some functions: A::A(int i_a) {cout<<int Ctor\n;} //conversion constructor void
I have something analogous to the following code... void function(int x) { // complicated
I have a question about the following C code: void my_function() { int i1;
I have the following piece of code: class Student { public: Student(){} void display()

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.