Results 1 to 8 of 8

Thread: Help: Why can't I put glutPostRedisplay inside while loop?

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2001
    Location
    Singapore
    Posts
    28

    Help: Why can't I put glutPostRedisplay inside while loop?

    Hi all,

    I try to put glutPostRedisplay inside a for loop or while loop but I doesn't work example

    for (int k=0; k<5; k++)
    { translate +=5;
    glTranslatef(translate, 0.0, 0.0);
    glutPostRedisplay();
    }

    It doesn't work.. this will only be redisplayed after the last iteration. What I want is every iteration it's displayed. Can anyone help me?

    regards,
    songeb

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: Help: Why can't I put glutPostRedisplay inside while loop?

    In your 'draw' function you want glutpostredisplay and glutswapbuffers

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: Help: Why can't I put glutPostRedisplay inside while loop?

    is this in your 'draw' function?

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2001
    Location
    Singapore
    Posts
    28

    Re: Help: Why can't I put glutPostRedisplay inside while loop?

    sorry I don't understand your previous reply

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2001
    Location
    Singapore
    Posts
    28

    Re: Help: Why can't I put glutPostRedisplay inside while loop?

    sorry just received the other one from you

    hmmm... no it's not.. it's inside another function to short of animate it

  6. #6
    Junior Member Newbie
    Join Date
    Feb 2002
    Location
    -
    Posts
    1

    Re: Help: Why can't I put glutPostRedisplay inside while loop?

    the problem is, that glutPostRedisplay works "parallel" to the rest of the program. And the code in the while loop is executet faster than the glutPostRedisplay.
    A solution would be to implement this code in the Idel-function of Glut.

  7. #7
    Senior Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Holland
    Posts
    179

    Re: Help: Why can't I put glutPostRedisplay inside while loop?

    You have to separate your drawing code from your timing code.

    Create a Draw() method that will draw all your geometry for a scene at the 'current' time, where 'current' is determined when starting the Draw().

    Then also activate the GLUT Idle callback, and inside that callback do a glutPostRedisplay().

    Do your transforms and other time-dependent changes at the beginning of Draw(), based on the current time and/or the amount of elapsed time.

  8. #8
    Junior Member Newbie
    Join Date
    Dec 2001
    Location
    Singapore
    Posts
    28

    Re: Help: Why can't I put glutPostRedisplay inside while loop?

    Ok thanks all.. I follow your sugestion I write another function to redraw the object and call the glutPostRedisplay and it works thanks all

Similar Threads

  1. break/return statement inside loop reacts unexpectedly
    By Kleinkind87 in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 02-10-2017, 11:09 AM
  2. Taking input while inside while loop
    By biribiri in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 10-26-2013, 01:50 PM
  3. Replies: 3
    Last Post: 01-28-2013, 08:25 PM
  4. lot of if and while loops inside a for loop
    By agmegharaj in forum OpenCL
    Replies: 0
    Last Post: 08-24-2011, 01:45 AM
  5. loop with glutpostredisplay
    By bsperlin in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 09-07-2003, 10:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean