View Full Version : NeHe Lesson18
NeHe Lesson18 will allow you to toggle between many different Shapes, toggle the lighting and Texture Quality and show you how to use Glu in your Programmes.
Keyboard Controls...
l - Toggle Lighting
f - Toggle Filter (Quality of Texture)
SpaceBar - Toggle Between Shapes
Shapes - Cube, Cylinder, Disk, Sphere, Cone and Partial Disk.
Cursor Key Up - Tilt Up
Cursor Key Down - Tilt Down
Cursor Key Left - Rotate Left
Cursor Key Right - Rotate Right
PgUp - Zoom Out
PgDn - Zoom In
Update
This is the New Version which includes the Keyboard Handling Routine that Petr mentions later in the thread. Now the programme can detect if any of the Keys have been released.
New Update
This version was updated on 29th June 2007 and the Code should be much clearer.
Michael Hartlef
20-03-2007, 19:26
Thanks Matthew, but.... where is lesson 17 ? ;)
I'm doing all the simple lessons first. :D
The Lessons which involve messing about with Text or Reading Data from Files I'm going to do last.
Petr Schreiber
20-03-2007, 21:18
Very nice lesson again!,
it runs too fast on my PC :)
I modified spacebar to be less sensitive using:
' Put before WHILE
dim SpaceBarReleased as long = 1
' Put in keychecking code
if tbgl_getasynckeystate(%vk_space) = 0 then SpaceBarReleased = 1
if tbgl_getasynckeystate(%vk_space) and SpaceBarReleased = 1 then
SpaceBarReleased = 0
Object +=1
end if
Maybe better would be something like TBGL_GetAsyncKeyOnce or something like that to do the dirty job for you, I will include it in next release if everything will go ok.
Thanks again,
Petr
Thanks Mathew another awesome lesson. Using GLU as you did adds to the beauty of this lesson and understanding more of how openGL works. Thanks again, Very nice!!
Maybe better would be something like TBGL_GetAsyncKeyOnce or something like that to do the dirty job for you, I will include it in next release if everything will go ok.
Thanks again,
Petr
Yep it would be very useful to have such a command Petr, not only in tbgl but regular thinBasic too. This way you can check for it once or use the standard control the way it is now.
As a quick remedy this is what I use, for the example I used the up arrow. All on one line and no extra variables to keep track of.
if tbgl_GetAsyncKeyState(%VK_up) then Xspeed -= 1: sleep 100: end if
@kryton9 - Thank's... :)
@Psch - I've updated the Download so it now detects if the SpaceBar or L and F Keys have been released. TBGL_GetAsyncKeyOnce would be a useful Command to have.
Michael Clease
15-06-2007, 09:04
To make it run at a viewable rate I've tried changing the timing can someone try it.
thanks
Petr Schreiber
15-06-2007, 09:35
Hi Abraxas,
thanks for update!
I tweaked even your improved version :P
Your code for calculating framerate:
framecounter = framecounter +1
ctime = gettickcount
dtime = ctime - stime
if dtime >= 1000 then
FrameRate = framecounter
framecounter = 0
stime = ctime
endif
... can be replaced with single line:
FrameRate = tbgl_GetFrameRate
Problem could occur with your framerate dependant code:
if tbgl_GetAsyncKeyState(%VK_left) then Yspeed -= FrameRate/1000000
With higher framerate we need to make smaller steps, but your code does opposite.
It is enough to divide by framerate:
if tbgl_getWindowkeystate(hWnd, %VK_left) then Yspeed -= 1/FrameRate
Attached version makes use of tbgl_GetWindowKeyOnce, which is new in TBGL 0.2.0.0.
So instead of:
if tbgl_getasynckeystate(%vk_space) = 0 then SpaceBarReleased = 1
if tbgl_getasynckeystate(%vk_space) and SpaceBarReleased = 1 then
SpaceBarReleased = 0
Object +=1
end if
... can now be used again just one liner:
if tbgl_getwindowkeyOnce(hWnd, %vk_space) then Object +=1
I am sorry to do "correction" of you code like an annoying school teacher :-[, but I think it can give better performance and save you some gray hair in future.
Bye,
Petr
Michael Hartlef
15-06-2007, 09:58
Petr, when you want to display the FPS, I use the same method to calculate it like Abraxas does. This way you see the numbers and not just a mess. :D
Btw, how does TBGL_GetFrameRate work internally?
Michael Clease
15-06-2007, 10:07
Psch thanks for that, it was about 30 minutes after posting when i was about to leave for work that i reaslised it was working backwards but didnt have time to go and modify it.
Mike - it is your routine (i nabbed it. :P) thanks.
Glad this information came up. Nice commands there Petr. Will make it so much easier. Didn't know about them, or if I read about them forgot.
I like simple, and these make things simple!
I came across this (http://lazyfoo.net/SDL_tutorials/lesson14/index.php) lesson on Lazy Foo, some time ago.
I'm thinking of creating a General Routine for Capping the Frame Rate which could be used in all the Lessons.
Petr Schreiber
15-06-2007, 12:40
Hi,
matthew, whats wrong with tbgl_GetFrameRate :'( ?
Mikes system is probably the most precise one, but it needs to wait some frames before it returns something and it tends to return more average value, while normally I need to know framerate in each frame to perform movement calculations.
TBGL_GetFrameRate is very simple function, lets see what it does...
It can be called only once in each frame. Why ? First because it was designed this way ;D and second it leads to real man coding ;D. Because when you store result at begining of each frame to variable, it is much more faster to read value from it later than invoke some measuring function multiple times per frame.
As it is called once in frame, it is enough to measure time between two calls to this function and from this find out how long frame took. TBGL_getframeRate is kind of hybrid, because in case it runs in old ( ancient ) hardware it uses GetTickCount to get time, while on newer PCs it automatically makes uses of hardware counter, which is very precise ... at least for this purpose :)
Bye,
Petr
^^
Lol, Okay then we'll use 'tbgl_GetFrameRate'. :D
Petr Schreiber
15-06-2007, 19:39
Good,
now I can sleep peacefuly :D
Bye,
Petr
Updated the Code a bit. 8)
Matthew thanks for the update.
Michael Hartlef
29-06-2007, 12:40
Yes, thank you Mattew.
^^
Thank's, I'm going to start updating the Code for all the other Lessons as well. :)
Petr Schreiber
29-06-2007, 15:19
Thanks Matthew,
its nice how you maintain your sources :)
Bye,
Petr