View Full Version : lionhearts beginner open gl lesson 1a
Lionheart008
09-09-2008, 14:13
::)
Dear thinbasic, thinair friends, they are working as a 'beginner' with thinbasic and open gl ("TBGL"), will give here in this little column new informations...
=> I will write simple examples, change existing examples or create new ones...
=> First lesson: you can build two polygons (with three vertex) one of them with a floating color and a new little rectangle (box) with floating color... :)
important is the vertex position (x,y,z) and the color input (description follows)...
=> I will try to explain it with easy words, because I am a newbie here too and have had only some less information about "open gl" themes, but I like it very much and it's amazing stuff, if you can imagine, you can build 3d scenes for games or teaching lessons :-)
bye, the first input is done, I will try to make in a regularly way progress with my examples to show it here and every help or comment is welcome... :-)
Infos: here comes my "first lesson" I have built after an existing example by petr schreiber 1) www.http://psch.thinbasic.com/tutorials_basic_intro.html and a
2) "nehe" lesson (good examples for beginner and advanced users) http://nehe.gamedev.net/
and
3) massive input into open gl themes of course for example here: a) www.opengl.org and here: b) http://de.wikipedia.org/wiki/OpenGL and here
c) http://developer.nvidia.com/object/nvidia_opengl_specs.html
4) for basic and further inputs about "thinbasic": http://en.wikipedia.org/wiki/ThinBasic.
----------
best wishes, good ideas and see you here,
lionheart :-D, the description for the first lesson with colors will follow the next time
;D have fun with it
Petr Schreiber
09-09-2008, 14:48
Hi LionHead,
very nice lesson, thanks a lot!
Just two little details:
It is preffered to use TBGL_ResetKeyState(), TBGL_GetAsyncKeyState(-1) does the same, but it is esoteric. Mea culpa, TBGL website did not contained this information, I updated it now.
When rendering TBGL_Box, you do not need to use TBGL_BeginPoly / TBGL_EndPoly. Only TBGL_Color, TBGL_ColorAlpha, TBGL_TexCoord2D, TBGL_Normal,TBGL_Vertex are allowed between TBGL_BeginPoly / TBGL_EndPoly, as help file explains
I attach tuned version.
Thanks,
Petr
Lionheart008
10-09-2008, 20:53
:)
=> theme: "box beginner open gl lesson 1b"
hello again dear thinBasic friends !
part two: here it comes... now a little open gl "box" example with colors, translating the position of boxes and a new "close" window by the new "thinBasic" 1.7.0.0 version :-) GOOOD! :-D
this little example is just a first example how to translate (later rotate) primitives, here a box object... - I have to improve it in some direction, but this chapter is long ! ;-)
more will come... ::)
bye and servus, lionheart
Lionheart008
11-09-2008, 14:40
hello thinBasic TBGL friends ;-)
I have modified with a new cube my last beginner open gl lesson 1b
-- perhaps somebody can help or I can wait until petr will come back :-)
qt 1): I have added a new little box (blue color) below the other ones...
=> This "box" had "bad" edges...(unsharp edges).. why? May be a rendering problem or it depends on the camera position?
qt 2): If I want to translate the object to another place and rotate it, I must do it for every object or it's possible to include it the push-popMatrix as one loop? ??? this problem I have today, nothing else...
best regards, nice day without our "heroes" ::)
lionheart :D
ps: sorry, forgotten the attachement...
Michael Hartlef
11-09-2008, 15:14
best regards, nice day without our "heroes" ::)
Now that is very motivating for the rest of us. :-\
Michael Hartlef
11-09-2008, 15:32
qt 1): I have added a new little box (blue color) below the other ones...
=> This "box" had "bad" edges...(unsharp edges).. why? May be a rendering problem or it depends on the camera position?
Ok, you used TBGL-BOX, which creates a 3D box. With the first one you created, there was only one side visible for you. So this way you thought, that you created a rectangle. But as you created a box , once you move it out of the center from the camera view, you will see some other sides too. With the use of TBGL_POLYGONLOOK you can see that yourself.
'-------- build a 2. box
TBGL_PolygonLook %GL_LINE
TBGL_COLOR 0, 0, 255+sin(Timer)*127
tbgl_Box 0.5, 1.0, 4.0
TBGL_PolygonLook %GL_FILL
Maybe it is better to use just a 4side polygon.
qt 2): If I want to translate the object to another place and rotate it, I must do it for every object or it's possible to include it the push-popMatrix as one loop?
Yes, or you take the current matrix postion/rotation into count yourself. In my oppinion that would be crazy. The Push/Pop matrix commands help you to retrieve clear matrix transformations for the next transform/rotate operation.
But you don't need to do this, if you start using entities in TBGL, there you handle objects. And there TBGL takes care of the transformations during the rendering.
Michael Hartlef
11-09-2008, 15:33
.
Lionheart008
11-09-2008, 16:01
dear michael... good idea ;-)
a) I have tried it with your advice polygon look GL_Line and GL_QUADS, but nothing has changed with the both edges of the quad (up right, up left)... ;-( it looks like the edges are cut off ...
b) perhaps I will try the next example with a 4 side polygon ! :D
c) sorry, about the word "heroes".. it was for me a "nice" (friendly) word to all the people here they are full of inspiration, skill and positively help behaviour (you too! :-)))...
I didn't want to 'demotivate' you, sorry again... :o
thank you for help... ! :-) more open gl examples will come...
lionheart
Lionheart008
11-09-2008, 17:14
hello again... my 5 cent for today ::)
... this new 'rotating box example' does function very well :-)
I have load a new file (with 3d Entity, an skeleton open GL example with one white box) and have included three new boxes... two boxes turning round the basic cubes, so I can imagine some day a little planet will cruising around the sun ::)
;D
- what I have done?
a) changed the colors of the boxes
b) changed the rotating speed
c) changed the translation points
that's all for today...
I am satisfied again... this example runs, but the old problem (above) stay here with the bad edges (must laugh!).. I will fetch it, I am sure...
have a nice day, ciao und servus, lionheart
Michael Hartlef
11-09-2008, 19:38
??? Bad edges? Do you mean the edges(Kanten) or corners (Ecken). Do you mean that the edges are drawn unsharp? If that is what you ment, then it caused by antialiasing of your videocard. The "missing corners" are not really missing. Itis the perspective after you rotated the box. To look at as a wireframed box and not a filled model, I want to point that part to you.
Maybe PM me in german, so I can understand better what you mean.
Michael Hartlef
11-09-2008, 19:48
dear michael... good idea ;-)
a) I have tried it with your advice polygon look GL_Line and GL_QUADS, but nothing has changed with the both edges of the quad (up right, up left)... ;-( it looks like the edges are cut off ...
Nothing changend? Here is the code and a picture. The corners are not cut, you just look slightly from above to a 3D box.
'
' Lesson #2 from thinBASIC TBGL tutorials
' "Colors"
'
' by Petr Schreiber
' Updated to new syntax on 10-04-2008
' modified by Frank Brübach (Lionheart), since 09-11.09.2008
Uses "TBGL"
DIM hWnd AS DWORD
MsgBox (0, "Hello, dear thinbasic friends, \nYou should see four colorful objects soon, \ntake time and look at the picture with color changing"+$CRLF(2)+"Press ESCAPE to quit window", %MB_ICONINFORMATION, "Lionhearts Lesson 1b")
' We will initialize OpenGL and internal buffers
' Function also returns window handle
hWnd = tbgl_CreateWindowEx( "Lionhearts OGL 'beginner' Lesson 1b - press ESC to quit the example", 640, 480, 32, %TBGL_WS_WINDOWED)
tbgl_ShowWindow ' This will display the window on the screen
tbgl_BackColor 0, 0, 125 ' Let's set the default background to darkblue - just one call needed !
TBGL_RESETKEYSTATE() ' Reset status of the all keys to prevent immediate quit
while TBGL_iswindow(hWnd) ' While window exists, we will draw and check for ESCAPE
tbgl_ClearFrame ' This clears the frame and prepares it for drawing
tbgl_Camera 0,0,5,0,0,0 ' We will look from point 0,0,5 to 0,0,0 ( origin of coordinates )
tbgl_BeginPoly %GL_TRIANGLES' Here begins definition of traditional triangle polygon
tbgl_Color 128+sin(Timer)*127, 0, 0 ' Pulsing Black-To-Red
tbgl_Vertex -1.5,0,0
tbgl_Color 0, 128+sin(Timer+1)*127, 0 ' Pulsing Black-To-Green
tbgl_Vertex 1.5,0,0
tbgl_Color 0, 0, 128+sin(Timer+2)*127 ' Pulsing Black-To-Blue
tbgl_Vertex 0,1.5,0
' Second polygon
TBGL_COLOR 255, 0, 0
TBGL_VERTEX -3, -1, -1 '----x, y, z coordinates for one point!
TBGL_COLOR 0, 255, 0
TBGL_VERTEX 3, -1, -1
TBGL_COLOR 0, 0, 255
TBGL_VERTEX 2, 1, -1
TBGL_ENDPOLY
'-------- build a new box
TBGL_COLOR 125+sin(Timer)*127, 60, 255
tbgl_Box 0.5, 1.0, 4.0
tbgl_PushMatrix
tbgl_Translate 0.25, -1.5, -1 '-- tbgl_Rotate 45, 1,0,0
TBGL_PolygonLook %GL_LINE
'-------- build a 2. box
TBGL_COLOR 255, 255, 255
tbgl_Box 2.25, 0.45, 0.40
TBGL_PolygonLook %GL_FILL
tbgl_PopMatrix
tbgl_DrawFrame ' This will display the scene
' When ESCAPE is pressed, we will leave the main loop
IF TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE ) THEN EXIT while
Wend
tbgl_DestroyWindow ' This will destroy the window
Lionheart008
11-09-2008, 20:03
SUPER ! :-) I have only change the viewpoint of the camera... You are right!
;D
I had just headache because of this little view problem... :o In german language you would say "Tomaten auf den Augen!"... it's only a view angle problem that get me such silly trouble... the code was ok... but the 'devil lives in so many details'...
I am glad, I haven't a graphic driver problem...
one big "icecream pot" for you.. or a "erdinger weizen" ? ;-)
by the way:
'-------- build a 2. box
TBGL_PolygonLook %GL_LINES '-- QUADS
TBGL_COLOR 0, 0, 255+sin(Timer)*127
tbgl_Box 2.25, 0.45, 0.4
TBGL_PolygonLook %GL_FILL
=> the code of the box object does function with "GL_LINES" and "GL_QUADS", not so bad... ;-) "GL_FILL" and "PolygonLook" I didn't know yet, very good! :D
see you, best regards, Lionheart
ps: I have added this picture and have expand the box with another color... I see it's everything fine :-)
- "beer will come by post or live in "biergarten" meeting"
Michael Hartlef
11-09-2008, 20:09
one big "icecream pot" for you.. or a "erdinger weizen" ? ;-)
by the way:
'-------- build a 2. box
TBGL_PolygonLook %GL_LINES '-- QUADS
TBGL_COLOR 0, 0, 255+sin(Timer)*127
tbgl_Box 2.25, 0.45, 0.4
TBGL_PolygonLook %GL_FILL
=> the code of the box object does function with "GL_LINES" and "GL_QUADS", not so bad... ;-) "GL_FILL" I didn't know yet, very good! :D
see you, best regards, Lionheart
I'm glad everything is fine now. I take both, first teh icecream and then the beer. :)
Lionheart008
12-09-2008, 01:15
dear all :-)
special for michael ;-)
I'm glad everything is fine now. I take both, first the icecream and then the beer. Smiley
so have fun with it :-) I invite you for a fixed day in spring next year, if the summer is gone. I will send beer and icecream via post and the beer in bottles by helicopter... smile
=> last little input for my rotating box example with colors:
- a) create a little pulsing of the box after some seconds between two colors...
- b) one more rotating box with another speed...
o.k., that's enough for today (this night, sorry),
good sleep all :-)
servus and bye, Lionheart
Lionheart, very happy to see you getting into the 3d aspect of thinBasic too. I am sure you will grow to love it as tbgl has really made massive improvements this year, especially with the entity system in place.
Petr has many examples in the examples folder, the bonuspacks and Matthew made a lot of the nehe tutorials for thinBasic. You have the right idea in going through those and working the way you are. Thanks for sharing your adventure into all of this cool stuff!
Lionheart008
12-09-2008, 09:50
hi dear kent :-)
you are very welcome! :-D
- yes, I will get knowledge step by step with "open gl" theme and "gui" (UI) examples...
- it's hard to get a seriously overview about thinBasic and thinAir, all the infos here and check examples. It will take a long time to proof everything, but I pick up some examples for me to push my curiousity or learn more about this fascinating script language...
- I have only a little "time problem" (girl friend, dog, I write a criminal detective novel!) and would like to do more, but I love nature, summer, ice cream and my music too (playing keyboard, piano...)
- what's your topic theme here?
best regards, wish a good day for you, Lionheart