PDA

View Full Version : Help on TBGL/OpenGL



Lionheart008
04-09-2008, 22:39
Thread splitted from http://community.thinbasic.com/index.php?topic=2006.0
_________________________________________________

hi all:-)

question for the open gl window you have attached in the last post...

1) how can I rotate an open gl polygon? after that I will rotate it by mouse or move it with the arrow tabs of the keyboard (open, left, right, down) :-)

"TBGL_TranslatePoly" doesn't exist or shows errors, the same to
"TBGL_RotatePoly"



TBGL_Translate Poly %GL_LINES(-0.0, 0.0, -4.0) '' Move Left 1.5 Units And Into The Screen 4.0
TBGL_Rotate Poly %GL_LINES(1.0, 2.0, 0.0) '' Rotate The Triangle On The X axis ( NEW )

TBGL_BeginPoly %GL_LINES
' -- Horizontal, from left to right, in half of screen
TBGL_COLOR 255, 0, 0
TBGL_Vertex 0, 0.55
TBGL_COLOR 255, 0, 0
TBGL_Vertex 1, 0.55

' -- Vertical, from top to down, in half of screen
TBGL_COLOR 255, 0, 0
TBGL_Vertex 0.55, 0
TBGL_COLOR 255, 0, 0
TBGL_Vertex 0.55, 1

TBGL_ENDPOLY

TBGL_Rotate Poly %GL_LINES = + 0.8 '' Increase The Rotation Variable For The Triangle ( NEW )


TBGL_RotatePoly = + 0.8 doesn't function too;-)

Perhaps somebody can help...

good evening, good ideas and until the next time, best regards, lionheart

ps: good to hear the next new issue of thinbasic will come this month! :->

Lionheart008
05-09-2008, 00:16
hi again:-)

I have solved my problem with the rotation while exploring another open gl script;-))


SUB Render_SceneGeometry()

tbgl_Rotate GetTickCount/10, 0, 1, 0
' -- Put here rendering code

TBGL_Box 1, 2, 3

END SUB

good night! :D

ErosOlmi
05-09-2008, 04:17
Lionheart008,

because you seems interested in OpenGl and TBGL, maybe worth to mention you TBGL Bonus Pack (http://www.thinbasic.com/index.php?option=com_docman&task=cat_view&gid=23&Itemid=66)

TBGL Bonus Pack is a collection of nice thinBasic scripts working with TBGL. You will find inside a lot of sources and projects developed during some years here in thinBasic community and collected into a single ZIP file.

Ciao
Eros

Michael Hartlef
05-09-2008, 07:12
hi again:-)

I have solved my problem with the rotation while exploring another open gl script;-))


SUB Render_SceneGeometry()

tbgl_Rotate GetTickCount/10, 0, 1, 0
' -- Put here rendering code

TBGL_Box 1, 2, 3

END SUB

good night! :D


Hi Lionheart008,

welcome here on the forum. Yes, looking at other scripts is good way of learning TBGL. TBGL isn't just an OpenGL wrapper, it is much more powerfull. Btw. you can use OpenGL with it's native commands via the include files that Petr provided. And don't forget to add the TBGL help file to the user help in thinAir. This way you will be able to place the cursor on one command, press F1 and the help will open up right away!

Cheers
Michael

Petr Schreiber
05-09-2008, 09:25
I am sorry to be the last one to reply,

but I was away from PC.

Another source for learning is TBGL website (http://psch.thinbasic.com/index.html).
You can get there another info on TBGL - articles, tutorials, support tools...

I am considering writing new "from beginner to advanced user" series of tutorials, to avoid confusion.
Let me know.

As Mike said, TBGL is not OpenGL 1:1 wrapper, you can code via following ways ( even mix it freely )
Use TBGL just for window handling and do the rest using native OpenGL provided by headers
Use low level TBGL commands like you do now
Use high level, but also high performance entity system



Petr

Lionheart008
05-09-2008, 09:54
Good morning dear Gentlemens:-)
hi all here thanks for your friendly replies:

hi michael:


Btw. you can use OpenGL with it's native commands via the include files that Petr provided. And don't forget to add the TBGL help file to the user help in thinAir. This way you will be able to place the cursor on one command, press F1 and the help will open up right away!

1) can you help with a link or how I can find Petr include files?

2) what I wish: a) open gl window / or b) a pure windows 32 gui with making a lot of menus for a later application I will build with thinBasic, perhaps it's better to think about the way to build a window include with open gl features???? I have no experience with this one;-) until today

3) it's a hard stuff for a newbie ;-) I would like to build in a few weeks (month, year) a new "sds/nurbs modeler" ( I call this project "INKA 3D", open source...) or/and a "colour tool" with thinBasic (thinAir), that's my aim here. I see the encouraged people here and that's what I like... I searched for a little tool like thinBasic (or Freebasic!) to learn with the software and its tool... Perhaps I have found this sweet "home" (must laugh, the word "Heimat" doesn't exist in englisch), perhaps you know what I mean...

I make mistakes and ask a lot, but I am full of ideas and learn day by day... :-)))

last question for petr


As Mike said, TBGL is not OpenGL 1:1 wrapper, you can code via following ways ( even mix it freely )

* Use TBGL just for window handling and do the rest using native OpenGL provided by headers
* Use low level TBGL commands like you do now
* Use high level, but also high performance entity system

TBGL for window handling... can be I am looking for this one, do you have any example?

cheers to all here and thanks a lot for you help and open for me a new door ::)

ps: I have attached my little idea as a project... a window gui menu without function... I started it some days before and now I learn thinBasic (must laugh!) ;-)))

ErosOlmi
05-09-2008, 11:48
1) can you help with a link or how I can find Petr include files?


All the files you need are under \thinBasic\Inc\ directory.

Check \thinBasic\SampleScripts\TBGL\TBGL_UsingAPI.tBasic script. It shows how to include OpenGL files and use them in simple way.

Ciao
Eros

PS: because i think this thread is now going out of its original request (title is"how to build an *.exe file with thinbasic?") what about opening specific new requests post in TBGL dedicated forum at http://community.thinbasic.com/index.php?board=39.0 Having specific post talking about specific requests is much better for all: for who has to reply, for who will read the posts in future just for learning. If you accept, I can split this post into separated thread and place your requests into TBGL forum.

Petr Schreiber
05-09-2008, 12:45
I vote for splitting.

To answer the questions:
1) To create OpenGL app, with TBGL just for rendering and window management

Open ThinAir
Click New / New file
In templates window, choose TBGL folder and click "TBGL_RawOpenGLSkeleton"
Click use, it will generate new file for you, with all headers properly linked


2) a)
Again you can choose TBGL template

2) b)
Design the menus, buttons ... everything like you did till now.
ThinBasic 1.7.0.0 will bring you possibility to insert OpenGL control inside. I will provide source code + dedicated article with all needed explained.

3) - Inka3D
Definitely possible. Little tip - I would recommend you to sign for 1.7.0.0 preview, or wait for 1.7.0.0 public release.
Current thinBasic can do the job for you without problem, but 1.7.0.0 will introduce two important big helpers:

Callback mechanism, instead of WHILE IsWindow ... you can use true window ( and even control ) callback
TBGL control inside dialog - automatic, no API knowledge needed while still very flexible


You will see it will make code much shorter, with much less struggle.
The "motivation image" I did is done using 1.7.0.0 preview.


Petr

Lionheart008
05-09-2008, 14:39
dear eros, petr and thinbasic friends,

short message:-)

"YES please split this topic, it's better ;-)"

I will come back later...

best regards, I check the files and the new version of thinBasic :-D

servus, lionheart

ErosOlmi
05-09-2008, 15:28
Split done.
Thanks a lot for understanding. We try to keep this community as organized as we can.

Lionheart008
05-09-2008, 18:11
... so I have done it, my first "open GL" example is ready with a simple rotating cube and a coordinate system :-)

thanks petr for the skeleton TBGL ... very useful... help and advices from all here, not very easy to learn this new tools, but it's exciting to see if it's run (run rudolph run!) ;-)

I attach a picture above, the code as file too:-)))

ciao and good ideas for today with thinbasic!

lionheart

ErosOlmi
05-09-2008, 18:20
Perfect. Seems you are progressing very nicely.

And you said you are a beginner ???
I cannot imagine when you will be an advanced!!!

Petr Schreiber
05-09-2008, 18:38
Very nice!,

congratulations on your first TBGL script :)


Petr

Petr Schreiber
05-09-2008, 19:04
And as a special prize for your fast progress...

... lets make it even faster and determine where do you click in 3D ;)
See new cursor functions in attached source code.


Petr

Lionheart008
05-09-2008, 19:37
...for eros and petr:-)

oh no... you are very welcome ;D
but motivation is the best way to become new skills (right word?) ;-) and I am happy too, that it all function as well...

some kind of shame upon me, it was only to look into some examples, copy, changes a little some entries and I make some new lines, nothing else...

very good idea to build in new mouse function, looks very nice with left mouse and right mouse clicking the colours of the sphere is changing and she's following the cube! wow! :-)

now I have to handle my girlfriend very close.. she can speak and is full in 3d realtime! ;-D

have a nice evening all to you!

servus, best regards, lionheart

ps: a window gui / open gl view window with menu functions folder is possible (petr)...? with the new issue of thinbasic 1.7.0.0? - you have attached a picture in another thread with my button-example... perhaps I can see more... but not today.. cheerioh

Petr Schreiber
05-09-2008, 20:40
Hi Lionheart ;D,



a window gui / open gl view window with menu functions folder is possible (petr)...? with the new issue of thinbasic 1.7.0.0?


Yes, it is possible in 1.7.0.0. It would be possible now via using some declarations from Win32 ... but as I said - better to wait for 1.7.0.0. I am sure its release is quite near, instead of multiple code blocks via API, you will be able to setup and destroy TBGL "control" just using 2 lines of code.

Stay tuned, let me know of any other questions.


Petr

Michael Clease
05-09-2008, 21:44
Hello Lionheart,

here is a little tip for a modeller look.

add the line before each Render_SceneGeometry()

add this for 3 of the windows

TBGL_PolygonLook %GL_LINE

and this line for 1 of the windows

TBGL_PolygonLook %GL_FILL

good luck

Mike

Michael Clease
05-09-2008, 22:33
I made my idea a bit more flexible.

see the bits marked ' *************************************

to change how each view looks just change

viewtype(n) = %GL_POINT
viewtype(n) = %GL_LINE
viewtype(n) = %GL_FILL

n is the number 1 to 4 (4 views)

Petr Schreiber
05-09-2008, 22:43
Abraxas,

very good idea.
In thinEdge modeller, I used to have array of UDT to describe viewport properties. So something like:


TYPE tViewportSetup
DrawPoints AS BYTE
DrawContours AS BYTE
DrawPolys AS BYTE
DrawTextures AS BYTE
DrawAlpha AS BYTE
END TYPE

...

DIM Viewport(4) AS tViewportSetup



Bye,
Petr

Lionheart008
06-09-2008, 13:42
dear abraxas and petr...

:-))) good improvements for the script, I like it! - thank you and unfortunately I am out of order today, have got any kind of a cold... don't know, perhaps it's a virus, damned...

see you soon and with new ideas and forces ;-D

lionheart some hours in bed... drinking tea...

ok... little question again...

qt: it's possible to fetch (get/set) the "properties" of an object I have created with thinbasic? in my example create or "popup" a little window with properties like "size, volum, color, vertex points" and so on for my cube? :-)))) must laugh...

now it's finished... eyes are burning and I am too tired for concentration any more...

ErosOlmi
06-09-2008, 18:00
ok... little question again...

qt: it's possible to fetch (get/set) the "properties" of an object I have created with thinbasic? in my example create or "popup" a little window with properties like "size, volum, color, vertex points" and so on for my cube? :-)))) must laugh...


A property control is something I have in the list of things to be implemented natively in one of the next thinBasic versions.

Michael Clease
06-09-2008, 18:13
Petr will confirm this but TBGL does not have a function to return geometry unless any objects are created using the modelling function which is what I would use in this situation.

As far the menu goes you could use the "UI" module and look at the MENU section "PopUpMenu" but I dont think it will work as the handle that TBGL returns isnt the windows handle (i think unless Petr has changed it).

You could still use the "UI" module and just create a Dialog at the current mouse position that way you can use listview controls.

just food for thought.

enjoy your sleep

Petr Schreiber
06-09-2008, 19:04
Hi Lionheart,

as I said, there are multiple paths to code with TBGL, from low level to high level.
The high level way is based on Scene-Entity system.

You can basically add lights, geometric objects, display lists and m15 models to scene.
Every "entity" can contain user defined data, that is where you could store your specific information like volume.

To get a bit of idea on entity based approach, use New/New file/TBGL/TBGL_EntitySkeleton.taguit template.


Will write more later,
Petr

Lionheart008
08-09-2008, 14:26
Hi Petr:-) hi all... thank you much more for your replies ::)

1) next question belongs to include a pyramid into the grid entity 3d open gl window..

I cannot build in the rotating pyramid.. I think I must not include everything to build the pyramid... I have got an "error message: draw pyramid", so it seems to be a line error...
don't know...

if you have time have a look at this script, it would be very nice...

2) My opinion it's the right way to build first of all the entity world, after that the pyramid...






'---Load needed modules
Uses "TBGL"
uses "UI"

' Rotation Variable
dim angle as single
dim Sheeps as long

' Timing Variables
dim FrameRate as number

'-------- window spezielles

Dim hWnd As Dword

'---Creates OpenGL window and returns handle
hWnd = TBGL_CreateWindowex("Lionhearts entity with pyramid - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED )
'---Shows TBGL window
TBGL_ShowWindow

' -- First we will create world as place to contain entities
%MY_WORLD = 1
tbgl_SceneCreate(%MY_WORLD)

' -- Our world will have two entities
%ENT_CAMERA = 1
%ENT_GRIDLIST = 2

' .. Camera
tbgl_EntityCreateCamera( %MY_WORLD, %ENT_CAMERA)
tbgl_EntitySetPos ( %MY_WORLD, %ENT_CAMERA, 0.0, 1.7, 0.0 )

' .. Grid
tbgl_EntityCreateDLSlot( %MY_WORLD, %ENT_GRIDLIST, 0, CreateGridAsDList() )


'---Resets key status before checking
TBGL_ResetKeyState()

'---Main script loop
WHILE TBGL_IsWindow(hWnd)

'---Script will run on different PCs so we must assure
'---constant speed of movement by scaling movements relative to frame rate
FrameRate = TBGL_getFrameRate

'---Prepares clear frame
TBGL_ClearFrame

tbgl_SceneRender(%MY_WORLD)

TBGL_DrawFrame ' Swaps the buffers - displays rendered image

if TBGL_GetwindowKeyState( hWnd, %VK_UP) then tbgl_EntityPush(%MY_WORLD, %ENT_CAMERA, 0, 0, 5/FrameRate) ' 5 meters/second
if TBGL_GetwindowKeyState( hWnd, %VK_DOWN) then tbgl_EntityPush(%MY_WORLD, %ENT_CAMERA, 0, 0, -5/FrameRate)

if TBGL_GetwindowKeyState( hWnd, %VK_PGUP) then tbgl_EntityPush(%MY_WORLD, %ENT_CAMERA, 0, 5/FrameRate, 0 )
if TBGL_GetwindowKeyState( hWnd, %VK_PGDN) then tbgl_EntityPush(%MY_WORLD, %ENT_CAMERA, 0, -5/FrameRate, 0 )

if TBGL_GetwindowKeyState( hWnd, %VK_LEFT) then tbgl_EntityTurn(%MY_WORLD, %ENT_CAMERA, 0, 60/FrameRate, 0)
if TBGL_GetwindowKeyState( hWnd, %VK_RIGHT) then tbgl_EntityTurn(%MY_WORLD, %ENT_CAMERA, 0, -60/FrameRate, 0) ' 60°/second

if TBGL_GetwindowKeyState( hWnd, %VK_ESCAPE) then EXIT WHILE

WEND

'---Closes OpenGL window
TBGL_DestroyWindow

function CreateGridAsDList() as long ' Returns to which display list we save
local i, j as long

tbgl_NewList 1
'---Let's build a grid
TBGL_BeginPoly %GL_LINES ' Starts polygon definition based on 2 vertex lines
TBGL_Color 0,200,0 ' Defines color

For i = -20 To 20
For j = -20 To 20
TBGL_Vertex -20, 0, j ' Adds vertex
TBGL_Vertex 20, 0, j ' Adds vertex

TBGL_Vertex i, 0, -20 ' Adds vertex
TBGL_Vertex i, 0, 20 ' Adds vertex

Next
Next

TBGL_EndPoly
tbgl_EndList

function = 1

'------- end sub

'-------------------------------- pyramide einbauen :-)

' Main Programme Loop starts here
while tbgl_iswindow(hWnd)
FrameRate = tbgl_GetFrameRate
tbgl_clearframe ' Clear Screen
tbgl_resetmatrix ' Reset the Current Matrix
tbgl_camera 0, 0, 1, 0, 0, 0 ' Default Camera Position

tbgl_translate 0, 0, -4 ' Move Pyramid to Centre of Screen
tbgl_rotate angle, 0.0, 0.5, 0.0 ' Rotation Setup

drawPyramid()

tbgl_drawframe ' Swap the Drawing Buffers

angle += 180.0/FrameRate

if tbgl_getasynckeystate(%VK_ESCAPE) then exit while

wend

sub drawPyramid()

tbgl_beginpoly %GL_TRIANGLE_FAN
tbgl_color 0, 128, 255 : tbgl_vertex 0.0, 1.0, 0.0
tbgl_color 255, 0, 0 : tbgl_vertex -1.0, -1.0, 1.0
tbgl_color 255, 255, 255 : tbgl_vertex 1.0, -1.0, 1.0
tbgl_color 0, 0, 255 : tbgl_vertex 1.0, -1.0, -1.0
tbgl_color 0, 255, 0 : tbgl_vertex -1.0, -1.0, -1.0
tbgl_color 255, 0, 0 : tbgl_vertex -1.0, -1.0, 1.0
tbgl_endpoly

end sub




have a nice day...

and

perhaps I can help you with your open gl online magazine:-))) as a beginner! :-D

