1 / 13

GLUT Tips and Tricks

GLUT Tips and Tricks. Thomas Butkiewicz, Ph.D. GLUT Code Organization. Keep you main() simple!. GLUT Code Organization. Keep display() understandable. GLUT Code Organization. Save flexible functions for reuse later:. Organize your drawing functions.

jerom
Download Presentation

GLUT Tips and Tricks

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GLUTTips and Tricks Thomas Butkiewicz, Ph.D.

  2. GLUT Code Organization Keep you main() simple!

  3. GLUT Code Organization Keep display() understandable

  4. GLUT Code Organization • Save flexible functions for reuse later: Organize your drawing functions Use #define’s to adjust look and feel across entire program(s):

  5. Misc GLUT tips & tricks To get current window size: glutGet(GLUT_WINDOW_WIDTH); glutGet(GLUT_WINDOW_HEIGHT);

  6. Misc GLUT tips & tricks Get the vertical transformation out of the way first. How to use mouse scroll wheel:

  7. Misc GLUT tips & tricks For arrow keys, function keys, etc: glutSpecialFunc(special);

  8. Misc GLUT tips & tricks Escape key = 27 in ASCII:

  9. Controlling Redrawing Do Not:Call display() directly (redundant draws!) Do: Call: glutPostRedisplay() Sets a “window needs redrawn” flag Multiple calls only redraws once Call glutPostRedisplay(): • at the end of mouse & keyboard callbacks • in your idle() function, or… • in your timer() function……

  10. Controlling Redrawing - Timer glutIdleFunc(): • Hogs processor power (even when minimized!) • Sometime a certain max frame rate limit desired • Smoother animation possible glutTimerFunc(): • Add small timer function, which just calls glutPostRedisplay(): • Then set the timer at the very end of your display function: Minimum # of milliseconds until timer called

  11. Smooth Animations Animating a set amount each frame is bad! • Frame rate determines speed of object • IdleFunccan lead to varying speeds, incompatibility between systems • Even TimerFunc does not guarantee set frame rate E.g. if you move ball 1 pixel every frame, what seems like a good speed on your laptop, might be unplayably fast on the grader’s desktop.

  12. Smooth Animations Use system time to interpolate: • Windows: GetTickCount() returns time in milliseconds since boot #include “Windows.h” • Linux’s equivalent is: gettimeofday()

  13. Have fun!

More Related