Results 1 to 9 of 9

Thread: using TBGL_VERTEX

  1. #1

    using TBGL_VERTEX

    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

  2. #2

    Re: using TBGL_VERTEX

    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.

    That might answer some of your questions.

    [code=thinbasic]
    ' 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
    [/code]
    Operating System: Windows 10 Home 64-bit
    CPU: Intel Celeron N4000 CPU @ 1.10GHz
    Memory: 4.00GB RAM
    Graphics: Intel UHD Graphics 600

  3. #3

    Re: using TBGL_VERTEX

    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

  4. #4

    Re: using TBGL_VERTEX

    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.

    Operating System: Windows 10 Home 64-bit
    CPU: Intel Celeron N4000 CPU @ 1.10GHz
    Memory: 4.00GB RAM
    Graphics: Intel UHD Graphics 600

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: using TBGL_VERTEX

    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.
    Attached Images Attached Images
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6

    Re: using TBGL_VERTEX

    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

  7. #7
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: using TBGL_VERTEX

    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):
    [code=thinbasic]
    ' 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
    [/code]


    Bye,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  8. #8

    Re: using TBGL_VERTEX

    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.
    Attached Images Attached Images

  9. #9
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: using TBGL_VERTEX

    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
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •