Solved

continuous updating of screen

Posted on 2004-09-30
11
289 Views
Last Modified: 2013-12-06
I have the following main and some functions. the roam() handles keystrokes. I change my camera's location based on the key strokes but the window is not updated after each key stroke. I have to resize the window to update the screen. can any one tell me what is wrong here?

int main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitWindowSize(600,600);
  glutInitDisplayMode(GLUT_DEPTH);
  glEnable(GL_DEPTH_TEST);
  glutCreateWindow("two polygons");
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutSpecialFunc(roam);
  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}

void reshape(int w, int h){...}
void display(void){...}
void roam(int key, int x, int y){
  switch(key){
    ...
  }
  reshape(w, h);
}
0
Comment
Question by:jhshukla
  • 5
  • 4
  • 2
11 Comments
 
LVL 1

Expert Comment

by:gseidman
ID: 12202485
Is there some reason you are using glutSpecialFunc() instead of glutKeyboardFunc()? Anyhow, you need to call glutPostRedisplay() any time you want the display to update, such as at the end of your keystroke handler.
0
 

Expert Comment

by:evolutional
ID: 12202924
I'd recommend that you update one per frame after your game has finished it's update logic. Normally, you'll render (via glutPostRedisplay) at the end of your mainloop as it's that function that usually calls the internal game logic.
0
 
LVL 9

Author Comment

by:jhshukla
ID: 12203477
glutSpecialFunc is for handling non ascii keys - i want arrow keys.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:gseidman
ID: 12203612
It shouldn't matter whether you use glutSpecialFunc() or glutKeyboardFunc(), you just need to call gluPostRedisplay() at the end of your handler.
0
 
LVL 9

Author Comment

by:jhshukla
ID: 12210014
I haven't tried glutPostRedisplay yet (but will do pretty soon). anyways I got it working by calling both display() and reshape(). If I call only one of them, it doesn't work. why?
plus, the response of the program lags by one keystroke. the first keystroke doesn't do anything and subsequent keystrokes generate the effect of the one just before them. how can I correct this?
0
 

Expert Comment

by:evolutional
ID: 12210719
It's likely to be with how your mainloop is structured. What does your mainloop in comparison to your keyboard handling routines?
0
 
LVL 1

Expert Comment

by:gseidman
ID: 12211540
Remember that display() and reshape() are your own functions, not GLUT or GL functions. You need to tell the GL subsystem to actually do something to the screen, and the way you do that is by calling glutPostRedisplay() (which will, in turn, call your display() function). The first thing to do to correct your update problems is to make sure that the GL subsystem knows when it should update, so please add the call to glutPostRedisplay() in your glutSpecialFunc() handler.
0
 
LVL 9

Author Comment

by:jhshukla
ID: 12212471
>> ... and the way you do that is by calling glutPostRedisplay() (which will, in turn, call your display() function).
I noticed that by adding printf statements in the display function. but it does not call the reshape function which actually renders the scene on the screen. do I need to call it manually or can I specify something so that it gets called automatically after display().


>> It's likely to be with how your mainloop is structured. What does your mainloop in comparison to your keyboard handling routines?
I am using glut's glutMainLoop(). from what I know so far, it handles all messages and communication between the window and the system.
0
 
LVL 1

Accepted Solution

by:
gseidman earned 30 total points
ID: 12212766
Why does your reshape() function draw the scene? You give glutReshapeFunc() the callback for when the drawing window changes size, not for when the scene needs to be redrawn. Do your drawing in the display() function. The reshape() function may or may not need to call glutPostRedisplay(), I don't recall. At this point, I'm done. Please accept the answer and assign points. Or don't. You're only offering 30, and the guidance I've given you already is worth far more than that.
0
 
LVL 9

Author Comment

by:jhshukla
ID: 12213754
>> You're only offering 30, and the guidance I've given you already is worth far more than that.
If you are not satisfied with the final assignment, then you raise this question. And if that is the case you can always ask in the CS Forum.

And to be honest I think your help was just 25 pts so far. To appreciate the value of points you better visit a C/C++ forum and see what kind of questions and clarifications people ask.

And I asked for clarification on an issue, not a solution to the problem. plus you never said anything about lagging in response to key strokes. I would have happily given away 50 points, had you been a little nice about it.
0
 
LVL 1

Expert Comment

by:gseidman
ID: 12217320
I'm happy with the assignment. And I'm currently working on a 500 point issue in the C++ channel, so I do know what's going on.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Python - How does this 2D array not work? 3 93
Recording what a camera sees for future playback. 5 41
Compile GLUT with Visual Studio 2015 1 204
count7 challenge 12 130
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question