Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: How to create a timer

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2001
    Posts
    9

    How to create a timer

    I want to create a timer that will start when user press any key and will stop when it equal to 0 or when it reach the specific time.

    Can I create the timer using sytem time (Windows time) and how do I read it in GLUT. Can anyone help me?

  2. #2
    Intern Contributor nemesis's Avatar
    Join Date
    Nov 2001
    Posts
    92

    Re: How to create a timer

    This will return the windows time:
    long time = timeGetTime();

    You have to include "mmsystem.h"
    and import the library "winmm.lib".

    I wish it helps.
    - nemesis -


    [This message has been edited by nemesis (edited 12-28-2001).]

  3. #3
    Intern Contributor
    Join Date
    Aug 2001
    Location
    sdddskskfj
    Posts
    62

    Re: How to create a timer

    Hey cyam95! If I understood your point, you want to create a timer like the Delphi TTimer component, don't you?

    Well, you can create this using the SetTimer function. Example:


    VOID CALLBACK Refresh(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime) {

    KillTimer(hWnd, 41);

    // put your code here

    }


    SetTimer(hWnd, 41, miliseconds, Refresh);


    SeTimer function have four parameters! The first, you have to inform your Handle application, the second a ID number, that identifies your Timer (you can put what ever you want), the third is the time in miliseconds you want to wait, and the last is the Function the SetTimer function will call, when the time were elapsed.

    Inside the Refresh function, you have to kill the timer, we used the KillTimer function. The first parameter is the hWnd (Handle) of your application, and the second, the code ID that you used to create the Timer (in our case 41). Note: If you don't to Kill the timer, you don't need! I only putted the KillTimer inside the 'Refresh' function because you said in your message, that you wanted to kill the Timer, when the time were elapsed!

    I think it'll help you!!!!

    cya!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •