PDA

View Full Version : using TBGL_VERTEX



sandyrepope
24-10-2007, 02:01
I've been trying to learn to use the tbgl module and am unclear on something. When using the command tbgl_vertex it takes three parameters, x, y, and z. What I'm unclear about is what these numbers are. Are they offsets from some point in the window?

Thanks
Sandy

matthew
24-10-2007, 02:47
The numbers you see in the parameters for TBGL_Vertex are just units of measurement.

The first number is its horizontal size, the second is its vertical size and the third is used for depth.

I've included a simple script which draws a square on the screen, try messing about with the parameters and see what happens.

Also if you haven't already, I suggest you download a copy of the OpenGL Redbook (http://www.4shared.com/file/7630450/5c8c4fd/redbook.html).

That might answer some of your questions. :)



' TBGL_Vertex Script

uses "TBGL" ' thinBASIC OpenGL Library

dim hWnd as dword
hWnd = tbgl_createwindowex("Press 'Esc' to Quit", 640, 480, 16, 0)

tbgl_showwindow ' Show Display

TBGL_GetAsyncKeyState(-1) ' Reset all Keys

' Start Main Loop
while tbgl_iswindow(hWnd)

tbgl_clearframe ' Clear Display
tbgl_camera 0,0,1,0,0,0 ' Default Camera Placement

tbgl_translate 0.0, 0.0, -6.0 ' Place in Screen by 6 Units

TBGL_BeginPoly %GL_QUADS ' Drawing using Quads
TBGL_Vertex -1.0, 1.0, 0.0
TBGL_Vertex 1.0, 1.0, 0.0
TBGL_Vertex 1.0, -1.0, 0.0
TBGL_Vertex -1.0, -1.0, 0.0
TBGL_EndPoly

tbgl_drawframe ' Display anything

if tbgl_getasynckeystate(%VK_ESCAPE) then exit while

wend

tbgl_destroywindow ' Closes Display

sandyrepope
24-10-2007, 03:19
Also if you haven't already, I suggest you download a copy of the OpenGL Redbook.

I've downloaded the book and will begin reading it as soon as I go offline. Thanks for letting me know about it and the link, Matthew. I didn't know about this one.

Thanks
Sandy

matthew
24-10-2007, 04:46
My first description of what a Vertex is, wasn't as accurate as it could have been. :P

I found this Image in One of my 3D-Graphics books, it shows you that a Vertex is just a point in 3D space and the 3 parameters are it's position in that space.

http://matthew-4gl.wikispaces.com/space/showimage/Vertex_Definition_for_Sandy.png

Petr Schreiber
24-10-2007, 09:47
Hi,

matthew thanks for the help !,
Sandy - new TBGL release is very close and it will come with improved helpfile, covering more explanations.

If you are in default 3D mode, position means location in 3D space. The "world" begins in 0, 0, 0.
I recommend to treat 1 unit as one meter, but it is up to you.


You also might want to visit http://psch.thinbasic.com/ to get extended information about TBGL.

I am very happy you are learning TBGL !


Petr

P.S. If you force tbgl_RenderMatrix2D, then position is considered to be exact pixel position.. In such a case you pass just x, y parameters. This is good for 2D graphics, but useles for anything else. Beauty of OpenGL units ( and generally vector graphics ) is that they are "general", so it does not matter at which resolution you run, the world still looks the same.

sandyrepope
24-10-2007, 16:06
Thanks for the replies everyone. I appreciate it.

I've been thinking about the vertex numbers. There doesn't seem to be any easy way to figure out what the numbers are that I'll need if I want to place several objects on the window. I guess I'll just have to experiment with different numbers until each one is in the position I want it.

Example: If I want several squares lined up in a horizontal row I'd have to create several polygons and just try numbers until each is in position. (This idea could take a while to do but it's the only way I know of to try.)

I'll keep trying things until I get it.

Thanks
Sandy

Petr Schreiber
24-10-2007, 18:13
Hi Sandy,

I am not sure if I get it but ...
Let squares as they are, just move camera to view best from scene.

Do you want to create 2D or 3D scene ?

Here is sample of squares in row (99% matthews code, just little mod):


' TBGL_Vertex Script

uses "TBGL" ' thinBASIC OpenGL Library

dim hWnd as dword
hWnd = tbgl_createwindowex("Press 'Esc' to Quit, PGUP, PGDOWN to change camera distance", 640, 480, 16, 0)
tbgl_showwindow ' Show Display

TBGL_GetAsyncKeyState(-1) ' Reset all Keys

dim i as long
dim CameraDistance as long = 35
' Start Main Loop
while tbgl_iswindow(hWnd)

tbgl_clearframe ' Clear Display

tbgl_camera 0,0,CameraDistance, _ ' Camera point to look FROM
0,0,0 ' Camera point to look TO

for i = 1 to 10

TBGL_BeginPoly %GL_QUADS ' Drawing using Quads
tbgl_Color i*16,255-i*16,0 ' ~Green to red fade
TBGL_Vertex -1.0, 1.0, 0.0
TBGL_Vertex 1.0, 1.0, 0.0
TBGL_Vertex 1.0, -1.0, 0.0
TBGL_Vertex -1.0, -1.0, 0.0
TBGL_EndPoly

' -- Squares are 2 units wide, so we will translate origin
' -- point at end of previous square
tbgl_Translate 2, 0, 0
next

' ** Could be done this way too

' TBGL_BeginPoly %GL_QUADS ' Drawing using Quads
' for i = 1 to 10
' tbgl_Color i*16,255-i*16,0 ' ~Green to red fade
' TBGL_Vertex -1.0+(i*2), 1.0, 0.0
' TBGL_Vertex 1.0+(i*2), 1.0, 0.0
' TBGL_Vertex 1.0+(i*2), -1.0, 0.0
' TBGL_Vertex -1.0+(i*2), -1.0, 0.0
' next
' TBGL_EndPoly

tbgl_drawframe ' Renders scene

if tbgl_getWindowkeystate( hWnd, %VK_ESCAPE) then exit while
if tbgl_getWindowkeyonce( hWnd, %VK_PGUP) then CameraDistance += 1
if tbgl_getWindowkeyonce( hWnd, %VK_PGDN) then CameraDistance -= 1

wend

tbgl_destroywindow ' Closes Display



Bye,
Petr

sandyrepope
25-10-2007, 01:46
Here is something I did in windows paint to show what I've been trying to do. I've been thinking about using 2D since the squares won't be moving. The ships will be traveling horizontally and vertically.

I'm not very good at creating graphics in a paint program yet so, Please, don't expect too much.

Thanks
Sandy

I forgot to say that there will be a border surrounding the field of squares.

kryton9
25-10-2007, 02:01
Sandy this is very exciting that you are taking the plunge into the tbgl module. You will soon grow to love it when you see how nicely Petr setup things for us.

There is a lot to grasp with opengl, but don't let it scare you. There is a lot that goes on to making the graphics appear like they do in the real world. This is with Perspective. In reality, the railroads do not go off into the horizon and end at a point, but we humans see it this way. OpenGL can be setup to view things in perspective, orthographic and in 2D. Orthographic, is how it would be in the real world, but doesn't look correct to us. It is useful for designers as you can get accurate measurements even in 3D views and not distorted as you do with perspective views.

You can also setup parameters to mimic cameras with various fields of view. So there is a lot that can be done just to setup opengl depending on what you want to do.

So basically first decide if you want a perspective view, 2d view or Orthographic view. Then you just build from that. Although this sounds complicated, Petr has made it very easy with the tbgl module to set all of this up.

I would recommend you go through his tutorials and examples he has on the install. Once you go through those, which are fun to do you can go on to Mathews Nehe conversions.

This is a great starting point:
http://psch.thinbasic.com/tutorials_basic_intro.html