Results 1 to 8 of 8

Thread: tbgl_Box and the color

  1. #1
    Senior Member zak's Avatar
    Join Date
    Dec 2008
    Posts
    637
    Rep Power
    83

    tbgl_Box and the color

    Hi Petr , Hi all
    in the NeHe Lesson 05 by matthew in his message:
    http://community.thinbasic.com/index.php?topic=677.0
    there is a cube defined by 4*6 = 24 TBGL_Vertex in addition to the color definition for every cube face
    but you have a tbgl_Box function, which is great in making drawing quadrics easier, is there any way to color the faces of the cube defined by tbgl_Box but every face in a different color ?
    below is a stripped down example from the matthew code, the cube color is blue.
    [code=thinbasic]
    uses "TBGL" ' thinBASIC OpenGL Library

    ' Declare Variables here
    dim rquad as single ' Quad Rotation
    dim frameRate as double ' Timing Variable


    ' Create Display, Return Handle.
    dim hWnd as dword
    dim bits as long

    hWnd = tbgl_createwindowex(" - Press 'Esc' to Quit", 640, 480, bits, %TBGL_WS_WINDOWED)

    tbgl_showwindow ' Show Display

    TBGL_ResetKeyState() ' Reset all Keys

    ' Start Main Loop
    while tbgl_iswindow(hWnd)

    frameRate = tbgl_getframerate
    tbgl_clearframe ' Clear Display

    tbgl_camera 0,0,1,0,0,0 ' Default Camera, View From 0,0,1 To 0,0,0.
    TBGL_Translate 0.0, 0.0, -7.0 ' Move Right 1.5 Units, Into the Screen 7 Units.
    TBGL_Rotate rquad, 1.0, 1.0, 1.0 ' X,Y & Z Axis Rotations.
    TBGL_Color 0, 0, 255 ' Blue
    tbgl_Box 2, 2, 2

    rquad -= ( 27.0 / frameRate ) ' Increase Quad Rotation

    tbgl_drawframe ' Display anything

    if tbgl_getWindowkeystate(hWnd, %VK_ESCAPE) then exit while

    wend

    tbgl_destroywindow ' Closes Display[/code]




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

    Re: tbgl_Box and the color

    Hi Zak,

    interesting idea.

    The thing is I thought in most cases I always used single colored box, that's what TBGL_box is defined how it is.

    Here is function in TBGL which will do what you need ( I hope ) for you.
    - colors are defined as RGB in array of 6 items
    - superBox function takes width, height, length + array of colors as parameter

    For optimal performance you could consider making it a display list first.

    [code=thinbasic]
    uses "TBGL" ' thinBASIC OpenGL Library

    ' Declare Variables here
    dim rquad as single ' Quad Rotation
    dim frameRate as double ' Timing Variable

    ' Create Display, Return Handle.
    dim hWnd as dword
    dim bits as long = 32

    hWnd = tbgl_createwindowex(" - Press 'Esc' to Quit", 640, 480, bits, %TBGL_WS_WINDOWED)
    tbgl_showwindow ' Show Display

    ' -- color definition
    TYPE SuperBox_RGB
    R AS BYTE
    G AS BYTE
    B AS BYTE
    END TYPE

    ' -- auxiliary names
    begin const
    %top = 1
    %bottom
    %front
    %back
    %left
    %right
    end const

    ' -- Array of colors
    Dim CustomColor(6) as SuperBox_RGB

    with CustomColor(%top)
    .R = 255
    .G = 255
    .B = 255
    end with

    with CustomColor(%bottom)
    .R = 255
    .G = 255
    .B = 0
    end with

    with CustomColor(%front)
    .R = 255
    .G = 0
    .B = 0
    end with

    with CustomColor(%back)
    .R = 0
    .G = 255
    .B = 255
    end with

    with CustomColor(%left)
    .R = 0
    .G = 0
    .B = 255
    end with

    with CustomColor(%right)
    .R = 255
    .G = 0
    .B = 255
    end with

    TBGL_ResetKeyState() ' Reset all Keys

    ' Start Main Loop
    while tbgl_iswindow(hWnd)

    frameRate = tbgl_getframerate
    tbgl_clearframe ' Clear Display

    tbgl_camera 0,0,1,0,0,0 ' Default Camera, View From 0,0,1 To 0,0,0.
    TBGL_Translate 0.0, 0.0, -7.0 ' Move Right 1.5 Units, Into the Screen 7 Units.
    TBGL_Rotate rquad, 1.0, 1.0, 1.0 ' X,Y & Z Axis Rotations.

    ' -- Super box takes dimnesions and color array as parameters
    SuperBox 2, 2, 2, CustomColor

    rquad -= ( 27.0 / frameRate ) ' Increase Quad Rotation

    tbgl_drawframe ' Display anything

    if tbgl_getWindowkeystate(hWnd, %VK_ESCAPE) then exit while

    wend

    tbgl_destroywindow ' Closes Display

    ' ------------------
    ' SuperBox procedure
    ' ------------------

    SUB SuperBox(a as single, b as single , c as single, Colors() as SuperBox_RGB )
    TBGL_BeginPoly %GL_QUADS
    ' Top Quad
    TBGL_Color Colors(1).R, Colors(1).G, Colors(1).B
    TBGL_Vertex a, b, -c ' Top Right
    TBGL_Vertex -a, b, -c ' Top Left
    TBGL_Vertex -a, b, c ' Bottom Left
    TBGL_Vertex a, b, c ' Bottom Right

    ' Bottom Quad
    TBGL_Color Colors(2).R, Colors(2).G, Colors(2).B
    TBGL_Vertex a, -b, c ' Top Right
    TBGL_Vertex -a, -b, c ' Top left
    TBGL_Vertex -a, -b, -c ' Bottom Left
    TBGL_Vertex a, -b, -c ' Bottom Right

    ' Front Quad
    TBGL_Color Colors(3).R, Colors(3).G, Colors(3).B
    TBGL_Vertex a, b, c ' Top Right
    TBGL_Vertex -a, b, c ' Top Left
    TBGL_Vertex -a, -b, c ' Bottom Left
    TBGL_Vertex a, -b, c ' Bottom Right

    ' Back Quad
    TBGL_Color Colors(4).R, Colors(4).G, Colors(4).B
    TBGL_Vertex a, -b, -c ' Bottom Left
    TBGL_Vertex -a, -b, -c ' Bottom Right
    TBGL_Vertex -a, b, -c ' Top Right
    TBGL_Vertex a, b, -c ' Top Left

    ' Left Quad
    TBGL_Color Colors(5).R, Colors(5).G, Colors(5).B
    TBGL_Vertex -a, b, -c ' Top Right
    TBGL_Vertex -a, -b, -c ' Top Left
    TBGL_Vertex -a, -b, c ' Bottom Left
    TBGL_Vertex -a, b, c ' Bottom Right

    ' Right Quad
    TBGL_Color Colors(6).R, Colors(6).G, Colors(6).B
    TBGL_Vertex a, b, -c ' Top Right
    TBGL_Vertex a, b, c ' Top Left
    TBGL_Vertex a, -b, c ' Bottom Left
    TBGL_Vertex a, -b, -c ' Bottom Right
    TBGL_EndPoly
    END SUB
    [/code]


    Petr

    EDIT: corrected

    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

  3. #3
    Senior Member zak's Avatar
    Join Date
    Dec 2008
    Posts
    637
    Rep Power
    83

    Re: tbgl_Box and the color

    Hi Petr
    you forget to change the numbers in the function SuperBox to a,b,c i attached the code below.
    this is great, a superbox, i suggest i a future tbgl version something like this coded internaly tbgl_superbox a,b,c, ct,cb,cr,cl,cf,cb
    in wich the ct= top color, cb= bottom color and so on.
    thanks
    ' Empty GUI script created on 06-22-2009 13:32:46 by (ThinAIR)
    uses "TBGL" ' thinBASIC OpenGL Library
     
    ' Declare Variables here
    dim rquad as single ' Quad Rotation
    dim frameRate as double ' Timing Variable
     
    ' Create Display, Return Handle.          
    dim hWnd as dword
    dim bits as long = 32
     
    hWnd = tbgl_createwindowex("  - Press 'Esc' to Quit", 640, 480, bits, %TBGL_WS_WINDOWED)
    tbgl_showwindow ' Show Display
     
    ' -- color definition
    TYPE SuperBox_RGB
     R AS BYTE
     G AS BYTE
     B AS BYTE
    END TYPE
     
    ' -- auxiliary names
    begin const
     %top = 1
     %bottom
     %front
     %back
     %left
     %right
    end const
     
    ' -- Array of colors 
    Dim CustomColor(6) as SuperBox_RGB
     
    with CustomColor(%top)
     .R = 255
     .G = 255
     .B = 255
    end with
     
    with CustomColor(%bottom)
     .R = 255
     .G = 255
     .B = 0
    end with
     
    with CustomColor(%front)
     .R = 255
     .G = 0
     .B = 0
    end with
     
    with CustomColor(%back)
     .R = 0
     .G = 255
     .B = 255
    end with
     
    with CustomColor(%left)
     .R = 0
     .G = 0
     .B = 255
    end with
     
    with CustomColor(%right)
     .R = 255
     .G = 0
     .B = 255
    end with
     
    TBGL_ResetKeyState() ' Reset all Keys 
     
    ' Start Main Loop
    while tbgl_iswindow(hWnd)
     
     frameRate = tbgl_getframerate
     tbgl_clearframe         ' Clear Display
     
     tbgl_camera 0,0,1,0,0,0      ' Default Camera, View From 0,0,1 To 0,0,0.
     TBGL_Translate 0.0, 0.0, -7.0   ' Move Right 1.5 Units, Into the Screen 7 Units.
     TBGL_Rotate rquad, 1.0, 1.0, 1.0 ' X,Y & Z Axis Rotations.
     
     ' -- Super box takes dimnesions and color array as parameters
     SuperBox 2, 1, 1, CustomColor
     
     rquad -= ( 27.0 / frameRate ) ' Increase Quad Rotation 
     
     tbgl_drawframe      ' Display anything
     
     if tbgl_getWindowkeystate(hWnd, %VK_ESCAPE) then exit while
     
    wend
     
    tbgl_destroywindow ' Closes Display
     
    ' ------------------
    ' SuperBox procedure
    ' ------------------
     
    SUB SuperBox(a as single, b as single , c as single, Colors() as SuperBox_RGB )
     TBGL_BeginPoly %GL_QUADS
       ' Top Quad
      TBGL_Color Colors(1).R, Colors(1).G, Colors(1).B
      TBGL_Vertex a, b, -c ' Top Right
      TBGL_Vertex -a, b, -c ' Top Left
      TBGL_Vertex -a, b, c ' Bottom Left
      TBGL_Vertex a, b, c ' Bottom Right
     
      ' Bottom Quad
      TBGL_Color Colors(2).R, Colors(2).G, Colors(2).B
      TBGL_Vertex a, -b, c ' Top Right
      TBGL_Vertex -a, -b, c ' Top left
      TBGL_Vertex -a, -b, -c ' Bottom Left
      TBGL_Vertex a, -b, -c ' Bottom Right
     
      ' Front Quad
      TBGL_Color Colors(3).R, Colors(3).G, Colors(3).B
      TBGL_Vertex a, b, c ' Top Right
      TBGL_Vertex -a, b, c ' Top Left
      TBGL_Vertex -a, -b, c ' Bottom Left
      TBGL_Vertex a, -b, c ' Bottom Right
     
      ' Back Quad
      TBGL_Color Colors(4).R, Colors(4).G, Colors(4).B
      TBGL_Vertex a, -b, -c ' Bottom Left
      TBGL_Vertex -a, -b, -c ' Bottom Right
      TBGL_Vertex -a, b, -c ' Top Right
      TBGL_Vertex a, b, -c ' Top Left
     
      ' Left Quad
      TBGL_Color Colors(5).R, Colors(5).G, Colors(5).B
      TBGL_Vertex -a, b, -c ' Top Right
      TBGL_Vertex -a, -b, -c ' Top Left
      TBGL_Vertex -a, -b, c ' Bottom Left
      TBGL_Vertex -a, b, c ' Bottom Right
     
      ' Right Quad
      TBGL_Color Colors(6).R, Colors(6).G, Colors(6).B
      TBGL_Vertex a, b, -c ' Top Right
      TBGL_Vertex a, b, c ' Top Left
      TBGL_Vertex a, -b, c ' Bottom Left
      TBGL_Vertex a, -b, -c ' Bottom Right
     TBGL_EndPoly
    END SUB
    

  4. #4
    Senior Member zak's Avatar
    Join Date
    Dec 2008
    Posts
    637
    Rep Power
    83

    Re: tbgl_Box and the color

    why the code in my messages is small and black??

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

    Re: tbgl_Box and the color

    Hi Zak,

    thanks for correction, I was in hurry too much.

    Regarding the formatting - you use CODE tag without parameters I presume.

    Try to use (without spaces) [ code = thinBasic ] ... source here ... [ / code ] instead. It will immediately automatically highlight the code.


    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
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    160

    Re: tbgl_Box and the color

    Quote Originally Posted by zak
    i suggest i a future tbgl version something like this coded internaly tbgl_superbox a,b,c, ct,cb,cr,cl,cf,cb
    in wich the ct= top color, cb= bottom color and so on.
    thanks
    I also think that would be useful but something like
    [code=thinbasic]TBGL_BoxColored (a,b,c, ct,cb,cr,cl,cf,cb)[/code]

    and perhaps if each face could be assigned a texure that would be even better.

    [code=thinbasic]TBGL_BoxColoredTextured (a,b,c, ct,cb,cr,cl,cf,cb, tt,tb,tr,tl,tf,tb)[/code]


    Mike

    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

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

    Re: tbgl_Box and the color

    Hi,

    thanks all for the suggestions.

    I think having 12 extra parameters is pretty mad, thats why I would propose similar solution to the one I showed, which is passing array of parameters (Texture/R/G/B for each face). The UDT could be pre-defined in module already.

    Second thing is that using different texture for each face will give your graphic card a bit of headache, in case of multiple cubes I would solve it by rendering each side with same texture in series...

    But I understand in case of few cubes this would be too much for programmer - so I will try your suggestion, just in slightly modded syntax:
    [code=thinbasic]
    tbgl_Box ( width, height, length [, faceParameters ])
    [/code]


    Thanks,
    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
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,830
    Rep Power
    10

    Re: tbgl_Box and the color

    Quote Originally Posted by zak
    why the code in my messages is small and black??
    Hi zak,

    as suggested by Petr you need to add the language name in Code block or use "forum syntax highligher GeShi".
    See atached picture.

    Ciao
    Eros
    Attached Images Attached Images
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. MOVED: tbgl_Box and the color
    By Petr Schreiber in forum TBGL General
    Replies: 0
    Last Post: 22-06-2009, 19:10

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
  •