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
Solved

continuous updating of screen

Posted on 2004-09-30
11
288 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GPU processing of c++ library 7 110
3D rotation changing an axis 4 81
Any Game advice for ellipses drawing a solar system? 1 75
PDF: Display my cards game? 8 124
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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

790 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