Solved

continuous updating of screen

Posted on 2004-09-30
11
284 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now