ciao und servus, Lionheart

Petr Schreiber
08-09-2008, 14:47
Hi Lionheart,

you were so close!
I attach solution for you.

What was wrong? You forgot END FUNCTION in the grid creation, which caused a bit of mess. You also had 2 rendering loops, which is a bit unusual.

My modification creates display list from your pyramid, for super fast rendering. To rotate the pyramid, I just used TBGL_EntityTurn. You could also use TBGL_EntitySetRot for absolute angle rotation, Turning is cumulative.

If you are in writing mood, I would be happy to see your article. Just beware I am terrible dog - waking you up on midnight with "WHERE IS THE FINISHED ARTICLE !?" is pretty common... :D
I would recommend to wait till Journal #2 is out, as it introduces some changes in coding style, which will make it a bit easier to write demos. Up to you.


Bye and thanks,
Petr

Michael Hartlef
08-09-2008, 14:58
perhaps I can help you with your open gl online magazine:-))) as a beginner! :-D


OpenGL magazine??? I guess I have to visit Petr's website more often. Off to have a look.

Petr Schreiber
08-09-2008, 15:06
I guess LionHeart means Journal? But that is not OpenGL only :)
If I would come with something new, you are the first to know it. You have sure position on my WIP list ;)


Petr

Lionheart008
08-09-2008, 16:22
dear petr, dear michael:-)

yes, I mean the "journal"...

- one more from the open gl road...

to translate the x,y,z coordinates of the triangle.. In what direction I must count the polygon vertex to translate it???


tbgl_color 0, 128, 255 : tbgl_vertex 0.0, 1.0, 0.0
tbgl_color 255, 0, 0 : tbgl_vertex -1.0, -1.0, 1.0
tbgl_color 255, 255, 255 : tbgl_vertex 1.0, -1.0, 1.0
tbgl_color 0, 0, 255 : tbgl_vertex 1.0, -1.0, -1.0
tbgl_color 0, 255, 0 : tbgl_vertex -1.0, -1.0, -1.0
tbgl_color 255, 0, 0 : tbgl_vertex -1.0, -1.0, 1.0

'-second pyramid

tbgl_color 0, 128, 255 : tbgl_vertex 0.0, 1.0, -1.0
tbgl_color 255, 0, 0 : tbgl_vertex -1.0, -1.0, 0.0
tbgl_color 255, 255, 255 : tbgl_vertex 1.0, -1.0, 0.0
tbgl_color 0, 0, 255 : tbgl_vertex 1.0, -1.0, -2.0
tbgl_color 0, 255, 0 : tbgl_vertex -1.0, -1.0, -2.0
tbgl_color 255, 0, 0 : tbgl_vertex -1.0, -1.0, -1.0

I have translated only the z-coordinates (put them "-1" to the first polygon), but there must be a mistake... this pyramid has six sides :-)

=> I thought it may go with matrix functions as "tbgl_Translate x, y, z" too:-)

my input will come for the magazine/journal :-)

see you, thanks and this little example is finished :-D

lionheart

Petr Schreiber
08-09-2008, 16:47
Hi LionHeart,

do we still talk about the scene-entity scheme?
If you want to render two identical pyramids, just one shifted, we can just place the same object ( pyramide display list ) on two places.

I attach new code for you, I just added new entity. The important part is:


' -- Create pyramid geometry - ONCE
CreatePyramidAsList()

' -- Place it in scene ... TWICE under different names
tbgl_EntityCreateDLSlot( %MY_WORLD, %ENT_PYRAMIDLIST1, 0, %LST_PYRAMID )
tbgl_EntitySetPos ( %MY_WORLD, %ENT_PYRAMIDLIST1, 0.0, 0.0, 0.0 )

tbgl_EntityCreateDLSlot( %MY_WORLD, %ENT_PYRAMIDLIST2, 0, %LST_PYRAMID )
tbgl_EntitySetPos ( %MY_WORLD, %ENT_PYRAMIDLIST2, 0.0, 0.0, -2.0 )


Use cursor keys to move around the scene to see they are one behind other.
I made the second pyramid to spin in opposite direction just for fun:


' --Rotate pyramids
TBGL_EntityTurn(%MY_WORLD, %ENT_PYRAMIDLIST1, 0, 90/FrameRate, 0) ' = 90° per second
TBGL_EntityTurn(%MY_WORLD, %ENT_PYRAMIDLIST2, 0,-90/FrameRate, 0) ' =-90° per second


So ... to translate, you do not have to hardcode positions! Just place entity somewhere, and translate it using TBGL_EntitySetPos ( = absolute position ), TBGL_EntityMove ( = shift by specified distance, aligned to global world coordinates) or TBGL_EntityPush ( = shift by specified distance, aligned to local pyramid coordinates ).


Hope it helps,
Petr

UPDATE: I added fork with axes, so you can better control where grows X, Y and Z

P.S. Yes, tbgl_Translate would work too. Scene entity has hand optimized matrix math, so you might get better results.
The translate version could be like following ... but then the 2 pyramids would be handled as one object, which is not very useful in most cases:


TBGL_NewList %LST_PYRAMID
TBGL_PushMatrix
tbgl_beginpoly %GL_TRIANGLE_FAN
tbgl_color 0, 128, 255 : tbgl_vertex 0.0, 1.0, 0.0
tbgl_color 255, 0, 0 : tbgl_vertex -1.0, -1.0, 1.0
tbgl_color 255, 255, 255 : tbgl_vertex 1.0, -1.0, 1.0
tbgl_color 0, 0, 255 : tbgl_vertex 1.0, -1.0, -1.0
tbgl_color 0, 255, 0 : tbgl_vertex -1.0, -1.0, -1.0
tbgl_color 255, 0, 0 : tbgl_vertex -1.0, -1.0, 1.0
tbgl_endpoly

