PDA

View Full Version : antique blending tbgl example :)



Lionheart008
16-12-2009, 22:17
old wine smells good :)
because I love this little and simple tbgl examples (found in an old tbgl folder on my notebook and didn't want to delete it!) I modified with new textures and some tbgl box, sphere. I like this kind of texture blending!
original code came from tbgl_batman petr / tbgl / "tbgl_demo3_quad_textureAndBlended".

perhaps it's also useful to learn for tbgl beginners with simple and exciting examples ;)



Uses "TBGL"

Dim hWnd As Dword

hWnd = TBGL_CreateWindowEx("Rotating textured square with blending, press ESC to quite", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow

TBGL_LoadTexture APP_SourcePath+"Textures/Avatar3d.Bmp", 1, %TBGL_TEX_MIPMAP
TBGL_LoadTexture APP_SourcePath+"Textures/house_interior.Bmp", 2, %TBGL_TEX_MIPMAP

TBGL_UseTexturing %TRUE

TBGL_BindTexture 1
'TBGL_BindTexture 2

TBGL_ResetKeyState()

While TBGL_IsWindow(hWnd)
TBGL_ClearFrame

TBGL_Camera 0, 0, 10, _
0, 0, 0

TBGL_Rotate GetTickCount/20, 0, 1, 0
DrawQuad()

TBGL_Color 255,100,25
TBGL_Box 1,1,1
TBGL_Translate 0, 0, 3

TBGL_Color 255,100,25
TBGL_Box 1,1,1

TBGL_Translate 1, 0, 5 '--
TBGL_Color 255,100,25
'TBGL_Box 1.5,1.5,1.5
TBGL_Sphere 1.25

TBGL_UseBlend %TRUE
DrawQuad()
TBGL_UseBlend %FALSE

TBGL_DrawFrame

If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While

Wend

TBGL_DestroyWindow

Sub DrawQuad()

tbgl_BeginPoly %GL_QUADS
tbgl_Color 255, 0, 0 ' -- Red color
tbgl_TexCoord2D 0, 0 ' -- Texture coordinate, lower left corner
TBGL_Vertex -2, -2, 0

tbgl_Color 0, 255, 0 ' -- Green color
tbgl_TexCoord2D 1, 0 ' -- Texture coordinate, lower right corner
TBGL_Vertex 2, -2, 0

tbgl_Color 0, 0, 255 ' -- Blue color
tbgl_TexCoord2D 1, 1 ' -- Texture coordinate, higher right corner
TBGL_Vertex 2, 2, 0

tbgl_Color 255, 255, 0 ' -- Yellow color
tbgl_TexCoord2D 0, 1 ' -- Texture coordinate, higher left corner
TBGL_Vertex -2, 2, 0
tbgl_EndPoly

TBGL_Translate 2,0,-1
TBGL_BeginPoly %GL_QUADS
TBGL_Color 255, 0, 0 ' -- Red color
TBGL_TexCoord2D 0, 0 ' -- Texture coordinate, lower left corner
TBGL_Vertex -2, -2, 0

TBGL_Color 0, 255, 0 ' -- Green color
TBGL_TexCoord2D 1, 0 ' -- Texture coordinate, lower right corner
TBGL_Vertex 2, -2, 0

TBGL_Color 0, 0, 255 ' -- Blue color
TBGL_TexCoord2D 1, 1 ' -- Texture coordinate, higher right corner
TBGL_Vertex 2, 2, 0

TBGL_Color 255, 255, 0 ' -- Yellow color
TBGL_TexCoord2D 0, 1 ' -- Texture coordinate, higher left corner
TBGL_Vertex -2, 2, 0
TBGL_EndPoly

TBGL_Translate -2,1,-4
TBGL_BeginPoly %GL_QUADS
TBGL_Color 255, 0, 0 ' -- Red color
TBGL_TexCoord2D 0, 0 ' -- Texture coordinate, lower left corner
TBGL_Vertex -2, -2, 0

TBGL_Color 0, 255, 0 ' -- Green color
TBGL_TexCoord2D 1, 0 ' -- Texture coordinate, lower right corner
TBGL_Vertex 2, -2, 0

TBGL_Color 0, 0, 255 ' -- Blue color
TBGL_TexCoord2D 1, 1 ' -- Texture coordinate, higher right corner
TBGL_Vertex 2, 2, 0

TBGL_Color 255, 255, 0 ' -- Yellow color
TBGL_TexCoord2D 0, 1 ' -- Texture coordinate, higher left corner
TBGL_Vertex -2, 2, 0
TBGL_EndPoly

End Sub


two tbgl texture blending examples you find in zip file.

good night, frank

TomLebowski
17-12-2009, 13:13
hi frank! your texture blending example looks simple, the effect is indeed still great. I don't know all tons of tbgl examples, but this I like! :) I tried to make tbgl_sphere(s) and tbgl_boxe(s). the distance to texture belongs to z coordinate? that's true ?
I noticed if I increase z coordinate all other texture grow up in distance. - new tbgl works with entities, so far I have learned, but good to save also this old way.
many thanks for your lot of examples at the forum. I am always be impressed. even the little one I like with big show effects! bye, tom

ErosOlmi
17-12-2009, 13:58
Hi Tom.

I do not know if you had the chance to check TBGL bonus packs here:
http://www.thinbasic.com/index.php?option=com_jdownloads&Itemid=95&task=viewcategory&catid=5

TBGL bonus packs are a collection of script many thinBasic users posted here in forum.
Even if examples were created some time ago, they should still compatible with current thinBasic and can be a nice opportunity to experiment TBGL features.

Have fun
Ciao
Eros

TomLebowski
18-12-2009, 11:48
thanks eros for tbgl_bonus pack (there are two issues!), also frank has sent me last night a list with good tbgl examples!

one wish: (perhaps petr or anybody else can help)
- it's possible to update the "fun space game" with modern and correct entity feature ?

I like tbgl but don't know how it will be influence my way with GUI theme. perhaps I can mix my imagines. I like thinbasic and community. very nice people here and it's a small community with engaged guys. thanks. bye, tom (back to work again;) and off now.

Lionheart008
18-12-2009, 16:20
hello tom. short reply.

1) I send one little, simple tbgl example for you. it's not very hard to understand entities and work out your first example, if you have any problems with your tbgl example, ask ;)

this example a) use entities like "EntityCreateSphere" (here: "%eSphere") and b) simple "EntityCreateDLSlot" displaylist (here: "%lBoxy": have done four objects in one displaylist, translated at different positions and with different colors!) and moving objects by pushing keys.
the big yellow sphere (a sun?) "%sphere" will move slowly to left or right (up, down key) and other objects rotating around if you like to use left or right key. try it :)


