View Full Version : What is the main TBGL Setup ?
D.J.Peters
17-03-2010, 08:30
Hello Petr
can you please post the PB code how do you setup OpenGL and the code from TBGL_ClearFrame.
there are something wrong or not standard
lights about any object looks more from the side and
i must flip the y coord from normal if i load an model
in OpenGL normal 0,1,0 is in TBGL mode 0,-1,0 ?
can it be you use glEnable(GL_AUTO_NORMAL) in your OpenGL setup?
thank you
Joshy
by the way i don't get sphere map rendering working with TBGL
If P.UseEnv<>0 Then
glTexGeni (%GL_S, %GL_TEXTURE_GEN_MODE, %GL_SPHERE_MAP)
glTexGeni (%GL_T, %GL_TEXTURE_GEN_MODE, %GL_SPHERE_MAP)
glTexGeni (%GL_S, %GL_SPHERE_MAP, 0)
glTexGeni (%GL_T, %GL_SPHERE_MAP, 0)
glEnable(%GL_TEXTURE_GEN_S)
glEnable(%GL_TEXTURE_GEN_T)
TBGL_UseTexturing %TRUE
TBGL_UseBlend %TRUE
TBGL_BindTexture EnvMapID
TBGL_Color 0,0,0
TBGL_CallList P.ListID
TBGL_UseBlend %FALSE
TBGL_UseTexturing %FALSE
glDisable(%GL_TEXTURE_GEN_S)
glDisable(%GL_TEXTURE_GEN_T)
End If
Petr Schreiber
17-03-2010, 14:07
Hi Joshy,
the things which affect lighting in TBGL are the following:
glEnable %GL_NORMALIZE
glEnable %GL_AUTO_NORMAL
glShadeModel %GL_SMOOTH
glLightModelI %GL_LIGHT_MODEL_TWO_SIDE, 1
Regarding clear frame, by default it behaves like:
glClear( %GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT )
glLoadIdentity( )
... but this can be further tweaked by the passed params.
Regarding SphereMap "not working", could you be more specific, or ideally could you provide script/expected output?
I did few tests now, seemed ok to me:
' rotating cube with sphere mapping
Uses "TBGL" ' -- Module for 3D graphics
#INCLUDE "thinbasic_gl.inc"
#INCLUDE "thinbasic_glu.inc"
Dim hWnd As Dword
' -- Creates window and returns handle by which we can identify it
hWnd = TBGL_CreateWindowEx("Rotating textured square, press ESC to quite", 640, 480, 32, %TBGL_WS_WINDOWED)
TBGL_ShowWindow
' -- Loads texture to slot 1 with MIPMAP filtering
tbgl_LoadTexture APP_SourcePath+"Textures\Test.Bmp", 1, %TBGL_TEX_MIPMAP
' -- Enables aplication of textures to objects
tbgl_UseTexturing %TRUE
' -- We will apply texture 1
tbgl_BindTexture 1
TBGL_ResetKeyState() ' -- Resets status of all keys
' -- Main loop
While TBGL_IsWindow(hWnd)
' -- Erases previous frame
tbgl_ClearFrame
' -- Sets camera to look from 0,0,5 to 0,0,0
tbgl_Camera 0, 0, 5, _
0, 0, 0
' -- All following geometry will be rotated around vector 0,1,0
' -- That is - Y axis
TBGL_Rotate GetTickCount/10, 1, 1, 1
' -- Creates quads, shapes with 4 vertices
TBGL_BindTexture 1
glTexGeni (%GL_S, %GL_TEXTURE_GEN_MODE, %GL_SPHERE_MAP)
glTexGeni (%GL_T, %GL_TEXTURE_GEN_MODE, %GL_SPHERE_MAP)
glTexGeni (%GL_S, %GL_SPHERE_MAP, 0)
glTexGeni (%GL_T, %GL_SPHERE_MAP, 0)
glEnable(%GL_TEXTURE_GEN_S)
glEnable(%GL_TEXTURE_GEN_T)
TBGL_UseTexturing %TRUE
TBGL_UseBlend %TRUE
TBGL_BindTexture 1
TBGL_Box 1, 1, 1
TBGL_UseBlend %FALSE
TBGL_UseTexturing %FALSE
glDisable(%GL_TEXTURE_GEN_S)
glDisable(%GL_TEXTURE_GEN_T)
' -- Finishes drawing
tbgl_DrawFrame
' -- If ESC key is pressed, it will jump out of loop
If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While
Wend
' -- Destroys window
TBGL_DestroyWindow
With color 0,0,0 and blending enabled it produces nothing, but you can tweak the blend mode using TBGL_BlendFunc.
With color set to 255,255,255 it seems to work nicely here.
Thanks,
Petr
D.J.Peters
17-03-2010, 20:00
hello Petr
thanks for your fast answer.
i replaced the most TBGL commands (material and lights) with OpenGL commands
the same code works with C/C++ and FreeBASIC but i don't get it with thinBasic.
you can see the light over the car is shining from down to top
and the env.bmp texture isn't visible
the code is the same i used for the video you saw on youtube
would be nice if you can take a look on this
(sometimes i'm blind)
thank you
Joshy
Petr Schreiber
17-03-2010, 20:42
Two sided lighting confused it,
try the modified code from the attachement.
It looks already as it should(I think), very nice job!
Where did you get such a nice model?
Petr
Attachement removed
D.J.Peters
17-03-2010, 21:33
glLightModelI %GL_LIGHT_MODEL_TWO_SIDE, 0
yes sir this was the point of trouble :D
thank you
would be a good idea if you can post your OpenGL setup in the TBGL help file
it's hard to find if any other OpenGL coder will port code to TBGL.
by the way the BMW in the video is made by me the other fine models are
from many other secret sources. ;--)
i use this other models only for private rendering tests.
for my driving simulator/game (FreeSpeedRacer) i will use only my own models
(with many physical attributes)
and the FSR user/player can create his own vehicles too. (CarEdit3D is in work)
the world can be created with TrackEdit3D (not in work atm.)
currently i try to solve the math for trucks with trailers.
(the biggest problem are the joint limits if you drive backward with an trailer)
Joshy
Petr Schreiber
17-03-2010, 21:44
I am happy it works,
I will cover the initialization in help file or article, it is good idea and should avoid similar confusion.
Good luck with the trailer physics, and do not forget to post here the progress, I am sure there is lot of people able to test and give you feedback.
Petr
D.J.Peters
17-03-2010, 23:50
Is there any other pitfall with TBGL that i should know ?
for example do you use %GL_FRONT_AND_BACK in your material settings ?
TBGL_SetMaterialDiffuse()
TBGL_SetMaterialAmbient()
TBGL_SetMaterialSpecular()
TBGL_SetMaterialSpecularExponent()
TBGL_SetMaterialTexture()
Joshy
D.J.Peters
18-03-2010, 02:59
hello Petr
i'm again :oops:
i try to use many TBGL commands as posible but i run in to trouble with the material
please replace TBGL_init() with this new code and note how it looks
than change
If 1 Then ' setup material
to
If 0 Then ' setup material
you can see the result is not the same do you know why?
and was is the right replacement for glDepthFunc(%GL_LEQUAL) in TBGL
without it the spheremap rendring looks disabled.
thank you
Joshy
Sub TBGL_Init()
Local hMat As Long
Local vec4(4) As Single
TBGL_BackColor(25,25,50,0)
TBGL_UseDepth %TRUE
TBGL_BlendFunc %GL_ONE, %GL_ONE
TBGL_UseTexture %TRUE
If 1 Then ' setup material
GlEnable (%GL_COLOR_MATERIAL)
vec4(1)=1:vec4(2)=1:vec4(3)=1:vec4(4)=1
glMaterialfv(%GL_FRONT_AND_BACK, %GL_DIFFUSE ,vec4)
glMaterialfv(%GL_FRONT_AND_BACK, %GL_SPECULAR,vec4)
glMaterialf (%GL_FRONT_AND_BACK, %GL_SHININESS,50.0)
Else
hMat = TBGL_NewMaterial
TBGL_SetMaterialDiffuse(hMat,255,255,255)
TBGL_SetMaterialSpecular(hMat,255,255,255)
TBGL_SetMaterialSpecularExponent(hMat,50)
TBGL_PushMaterial hMat
End If
' setup 2 lights
TBGL_UseLighting %TRUE
TBGL_UseLightSource %GL_LIGHT0,%TRUE
TBGL_UseLightSource %GL_LIGHT1,%TRUE
TBGL_SetLightParameter %GL_LIGHT0,%TBGL_LIGHT_POSITION, 0,5,0,0
TBGL_SetLightParameter %GL_LIGHT0,%TBGL_LIGHT_DIFFUSE , 1,1,1,1
TBGL_SetLightParameter %GL_LIGHT1,%TBGL_LIGHT_POSITION,-2,2,0,0
TBGL_SetLightParameter %GL_LIGHT1,%TBGL_LIGHT_DIFFUSE , 1,0.7,0.4,1
TBGL_SetLightParameter %GL_LIGHT1,%TBGL_LIGHT_SPECULAR, 1,0.8,0.4,1
glDepthFunc (%GL_LEQUAL) ' <--- what are the TBGL counter part for it
glTexGeni (%GL_S, %GL_TEXTURE_GEN_MODE, %GL_SPHERE_MAP)
glTexGeni (%GL_T, %GL_TEXTURE_GEN_MODE, %GL_SPHERE_MAP)
glTexGeni (%GL_S, %GL_SPHERE_MAP, 0)
glTexGeni (%GL_T, %GL_SPHERE_MAP, 0)
glDisable(%GL_NORMALIZE)
glDisable(%GL_AUTO_NORMAL)
glLightModelI %GL_LIGHT_MODEL_TWO_SIDE, 0
End Sub
Petr Schreiber
18-03-2010, 09:26
Hi Joshy,
one thing first - TBGL is not OpenGL wrapper, that is why I provide both OpenGL headers and TBGL in thinBASIC, and that is why not all the functionality of OpenGL isn't directly reflected to TBGL.
Even materials in TBGL are designed to be used slightly differently -> define once, retrieve handle, and then use when necessary. TBGL materials can also have texture specified.
Regarding the difference in rendering - TBGL materials do not track the current glColor. So to get the same result, you have to do:
If 1 Then ' setup material
GlEnable (%GL_COLOR_MATERIAL)
vec4(1)=1:vec4(2)=1:vec4(3)=1:vec4(4)=1
glMaterialfv(%GL_FRONT_AND_BACK, %GL_DIFFUSE ,vec4)
glMaterialfv(%GL_FRONT_AND_BACK, %GL_SPECULAR,vec4)
glMaterialf (%GL_FRONT_AND_BACK, %GL_SHININESS,50.0)
Else
hMat = TBGL_NewMaterial
TBGL_SetMaterialDiffuse(hMat,255,255,255)
TBGL_SetMaterialSpecular(hMat,255,255,255)
TBGL_SetMaterialSpecularExponent(hMat,50)
TBGL_PushMaterial hMat
GlEnable (%GL_COLOR_MATERIAL)
End If
I don't like the "GlEnable (%GL_COLOR_MATERIAL)" switch too much, but I am putting it on the list of possible optional properties of TBGL materials.
Petr
christianssen
18-03-2010, 13:09
hi joshy,
very nice model with porsche car, thanks! :)
what 3d modelling (cayman.c3d) software you have used for this project ? it's a model created by your ownself (for free) ? or it's a 3d model you have had to buy for some hot dollars ? I know there are different 3d model librarys, but I didn't want to buy 3d models because I have no things in mind for needing in professional way.
bye, denis
D.J.Peters
18-03-2010, 22:12
thanx Petr
know i can see the problem.
hello christianssen
*.c3d is my own format from CarEdit3d.exe i'm working on.
I ripped some models as simple triangle strips from commercial games.
You can find many ripped models on the net too but it's only for private fun.
but if you like free car models i have found the bigest best site for it.
wait i`m searching the link for you
i found it there are 28 sites with cars but see self
http://dmi.chez-alice.fr/models0.html
here are the main site (with military vehicles, trucks, sport cars ..)
http://dmi.chez-alice.fr/models1b.html
Joshy
edit:
the most models are in *.lwo format
if you need an 3D object converter
http://web.t-online.hu/karpo/
not all but the most export formats are enabled in the shareware version