TBGL_Translate 0, 0, -1

tbgl_beginpoly %GL_TRIANGLE_FAN
tbgl_color 0, 128, 255 : tbgl_vertex 0.0, 1.0, 0.0
tbgl_color 255, 0, 0 : tbgl_vertex -1.0, -1.0, 1.0
tbgl_color 255, 255, 255 : tbgl_vertex 1.0, -1.0, 1.0
tbgl_color 0, 0, 255 : tbgl_vertex 1.0, -1.0, -1.0
tbgl_color 0, 255, 0 : tbgl_vertex -1.0, -1.0, -1.0
tbgl_color 255, 0, 0 : tbgl_vertex -1.0, -1.0, 1.0
tbgl_endpoly
TBGL_PopMatrix
TBGL_EndList


The approach with entities as I did it in attached file is a bit better, as we instance one cached geometry on two places while maintaining easy control over each one.

Lionheart008
08-09-2008, 20:06
dear petr, michael and all others...

... so!

it works fine:-) the new example with rotating pyramids and two boxes!!! a little mistake does still exists, but it's not so important, I overlapped both boxes :P

not easy to understand first of all with entity translating the objects, but I think it's comfortabler to translate in this way the points or objects...

GOOD IDEA ;D

I am groggy, sometimes I believe, this is sometimes to much input for me, because it's strange material for me, to learn a new cosmos ;-)

after building this scene I am proud:-) without help or advices nothing will run !

thanks again for pushing my questions into right direction...

ciao and servus, Lionheart

ps: there is a thinbasic (thinair) file ("help file") for ->primitives? I am sure, but nothing found until today...

the next examples will come! :-)))

Petr Schreiber
09-09-2008, 08:35
Hi LionHeart,

nice variation!
If you wish to treat those 4 boxes as one "body", just with some offsets, you can use TBGL_Translate if you wish.
Like this:


FUNCTION CreateBoxAsList() AS LONG

TBGL_NewList %LST_BOX
' -- Push/Pop matrix assures the translation will not affect other primitives
tbgl_PushMatrix
' -- Move 2 units on X axis
TBGL_Translate 2, 0, 0
tbgl_Color 0, 40, 128
tbgl_Box 1,1,1
TBGL_PopMatrix

tbgl_PushMatrix
TBGL_Translate -2, 0, 0
tbgl_Color 155, 0, 0
tbgl_Box 2,1,1
TBGL_PopMatrix

tbgl_PushMatrix
TBGL_Translate 0, 2, 0
tbgl_Color 255, 0, 0
tbgl_Box 1,2,1
TBGL_PopMatrix

tbgl_PushMatrix
TBGL_Translate 0, -2, 0
tbgl_Color 155, 0, 0
tbgl_Box 1,1,2
TBGL_PopMatrix

TBGL_EndList

FUNCTION = %LST_BOX

end FUNCTION


In your original code you left " tbgl_beginpoly %GL_LINES" before rendering boxes, without any "TBGL_EndPoly". This makes driver crazy. I added one safety button to your program. When you press F1, it shows you whether you did something wrong or not.

The attached source code does not produce any OpenGL error, but try to add TBGL_BeginPoly %GL_LINES randomly in code after window creation, and you should see F1 key will tell you there is a problem. If you have localized German drivers, the info will be in German :D.

Regarding "help on primitives" - in ThinAir, click Help / User help / TBGL. If the TBGL item is not there, just browse for Help directory in your thinBasic instalation for ThinBasic_TBGL.CHM help file.


Petr

Lionheart008
09-09-2008, 09:37
hi petr, hi all :-)

thank you for more input... I need such things ::)

a) before you posted here I have done the next little changes with "colors" ;-) I have include a special "sinus" function you know, must laugh :-)

b) I have improved the message box as entry to my open gl example

c) I like the complex structures and different ways to get the objects... I also see the different ways "Nehe" lessons did it the first chapter of his open gl examples ;-)


Regarding "help on primitives" - in ThinAir, click Help / User help / TBGL. If the TBGL item is not there, just browse for Help directory in your thinBasic instalation for ThinBasic_TBGL.CHM help file.

thank you for that one ! :)

d) if I change the camera position the objects the light will change too... I will find the way to make it better...

bye, see you soon here, I hope so to learn more...

best regards, lionheart

... more will come with your new input :-D
... my female dog is waiting for walking..

PS: to move in 3d space is great! - missing only "Strg" + "Cursur" combination
(up, down, left, right) to change the view below the grid or walk through it :-)
but this one I will build at a later moment...

Lionheart008
15-09-2008, 15:22
hi all, dear petr,

just a short question about the new tbgl entity codes...


' -- Create something to look at
TBGL_EntityCreateBox(%sScene, %eBox, 0, 1, 1, 1, 0, 255, 50, 255)
TBGL_EntitySetPos(%sScene, %eBox, 0, 0, 0)

a) this is a new code form to include new boxes or pyramids or something else???
b) I have done some minutes before a new little example with boxes, changed the view size and the buttons and the colors of the boxes...

best regards, lionheart

ps: the description for a simple "tbgl example tutorial" will come this week... ;)

Petr Schreiber
15-09-2008, 15:46
Hi,

thanks for the example :)

The Scene-Entity approach is something very basic.

You just create Scene, which is nothing but container for entities.
Entity is object, part of the scene. Entity can be:

Camera
Light ( point, directional, spotlight )
Geometric primitive ( box, cylinder, sphere, torus )
Display list reference ( any static geometry )
Model reference ( any static, but especially dynamic geometry )
Pivot ( invisible reference point )


As pyramid is not handled as general purpose geometric primitive, it should be cached using display list.


TBGL_NewList 1
' -- Code to render pyramid
TBGL_EndList

