Hi Petr, this Morning I started work on NeHe Lesson 10 but it was taking me too long to do so I moved straight onto Lesson 11.
But now I'm having trouble with the glPolygonMode Commands.
If I include the following Code in my Programme...
glpolygonmode %gl_back, %gl_line
glpolygonmode %gl_front, %gl_fill
It appears to draw the Flag back-to-front. ???
The Programme works without the glPolygonMode Commands but it's a bit slow.
I've included the Code and Texture so you can take a look at it.
Petr Schreiber
17-03-2007, 21:59
Hi,
I can confirm it runs very slow.
Give me few minutes...
Bye,
Petr
Petr Schreiber
17-03-2007, 22:18
Mathew,
using
glFrontFace %GL_CW
you will specify which vertex order is visible and your code will look ok.
Worse is the speed of this example, it will be good "victim" for my model shading practices :)
Bye,
Petr
Thank's for your help. :)
ErosOlmi
17-03-2007, 22:37
I will study this example to see if any other optimization in Core engine is possible.
Thanks
Eros
Petr Schreiber
17-03-2007, 22:53
Hi,
if you download Matthew translation you will see how it is done in classic languages using classic approach.
Here is sample which uses "model shaders" implementation in TBGL 0.1.9.2.
On my PC it runs about 40% faster.
Please note syntax in current release is quite unpleasant, next release will have some better syntax ( while maintaing backwards compatiblity ), Matthews original is needed also because of texture!
'*****************************************************************************
'* NeHe Lesson11 *
'* *
'* conversion by Matthew *
'* tweak by Petr Schreiber *
'* *
'*****************************************************************************
uses "TBGL" ' thinBASIC OpenGL Library
uses "MATH" ' Math Library, needed for PI.
dim Xrot as single ' X-Rotation
Dim Yrot as single ' Y-Rotation
dim Zrot as single ' Z-Rotation
' Create Our Window and Return Handle
DIM hWnd AS dword = TBGL_CreateWindow("NeHe Lesson11 - Press 'ESC' to Quit")
TBGL_ShowWindow ' Show Our Window
tbgl_GetAsyncKeyState(-1) ' Reset all the Keys
' Load Texture
tbgl_loadtexture app_sourcepath + "NeHe_Tim.bmp", 1, %tbgl_tex_linear
' ! We don't need to enable texturing or bind texture TBGL engine handles
' this automatically for virtual models
dim x,y,i as long
dim VertexID as long
' 45 * 45 squares ( = 4 vertices ) = 8100
tbgl_m15InitModelBuffers 1, 8100
' Sets model upper vertex limit
tbgl_m15SetModelVertexcount(1, 8100)
' Creation of mesh we will modify
' in TBGL 0.1.9.2 it is still quite clumsy ( lot of typing )
for x = 1 to 44
for y = 1 to 44
incr VertexID
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15TexN, 1)
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15TexX, X / 45.0)
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15TexY, Y / 45.0)
tbgl_m15SetVertexXYZ( 1, VertexID, (X / 5.0) - 4.5, (Y / 5.0) - 4.5, 0)
tbgl_m15SetVertexRGB( 1, VertexID, 255,255,255)
incr VertexID
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15TexN, 1)
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15TexX, (X+1) / 45.0)
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15TexY, Y / 45.0)
tbgl_m15SetVertexXYZ( 1, VertexID, ((X+1) / 5.0) - 4.5, (Y / 5.0) - 4.5, 0)
tbgl_m15SetVertexRGB( 1, VertexID, 255,255,255)
incr VertexID
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15TexN, 1)
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15TexX, (X+1) / 45.0)
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15TexY, (Y+1) / 45.0)
tbgl_m15SetVertexXYZ( 1, VertexID, ((X+1) / 5.0) - 4.5, ((Y+1) / 5.0) - 4.5, 0)
tbgl_m15SetVertexRGB( 1, VertexID, 255,255,255)
incr VertexID
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15TexN, 1)
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15TexX, X / 45.0)
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15TexY, (Y+1) / 45.0)
tbgl_m15SetVertexXYZ( 1, VertexID, (X / 5.0) - 4.5, ((Y+1) / 5.0) - 4.5, 0)
tbgl_m15SetVertexRGB( 1, VertexID, 255,255,255)
tbgl_m15SetVertexparam( 1, VertexID, %TBGL_m15PSTOP, 1)
next
next
local floatX as single
local frameTime as single
While tbgl_isWindow(hWnd)
TBGL_ClearFrame ' Clear the Screen
tbgl_translate 0.0, 0.0, -12.0 ' Move Into the Screen
tbgl_rotate Xrot, 1.0, 0.0, 0.0
tbgl_rotate Yrot, 0.0, 1.0, 0.0
tbgl_rotate Zrot, 0.0, 0.0, 1.0
frameTime = gettickcount/500
for i = 1 to 8100 '45*45*4
floatX = tbgl_m15getVertexParam(1, i, %TBGL_m15X)
tbgl_m15SetVertexParam( 1, i, %TBGL_m15Z, sin(frameTime + floatX))
next
' Finally we render flag
tbgl_m15DrawModel 1
Xrot += 0.3
Yrot += 0.2
Zrot += 0.4
tbgl_drawframe
If tbgl_GetwindowKeyState(hWnd, %VK_ESCAPE) then Exit While
Wend
TBGL_DestroyWindow ' Closes OpenGL Window
Bye,
Petr
I've just tried it and it runs a lot faster on my Computer. :)
Petr Schreiber
17-03-2007, 23:05
Hi,
this NeHe sample is quite brutal: 8100 vertices, that's quite a lot for immediate mode :)
Main boost consists in fact that using m15 functions mesh is precreated before execution, and then we modify just Z component.
In original NeHe you assign all: UVs and coordinates each frame.
Bye,
Petr
Guys came home and found another cool tutorial. The immediate mode ran ok, just a little jittery, the m15 version was nice and smooth. This will be another great lesson to learn from, thanks guys!!