TBGL_EntityCreateSphere(%sScene, %eSphere, 0, 1.5, 0, 255, 255, 0)
...
TBGL_EntityCreateDLSlot(%sScene, %eBoxy, 0, %lBoxy)

simple tbgl_example:

'-- simple tbgl example with box, sphere using entities

Uses "TBGL"

Begin Const
%sScene = 1
%eCamera = 1
%eTriangle
%eBoxy
%eSphere
End Const

Begin Const
%lTriangle = 1
%lBoxy
%lSphere
END CONST


FUNCTION TBMAIN()
LOCAL hWnd As DWORD
LOCAL FrameRate AS DOUBLE

hWnd = TBGL_CreateWindowEx("simple TBGL entity_Example for Tom - use [up],[down],[left],[right] keys", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX Or %TBGL_WS_MINIMIZEBOX Or %TBGL_WS_MAXIMIZEBOX)
TBGL_ShowWindow

TBGL_SceneCreate(%sScene)

TBGL_EntityCreateCamera(%sScene, %eCamera)
TBGL_EntitySetPos(%sScene, %eCamera, 0, 0, 12)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)

TBGL_NewList %lboxy
TBGL_Translate 2,0,1
TBGL_Color 255,0,10
TBGL_Box 1,1,1 '- box

TBGL_Translate 1,1,1
TBGL_Color 0,100,255
TBGL_Sphere 0.6 '- sphere

TBGL_Translate 2,-1,1
TBGL_Rotate 45, 1,1,1
TBGL_Color 255,100,155
TBGL_Torus 0.25,1.25 '- torus1

TBGL_Color 100,0,100
TBGL_Rotate 270, 1,1,1
TBGL_Torus 0.25,1.15 '- torus2
TBGL_EndList

TBGL_EntityCreateDLSlot(%sScene, %eBoxy, 0, %lBoxy)
TBGL_EntitySetPos(%sScene, %eBoxy, 0, 0, 0)

TBGL_EntityCreateSphere(%sScene, %eSphere, 0, 1.5, 0, 255, 255, 0)
TBGL_EntitySetPos(%sScene, %eSphere, 0, 0, 0)

TBGL_ResetKeyState()

While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
TBGL_SceneRender(%sScene)
TBGL_DrawFrame

If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
If TBGL_GetWindowKeyState(hWnd, %VK_UP) Then TBGL_EntityTurn(%sScene, %eBoxy, -1, 0, 0)
If TBGL_GetWindowKeyState(hWnd, %VK_DOWN) Then TBGL_EntityTurn(%sScene, %eBoxy, 1, 0, 0)
If TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then TBGL_EntityTurn(%sScene, %eBoxy, 0, 1, 0)
If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then TBGL_EntityTurn(%sScene, %eBoxy, 0,-1, 0)
If TBGL_GetWindowKeyState(hWnd, %VK_PGDN) Then TBGL_EntityTurn(%sScene, %eBoxy, 0, 0, 1)
If TBGL_GetWindowKeyState(hWnd, %VK_PGUP) Then TBGL_EntityTurn(%sScene, %eBoxy, 0, 0,-1)
If TBGL_GetWindowKeyState(hWnd, %VK_UP) Then TBGL_EntityPush(%sScene, %eSphere, -0.01, 0, 0)
If TBGL_GetWindowKeyState(hWnd, %VK_DOWN) Then TBGL_EntityPush(%sScene, %eSphere, 0.01, 0, 0)
Wend

TBGL_DestroyWindow
END FUNCTION


2) to see one more simple example look at the triangle example I send too.

3) look at petr's website for tbgl beginners tutorials:
http://psch.thinbasic.com/old/tbgl_tut_b.html

best regards, frank