What the example does, is that it passes graphic code between TBGL_NewList / TBGL_EndList to graphic card "cache" under reference number 1, so you then reference whole object ( even if defined by thousand lines of code ) by single number.
That means - instead of sending the same pyramid each frame of animation to graphic card, you just define it once.

To bind display list as entity to scene, you can use:


TBGL_EntityCreateDLSlot( <sceneID>, <entityNameEquate>, <parentEntityNameEquate>, <displayListID> )


So with entity based approach you just define scene "graph" before actual rendering, and then render all using one line of code - TBGL_SceneRender. If you want some entity to move or something, you just call appropriate command and next TBGL_SceneRender call will render the updated scene.

The advantages of Scene-Entity approach are:

Hi speed ( all transformations done internaly, no need to bother thinBasic with parsing lines )
Possibility to construct entity relationships ( for example attach camera to helicopter model )
Unified way to handle lights, cameras and geometry; referenced by equates
Some high level functionalities like getting distance from object to object, make objects look at other object...


Hope it is more clear now, I will try to write more articles on this in near future.


Petr

Lionheart008
15-09-2008, 18:33
dear petr, hi all :)

@petr: first of all: thanks for your promptly answer, I will use this information about the powerfull "entity" for the further exercises I will create ;-) good to know that! ...

@all: - what do you think about computerbooks like "3d programming" for games? Can you or another guy/woman advice to this kind of windows programming? I have found last week a book from "David Scherfgen: 3d-Spieleprogrammierung" and think about it to buy such a "big hammer" of higher level knowledge...

perhaps anybody has read this book or even use it for daily work... ?

best regards, freezing lionheart ;-)

Petr Schreiber
15-09-2008, 19:25
Hi LionHeart,

for 3D study I can recommend following books:

OpenGL redbook (http://www.glprogramming.com/red/) - the basics of OpenGL, there is printed version for OpenGL 2.1 available as well
GPU Gems (http://http.developer.nvidia.com/GPUGems/gpugems_part01.html) - real gem, but covers advanced topics
GPU Gems 2 (http://http.developer.nvidia.com/GPUGems2/gpugems2_frontmatter.html) - real gem number two :), but covers advanced topics


I have book at home, called "Moderní počítačová grafika", it would translate as "Modern Computer Graphics". It is very good overview, but not sure if available in other than Czech language :(

So I recommend to take a look at Red Book above first, it explains the real minimum, but with focus on OpenGL.


Petr

P.S. I am freezing as well, what happened to the nice weather, it even rains!

matthew
15-09-2008, 19:57
Version 1.0 of the OpenGL Redbook & Bluebook are freely available in the PDF format.

You can download them from the following links, Redbook (http://bmatthew1.pwp.blueyonder.co.uk/books/redbook.pdf) & Bluebook (http://bmatthew1.pwp.blueyonder.co.uk/books/bluebook.pdf).

Petr Schreiber
15-09-2008, 19:59
Thanks Matthew,

much better than HTML :)


Petr

Lionheart008
15-09-2008, 22:41
hi matthew, hi petr, hi all...

thanks for this new open gl pdf infos :-) great !

- the next life I will live, I need "two brains" to read all things I like and the other one can relax or do something else how to learn to use all the informations or switch off the lights if these things in daily life become too much ::)

- Open GL is exciting stuff, but I will use it (prefer) for an adventure, educational or strategy game, I don't like the "one shooter games"...

ciao und servus, Lionheart (still freezing)

Lionheart008
15-09-2008, 23:21
last input for today:-)

the new sphere has no fun to include in my pyramid example ;-)

a) I have got this error message... add the picture above...

b) perhaps I have to delete some lines or the function code lines are my mistake... ???

perhaps somebody can look at this script, would be very nice...

I think I am very close to the right lines :D

ciao, lionheart

ps: may be my mind is too tired (too cold) to find this simple mistake...

Lionheart008
16-09-2008, 01:23
;D "my next five cents for the last day"

a) sorry, I have only forgotten one important code line with the function box ... :)

b) two spheres run and are rotating through the scene, everything included as fine as I wished !!! "go for gold", must laugh!

c) good night... but proud to made it, the damned little mistakes make me laugh... ;)

ciao, ice lionheart

! ps: When I am starting this example new again, the position of the spheres are changing every time, why? :)

Petr Schreiber
16-09-2008, 10:13
Hi LionHeart,

congratulations on bug hunt and nice script!

The answer to your question "the position of the spheres are changing every time, why?" awaits you in the CreateSphereAsList procedure. You create sphere rotated using:


tbgl_Rotate GetTickCount/10, 0, 0, 1


... so the rotation is dependant on time you run the script, as GetTickCount returns number of milliseconds since midnight :)
Your game plans sound very interesting too.


Thanks,
Petr

Michael Hartlef
16-09-2008, 10:17
@all: - what do you think about computerbooks like "3d programming" for games? Can you or another guy/woman advice to this kind of windows programming? I have found last week a book from "David Scherfgen: 3d-Spieleprogrammierung" and think about it to buy such a "big hammer" of higher level knowledge...



Hi Lionheart008.

Like I said before, don't get that book. It's about DirectX and fully C++. I have it, and it is a good book. It teaches you to create your own game engine and games with it. But it's for DirectX and so will not serve you well when it comes to OPENGL. I would recomment also these books, I don't have them but they get good critics.

http://glbook.gamedev.net/

Lionheart008
16-09-2008, 12:56
;D

hi all !

(must laugh!)
yes, I am proud of it! Now a little bit "action" with a rotating torus around the scene, built in the script ...


so the rotation is dependant on time you run the script, as GetTickCount returns number of milliseconds since midnight

- thank you petr for your comment about "gettickcount" :)

=> THINBASIC is GREAT! - That's what making fun ! :D

@ michael...
;) bad infos for you (no, no, for ME!)... I have bought this strange programming book (ca. 40 Euro) today... MIST! - But perhaps I can use it some days, although it's fully information about direct x and c++... !!!


http://glbook.gamedev.net/
thanks! Your advice with "open gl books" are very good! I will better save my money for this books! ;)

