Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Logic trouble (help asked)

  1. #1

    Question Logic trouble (help asked)

    Hi ,

    I've got trouble understanding these two lines of code:

    line 33 & line 34

      'TBGL_RenderMatrix2D(0,1,800,601) 'this works better but is not logic for me
      TBGL_RenderMatrix2D(1,1,800,600) 'this don't work properly
    
    in this little piece of code

    '---Script created on 12-19-2018 17:30:47 by
    
    uses "TBGL"
    uses "console"
    
    dim htbgl as DWord 'handler for draw window
    
    const max_x Value = 800 'window size
    const max_y value = 600
    
    Function tbmain()
    
      call window_init
      call draw_loop
    
      TBGL_DestroyWindow
    
    end function
    
    function draw_box()
    
      TBGL_Line (1,1,1,max_y)
      TBGL_Line (1,max_y,max_x,max_y)
      TBGL_Line (max_x,max_y,max_x,1)
      TBGL_Line (max_x,1,1,1)
    
    end Function
    
    function window_init()
    
      htbgl = TBGL_CreateWindowEx ("800x600 - ESC to quit", 800,600,16,%TBGL_WS_WINDOWED + %TBGL_WS_DONTSIZE)
      tbgl_ShowWindow
      'TBGL_RenderMatrix2D(0,1,800,601) 'this works better but is not logic for me
      TBGL_RenderMatrix2D(1,1,800,600) 'this don't work properly
      TBGL_Color (255,255,255)
    
    end Function
    
    Function draw_loop()
    
    ' -- Main loop
      While tbgl_IsWindow(htbgl)
        If tbgl_GetWindowKeyState(htbgl, %VK_ESCAPE) Then Exit While
        tbgl_ClearFrame
    
        call draw_box
    
        tbgl_DrawFrame
        tbgl_ResetKeyState()
    
      Wend
    
    end Function
    
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  2. #2
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    Hmm its obvious, think "openGL" - not Windows...
    The order of width and height must be in another order. I think it was just clockwise but am not sure.
    I did a lot using 2d-matrix, if you don't find it for example in thinICE-project you will find for sure here in this game:
    https://www.thinbasic.com/community/...end-(game-RPG)

    If you experience problems of the sound in the game then it's related to GetTickCount-Function, I replaced it using thinbasic Hires-timer but I don't remember if I uploaded it. Anyway its not about the game but the order of left - down - right - top or something
    I think there are missing some Forum-sections as beta-testing and support

  3. #3
    Quote Originally Posted by ReneMiner View Post
    Hmm its obvious, think "openGL" - not Windows...
    The order of width and height must be in another order. I think it was just clockwise but am not sure.
    Hi Rene,

    this is not about that, but about the difference between the working line 33 and the not working line 34.

    Look, help for TBGL_RenderMatrix2D states that

    TBGL_RenderMatrix2D[( leftX, bottomY, rightX, topY )]
    leftX Specifies X coordinate for left side of current viewport
    bottomY Specifies Y coordinate for bottom side of current viewport
    rightX Specifies X coordinate for right side of current viewport
    topY Specifies Y coordinate for top side of current viewport
    so,
    const max_x Value = 800 'window size
    const max_y value = 600
    htbgl = TBGL_CreateWindowEx ("800x600 - ESC to quit",max_x,max_y,16,%TBGL_WS_WINDOWED + %TBGL_WS_DONTSIZE)
    TBGL_RenderMatrix2D(1,1,max_x,max_y) 'this don't work properly
    TBGL_Line (1,1,1,max_y) 'drawing a box
    TBGL_Line (1,max_y,max_x,max_y)
    TBGL_Line (max_x,max_y,max_x,1)
    TBGL_Line (max_x,1,1,1)
    
    ... rest of the code ...
    
    logically, for this code, one has to see a box at the utter limit of the drawing area. This isn't the case, there is a one pixel shift and in addition not for every parameter. To work around this issue, one has to cheat with TBGL_RenderMatrix2D(0,1,max_x,max_y+1). I found it weird and illogic.
    Last edited by DirectuX; 22-12-2018 at 17:47. Reason: precision
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

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

    thanks a lot for this discussion, you really discovered something worth closer look.

    The way raw OpenGL rasterizes some primitives is a bit unintuitive, so I tried to address it with a bit of help.

    Please find here attached new version of TBGL, which should draw points and lines correctly from "expectation" point of view

    You can test with the following variation of posted code below.

    Before launching the code, please download and unzip the updated DLL to ThinBasic/Lib directory:
    https://we.tl/t-IGCQmO63x9

    uses "TBGL"
     
    begin const
      %max_x = 800
      %max_y = 600
    end const
     
    function tbMain()
     
      window_init()
      draw_loop()
     
      tbgl_destroyWindow
     
    end function
     
    function draw_box()
    
      tbgl_line (1, 1, 1, %max_y)
      tbgl_line (1, %max_y, %max_x, %max_y)
      tbgl_line (%max_x, %max_y, %max_x, 1)
      tbgl_line (%max_x, 1, 1, 1)
    
    end function
     
    function window_init()
     
      global g_win as dword = tbgl_CreateWindowEx ("Pixel perfect 2D rendering - ESC to quit", 800, 600, 32, %TBGL_WS_WINDOWED or %TBGL_WS_DONTSIZE)
      tbgl_showWindow
      tbgl_renderMatrix2D (1, 1, 800, 600, %TBGL_PIXEL_PERFECT_2D) ' -- New, optional switch, for pixel perfect graphics
      tbgl_color 255 , 0, 255
     
    end function
     
    function draw_loop()
     
      ' -- Main loop
      tbgl_resetKeyState()
      
      while tbgl_isWindow(g_win)
        if tbgl_getWindowKeyState(g_win, %VK_ESCAPE) then exit while
    
        tbgl_clearFrame
     
          draw_box()
     
        tbgl_drawFrame
    
      wend
     
    end function
    

    Let me know how does it work for you.


    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

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    I performed further testing, and here is more robust version of the fix, please download here:
    https://we.tl/t-3SEOPzgXCD

    It will work with my example above.

    Let me know whether it works for you.


    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

  6. #6

    Post

    Quote Originally Posted by Petr Schreiber View Post
    I performed further testing, and here is more robust version of the fix, please download here:
    https://we.tl/t-3SEOPzgXCD

    It will work with my example above.

    Let me know whether it works for you.


    Petr

    Hi Petr,

    I read your answer but can't download the file : it expired meanwhile I was disconnected for Christmas break. Could you please share it anew?
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

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

    please find it attached to this post


    Petr
    Attached Files Attached Files
    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
    Thanks Petr,
    I just tried it, the new parameter works ok.

    By the way what do you think about the suggestion in the support thread ? https://www.thinbasic.com/community/...hp?issueid=555
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

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

    As TBGL development continues on gitHub, I created an issue for it:
    https://github.com/ThinBASIC/thinBasic_TBGL/issues/3

    Regarding pixel perfect mode, I will try to ensure it gets to the next release of thinBasic, so you can count on it.


    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

  10. #10

    Post

    Quote Originally Posted by DirectuX View Post
    Thanks Petr,
    I just tried it, the new parameter works ok.
    Hi Petr,
    • too quick. There are glitches.
      Here is a sample: perfecttest.zip (use T to toggle views)
    • In the same sample you can also notice that there is something odd with TBGL_MouseGetPos... : is there a hidden limit to returned values ? , because mouse get unexpectedly off the window at right or bottom, this doesn't occur on a smaller window.
    • I've read github version of the issue, "...does not allow to draw visible lines using the following code" is not what I meant: lines are visible but off-setted.
      While running the illustration code you provided on github, i got this bmp which curiously is ok for me: oddity.zip
      Meanwhile, I'll try to understand the commit.



    Edit: in src/tbgl_Frame.inc , line 153
    why when mode2d %TBGL_PIXEL_PERFECT_2D don't you reset pixelOffset to zero ? As it is now, when switching pixel perfect mode on then off again, you don't get back the starting state (0) but (-0.5).
    Last edited by DirectuX; 09-01-2019 at 10:17. Reason: thoughts on commit
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

Page 1 of 2 12 LastLast

Similar Threads

  1. Trouble in (my) Paradise
    By LCSims in forum Core module
    Replies: 24
    Last Post: 04-07-2013, 21:58
  2. TBGL FAQ ( Frequently Asked Questions )
    By Petr Schreiber in forum TBGL General
    Replies: 4
    Last Post: 07-05-2013, 15:35
  3. Logic wins??
    By danbaron in forum Science
    Replies: 0
    Last Post: 15-11-2010, 06:52
  4. Logic wins??
    By danbaron in forum Science
    Replies: 0
    Last Post: 15-11-2010, 06:51

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

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