Solved

continuous updating of screen

Posted on 2004-09-30
11
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…

752 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