have a nice day... see you soon here...

best regards, 'run to the sun', lionhearts

Petr Schreiber
16-09-2008, 14:51
Hi LionHeart,

you can save some money by signing to your local library.
I pay about 7 euro per year here, and have access to lot of technical books without bankrupting me :)

The script is nice, it starts looking like some planetarium or machine from horror movies.


Petr

Lionheart008
16-09-2008, 19:30
dear petr, michael, hi all...

little question to a function... does this one exists in "tbgl"? I must "animate" the points with a new tbgl command line??? - no idea, puh!

a) "movedPoints()" and b) "tbglPointSize"?


tbglColor3f 1.0,1.0,0.0
tbglPointSize(6)

MovedPoints()
tbglColor3f 1.0,0.0,0.0
tbglTranslate 1, -0.5, 0

I have found it in a book... ;-)

second: my planetarium for the monsters will growing up :-)
points or other things should fly through the entity space... I will make it with my own forces, but I have only this question with the MovedPoints and PointSize...

I didn't found any example for it, unfortunately...

:) thanks for the humour, I like such things ;)

ciao, lionhearts

Petr Schreiber
16-09-2008, 19:42
Hi,

your code would be:


tbgl_Color 255, 255, 0 ' -- Yellow
tbgl_PointSize 6

MovedPoints() ' -- No idea what this function does :D

tbgl_Color 255, 0, 0 ' -- Red
tbgl_Translate 1, -0.5, 0


So biggest problem for me is the mysterious MovedPoints() :)

To create points in TBGL you can use:


TBGL_BeginPoly %GL_POINTS
TBGL_Vertex 1,1,1 ' -- First point
TBGL_Vertex 3,2,2 ' -- Second point
TBGL_EndPoly


... so it is similar as you created your pyramid. You can again encapsulate point geometry in display list, create DLSlot entity and move it using TBGL_EntitySetPos for example.

Hope it helps :),
Petr

Lionheart008
16-09-2008, 19:55
hi petr...

o.k. I forgot the "moved points()"...


So biggest problem for me is the mysterious MovedPoints()
same to me... I wasn't sure if such a thing does exist, therefore I have asked...

yes, the other things I can built as usual :-) thank you, but I ask before I run with my head against a wall :o and become an error message king of the day ! :D

best regards, LionHeart

Petr Schreiber
16-09-2008, 19:58
Just one thing,

I am sure MovedPoints() is user defined function.


Petr

Lionheart008
16-09-2008, 22:29
hi petr, hi all ! :D

my last example with some moving points for this evening :)

not really great things, but I have tried it... wasn't so hard...

finally I wanted to rotate and make a tick to the torus (a torus in a smaller torus rotate with speed), but doesn't manage it...

tbgl_Rotate GetTickCount/16, 0, 0, 1
tbgl_Rotate 90, 1,0,0
tbgl_Color 200,200,255
tbgl_Torus 0.25, 1.0

I will try it tomorrow again...

good night, best regards, run to the Moon ;)

lionheart

ps: forgotten to mention... my mind isn't no longer active ;)

Petr Schreiber
16-09-2008, 22:51
Hi LionHeart :),

the problem is that you use display list to cache multiple toruses. As I said earlier, display list makes static "snapshot" of the scene between TBGL_NewList / TBGL_EndList. So even if you put rotation dependant on time in display list, it will rotate according to time list was created but no more.

Solutions?

Solution A: Create 2 display lists, one for inner torus, second for big torus and rotate the inner torus using TBGL_EntitySetRot

Solution B: Create torus as entity directly and use TBGL_EntitySetRot to rotate it.

I attach short example of second approach for you :)


Petr

ErosOlmi
16-09-2008, 22:57
Petr,

error in script: %eBox entity does not exists when using left/right keys.

Petr Schreiber
16-09-2008, 23:02
:-[

It is corrected now, I am sorry.


Petr

Lionheart008
16-09-2008, 23:24
:D thank you a lot petr and eros...

... I have built a second torus with two torus in it ;-) May be I have understood this example. But it's not easy to learn another way to control "entity"... with objects, lights, camera position and so on... I can imagine it's easier to handle with it ...

- tomorrow morning I arrange correctly my last pyramid example with the torus objects... now it's too late ... for me...

- I have had a strange error code message too some minutes before... by the way...

- good NIGHT!!! qt: don't you need sleep ? ;-) some aliens among us? must laugh... but my girl friend she's beating at me... ! :o

;D Lionheart in bed

Petr Schreiber
17-09-2008, 00:02
Hi,

yes, we are aliens, any other questions? ;D

The error you have seen is that there was code to handle arrow keys with not existing entity, probably relic from my originally posted ( wrong ) example.

Here comes the fix :)

One thing - you were calling TBGL_SceneRender twice, that is not necessary. You just define entities, arrange them, but call TBGL_SceneRender once.


Good night,
Petr

Lionheart008
17-09-2008, 05:41
:D Hi petr, hi dear aliens on planet earth,
hi all...

- checked your torus script and modified it a little some minutes ago...

- so far I have caught it in my mind... and yes, it's better to handle with entities structures.. I can see it in this example, but takes a while to get this overview... and I like such little example to learn with it... to understand thinBasic and TBGL

- I am going back to bed, made a coffee for my girl friend, she must work ! :)

- not so warm outside... brrr...

btw: We are all working for the 'men in black' team, isn't it? ;)

run to the sun, good morning, greetings, lionheart in bed again ;D

Michael Hartlef
17-09-2008, 07:06
Hi Leionheart008,

with that MovePoints function... did you ment a TBGL command to modify the positions of existing vertices ?

Michael

Lionheart008
17-09-2008, 10:19
Hi Michael...

belongs to a 'user called function' petr has mentioned, I am sure now...


DECLARE SUB Coordinatesystem(was AS STRING, TxtPara AS STRING, Para1 AS SINGLE, Para2 AS SINGLE, Para3 AS SINGLE)
DECLARE SUB Object1()
...
DECLARE SUB camera()
DECLARE SUB MovedPoints()

I have found this some days before and thought I can move by a certain function the points in a directly way by mouse or kick them with speed ;-)


did you ment a TBGL command to modify the positions of existing vertices?

If you know such a command for TBGL, oh yes! You are welcome to show me :)

...

SUB MovedPoints()
STATIC AS SINGLE Page, Height, Width
Page=Page + 0.01
IF Page > 2 THEN Page = -2
glTranslate Seite, 0, -6
Object1()
END SUB


... and so on...

- it was a good open gl example of an basic language I have found it with "google" ;-)

but I have deleted it yesterday evening! Hmh...

have a nice day, see you here, best regards, Lionheart


ps: my dog is waiting for me for walking... the sun is shining... good intro for a wednesday :D

Petr Schreiber
17-09-2008, 11:07
Hi :),

the mentioned code could be translated as:


SUB MovedPoints()
STATIC AS SINGLE Page, Height, Width
Page=Page + 0.01
IF Page > 2 THEN Page = -2
glTranslate Seite, 0, -6
Object1()
END SUB




SUB MovedPoints()
STATIC Page, Height, Width AS SINGLE
Page += 0.01
IF Page > 2 THEN Page = -2

TBGL_Translate Seite, 0, -6
Object1()
END SUB


... for classic, OpenGL like coding.

For entities you can create your points as display list, and insert to scene, then use entity positional commands.
Of course, if you wish, you can use TBGL_Translate when creating that display list.

I attach mod of your code for you.


Petr

Lionheart008
17-09-2008, 13:47
Hi all:-)

hi michael, hi petr, thanks for your "pointsize" modification, I have checked it and like it! :) in this way my 'horror planetarium' can be realize some day... ::)

must laugh...

btw: the "little points" became in the tbgl view to little quader form, isn't it? similar example I have tried yesterday and thought it might be a display (graphic driver) problem... but as I see, your example build this very nice quader too ;)

more will come later, I am sure...

caio, freezing Lionheart (don't want to switch the central heating on) ! :D

Lionheart008
17-09-2008, 14:13
hi all, petr again...

- now a short further example, little fun with a 'dancing torus'... ;D

- enjoy it... this torus example would be good for a learning tool with entities...

as usual my little question for 'PointSize':

first you choose "pointsize 5"
end of the script "pointsize 1"
why? ;)


TBGL_NewList %lMyPoints
TBGL_PointSize 5
TBGL_UseLighting %FALSE

TBGL_BeginPoly %GL_POINTS
TBGL_Color 255, 0, 0
TBGL_Vertex 2, 0, 0

TBGL_Color 0, 255, 0
TBGL_Vertex -2, 0, 0

TBGL_Color 0, 0, 255
TBGL_Vertex 0, 0, 2

TBGL_Color 255, 255, 0
TBGL_Vertex 0, 0, -2

TBGL_Color 255, 255, 0
TBGL_Vertex 1, 1, -1

TBGL_ENDPOLY

TBGL_UseLighting %TRUE
TBGL_PointSize 1

TBGL_EndList

see you...

ciao, lionheart

Petr Schreiber
17-09-2008, 14:23
Hi LionHeart,

thanks for new example :)
Quad look of points is given by OpenGL specification.

As OpenGL works as state machine, when you set something ( point size 5 ), it stays at its value until changed. So just for cleaner code I put the point size back to default 1.


Petr

P.S. Good! Resist! Central heating must be switched off as I have it here :D

Lionheart008
18-09-2008, 22:19
hi petr, michael, the rest of engaged tbgl friends :)

a) more will come to another time... delete my last post, black hole in my head, sorry... :D

b) therefore another good thing for beginner...

- changed a little one nehe 3 lesson...
- translated pyramid and quad, camera position...
- new message box about this script example
- window size

bye, lionheart "luke" skywalker

Petr Schreiber
19-09-2008, 13:48
Thanks for new sample :),

worked well for me.


Petr

Lionheart008
20-09-2008, 19:26
dear petr, hi all:)

qt: "letter animation" (A, B, C, d, e, f...z) I have a new idea, kicked from the torus example:)

a) it's possible to create such thing with tbgl command
"%eLetter(A)

b) or it's necessary to build every letter as a "tbgl_Lines" construct???

like the well known script...


TBGL_EntityCreateTorus(%sScene, %eTorus1, 0, 0.1, 1)
TBGL_EntitySetPos(%sScene, %eTorus1, 0, 0, 0)
TBGL_EntitySetColor(%sScene, %eTorus1, 128, 0, 0)


I can imagine I have to animate every letter (if possible) separately...

ciao, I am curious, because I would very like to build a new script with animated letters;)

best regards, Lionheart

Michael Clease
20-09-2008, 19:34
You could build your font using display lists and then call them with the entity system, thats what I would do.

Lionheart008
20-09-2008, 19:41
thanks :) mike... good idea... fonts can be the right way...

I have to check the examples from the thinbasic scriptfolders... tbgl... I know them not all...

I try it;) push it to hear, if I have created a new example...

Ciao and good evening, weekend and night... visit now a music concert :D

good luck for your projects, bye, Lionheart

Petr Schreiber
20-09-2008, 19:54
Hi,

hope you will enjoy the concert!
You can do it as Abraxas suggested, or use TBGL functions to create font:

TBGL_BuildFont - to use any font installed on your system
TBGL_LoadFont - to use font defined in bitmap ( to create it use TBGL Font Creator (http://community.thinbasic.com/index.php?topic=1024.msg6811#msg6811) )


But those are useful only for "normal" use, when they always face camera.


Bye,
Petr

Lionheart008
22-09-2008, 10:09
first of all: thanks for help and infos, dear mike and petr...
hi all:)

here it comes my little "3 cent" example with the tbgl fonts, it wasn't so hard... but I like to move / animate it... that will be the next task...

"thinbasic is really great stuff" ;D

cheerio, best regards, Lionheart

Petr Schreiber
22-09-2008, 19:35
Thanks for new example,

I am happy you are happy with TBGL now :)


Petr