Results 1 to 7 of 7

Thread: image apply to box cube

  1. #1

    image apply to box cube

    hello thinbasic! how I can load an image to an cube and apply to this cube? I am totally newbie on tbgl. A vertex box with six different images and colors at surface how to realise? last question: I want to push four cubes with different velocity for rotating with start and stop animation regards, floyd

  2. #2
    for the first question look at this subject:
    multiple textures on the cube faces :
    http://www.thinbasic.com/community/s...the-cube-faces
    download the two examples there, also don't forget to study the TBGL
    Lessons by Petr here: http://psch.thinbasic.com/old/tbgl_tut_b.html

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

    Zak gave you the essential advice, I would just add that for further study, there are examples in:
    /thinBasic/SampleScripts/TBGL/

    divided into multiple categories. I would recommend to study the Basic category first (basics of shape definition, texturing, ...), and then have a look at those in EntityBased category. They demonstrate the entity approach, very well suitable for easy manipulation with both camera, light and geometric entities.

    TBGL module is documented via Help file (just press F1 on TBGL keyword to get there), Articles and dedicated website.


    Petr
    Last edited by Petr Schreiber; 05-12-2011 at 17:39.
    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

  4. #4
    thanks zak, petr.

    I took some example and fiddled together for a first result with cubes and textures.

    '
    ' The entity skeleton for TBGL
    ' Suitable for developing editor apps
    ' , started on 12-08-2011
    '
    ' paul.w.floyd first attempt
     
    Uses "UI", "TBGL"
    
    ' -- ID numbers of controls
    Begin ControlID
      %lCanvas 
      %bClose 
      
      %myTimer 
    End ControlID
    
    ' -- Global equates
    Begin Const
      %MAIN_WIDTH   = 640
      %MAIN_HEIGHT  = 480
    
      %timeOut      = 20   ' -- Determines graphics refresh rate in milliseconds
    End Const
    
    ' -- Scene-Entity related ids            
    Begin Const
      ' -- Scene IDs
      %sScene  = 1
     
      ' -- Entity IDs 
      %eCamera = 1
      %eLight  
      %eBox
      %bAnima        
    End Const 
    
                
    Function TBMain()
    
      Local hDlg As DWord
      
      Dialog New Pixels, 0, "Dialog with TBGL",-1,-1, %MAIN_WIDTH, %MAIN_HEIGHT, _
                                         %WS_POPUP Or %WS_VISIBLE Or _
                                         %WS_CLIPCHILDREN Or %WS_CAPTION Or _
                                         %WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_MAXIMIZEBOX Or %WS_THICKFRAME, 0 To hDlg
        
        ' -- Place controls here
        Control Add Label, hDlg, %lCanvas, "", 5, 5, %MAIN_WIDTH-10, %MAIN_HEIGHT-40
          Control Set Color hDlg, %lCanvas, %BLACK, %BLACK
          Control Set Resize hDlg, %lCanvas, 1, 1, 1, 1    
    
         
        Control Add Button, hDlg, %bClose, "Close", %MAIN_WIDTH-105, %MAIN_HEIGHT-30, 100, 25
        Control Add Button, hDlg, %bAnima, "Anima", %MAIN_WIDTH-245, %MAIN_HEIGHT-30, 100, 25
        Control Set Resize hDlg, %bAnima, 0, 1, 0, 1    
        Control Set Resize hDlg, %bClose, 0, 1, 0, 1    
       
        Dialog Set Minsize hDlg, 320, 230
        Dialog Show Modal hDlg, Call dlgCallback
        
    End Function      
     
    CallBack Function dlgCallback()
      Static hCtrl As DWord
      
      Select Case CBMSG
        
        Case %WM_INITDIALOG
          Dialog Set Timer CBHNDL, %myTimer, %timeOut, %NULL
          Control Handle CBHNDL, %lCanvas To hCtrl
          
          ' -- Init OpenGL
          TBGL_BindCanvas(hCtrl)     
          
          ' -- Create scene
          TBGL_SceneCreate(%sScene)
      
          ' -- Create basic entities
          ' -- Create camera to look from 5, 5, 5 to 0, 0, 0 
          TBGL_EntityCreateCamera(%sScene, %eCamera)
            TBGL_EntitySetPos(%sScene, %eCamera, 5, 5, 5)
            TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)  
            
          ' -- Create point light  
          TBGL_EntityCreateLight(%sScene, %eLight)
            TBGL_EntitySetPos(%sScene, %eLight, 15, 10, 5)
    
          ' -- Create something to look at
          TBGL_EntityCreateBox(%sScene, %eBox, 0, 1, 1, 1, 0, 255, 255, 255)
            TBGL_EntitySetPos(%sScene, %eBox, 0, 0, 0)      
          
        Case %WM_SIZE, %WM_SIZING
          TBGL_UpdateCanvasProportions(hCtrl)
          RenderMyImage(hCtrl)
    
        Case %WM_TIMER
          RenderMyImage(hCtrl)
    
        Case %WM_CLOSE 
          TBGL_ReleaseCanvas(hCtrl)      
          Dialog Kill Timer CBHNDL, %myTimer
          
        Case %WM_COMMAND
          Select Case CBCTL
            
            Case %bClose
              If CBCTLMSG = %BN_CLICKED Then Dialog End CBHNDL
            
          End Select
          
      End Select
    End Function
    
    Function RenderMyImage( hCtrl As DWord )
      Static FrameRate As Double
    
    ' Load Texture, Apply it.
      TBGL_LoadTexture APP_SourcePath + "asterix2.bmp"     , 1, %TBGL_TEX_MIPMAP
      TBGL_LoadTexture APP_SourcePath + "illus.bmp", 2, %TBGL_TEX_MIPMAP
      TBGL_LoadTexture APP_SourcePath + "simpsons.bmp"   , 3, %TBGL_TEX_MIPMAP
      TBGL_LoadTexture APP_SourcePath + "robotguy.bmp"   , 4, %TBGL_TEX_MIPMAP
      TBGL_LoadTexture APP_SourcePath + "schultz.bmp"   , 5, %TBGL_TEX_MIPMAP
      TBGL_LoadTexture APP_SourcePath + "charly.bmp"   , 6, %TBGL_TEX_MIPMAP
    
      If TBGL_CanvasBound(hCtrl) Then
    
        FrameRate = TBGL_GetFrameRate
    
        TBGL_ClearFrame 
          
          TBGL_SceneRender(%sScene)                                 
           CubesTextures()
           
        TBGL_DrawFrame 
           TBGL_EntityTurn(%sScene, %eBOx, 0, 20/FrameRate, 0)
           
      End If  
    End Function
     
    Sub CubesTextures()
    Dim xRot, yRot, zRot As Single
    Dim frameRate As Double
    
    FrameRate = TBGL_GetFrameRate
        
    TBGL_Translate 0.0, 0.0, -5.0  ' Move Into Screen -5 Units
     TBGL_Rotate Xrot, 1.0, 0.0, 0.0 ' Rotate on X-Axis
     TBGL_Rotate Yrot, 0.0, 1.0, 0.0 ' Rotate on Y-Axis
     TBGL_Rotate Zrot, 0.0, 0.0, 1.0 ' Rotate on Z-Axis
      
     TBGL_UseTexturing %TRUE                      
    
     TBGL_Color 200,155,0 
     TBGL_BindTexture 1
     TBGL_BeginPoly %GL_QUADS     
      ' Bottom Face
      TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex -1.5, -1.5, -1.5 ' Top Right of Texture and Quad
      TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex 1.5, -1.5, -1.5 ' Top Left
      TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex 1.5, -1.5, 1.5 ' Bottom Left
      TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex -1.5, -1.5, 1.5 ' Bottom Right
     TBGL_EndPoly
     
     TBGL_BindTexture 2
     TBGL_BeginPoly %GL_QUADS     
      
      ' Right Face
      TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex 1.5, -1.5, -1.5 ' Bottom Right of Texture and Quad
      TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex 1.5, 1.5, -1.5 ' Top Right
      TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex 1.5, 1.5, 1.5 ' Top Left
      TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex 1.5, -1.5, 1.5 ' Bottom Left
     TBGL_EndPoly
      
     TBGL_BindTexture 3
     TBGL_BeginPoly %GL_QUADS    ' Drawing using Quads
      ' Front Face
      TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex -1.5, -1.5, 1.5 ' Bottom Left of Texture and Quad
      TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex 1.5, -1.5, 1.5 ' Bottom Right
      TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex 1.5, 1.5, 1.5 ' Top Right
      TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex -1.5, 1.5, 1.5 ' Top Left
     TBGL_EndPoly
     
    TBGL_BindTexture 4
     TBGL_BeginPoly %GL_QUADS    ' Drawing using Quads
        
      ' Top Face
      TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex -1.5, 1.5, -1.5 ' Top Left of Texture and Quad
      TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex -1.5, 1.5, 1.5 ' Bottom Left
      TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex 1.5, 1.5, 1.5 ' Bottom Right
      TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex 1.5, 1.5, -1.5 ' Top Right 
     TBGL_EndPoly
      
     TBGL_BindTexture 5
     TBGL_BeginPoly %GL_QUADS
       ' Back Face
      TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex -1.5, -1.5, -1.5 ' Bottom Right of Texture and Quad
      TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex -1.5, 1.5, -1.5 ' Top Right
      TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex 1.5, 1.5, -1.5 ' Top Left
      TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex 1.5, -1.5, -1.5 ' Bottom Left
     TBGL_EndPoly
     
     TBGL_BindTexture 6
     TBGL_BeginPoly %GL_QUADS
      ' Left Face
      TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex -1.5, -1.5, -1.5 ' Bottom Left of Texture and Quad
      TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex -1.5, -1.5, 1.5 ' Bottom Right
      TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex -1.5, 1.5, 1.5 ' Top Right
      TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex -1.5, 1.5, -1.5 ' Top Left
     TBGL_EndPoly
     
     Xrot += ( 54.0 / frameRate ) ' X-Axis Rotation 
     Yrot += ( 26.0 / frameRate ) ' Y-Axis Rotation
     Zrot += ( 72.0 / frameRate ) ' Z-Axis Rotation
     
     End Sub
    
    my cube was displayed well, but too dark, different colors are missing. and I wanted to self rotate them, dont work with my cube sub, I suggest the entity had no id number for that. help to fix the problem I am glad to see. there was a lot to study. my mind is rotating in a tbgl mess. but the tbgl tool is very exciting, thank you guys!

    floyd

    how to get an image for my profile? (stratocaster)
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Floyd; 09-12-2011 at 11:56.

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Quote Originally Posted by Floyd View Post
    how to get an image for my profile? (stratocaster)
    Use sub-menu "Forum Actions/Edit profile"

    Ciao
    Eros
    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

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

    I think you did your first attempt great, just few suggestions for improvement:
    1. loading the textures in RenderMyImage function will make the code load textures each frame. This is possible, but not necessary, it is enough to load the textures after binding the canvas in WM_InitDialog
    2. the light was wrong, because your cube did not have the normals specified. Normals are vectors, which tell TBGL how the light will be reflected from the surface
    3. mixing entity system and classic rendering the way you did is possible, but more systematic approach is to create custom entity based on actor template (TBGL/actor_template.taguit)
    4. using textures 126x126 will work only on modern GPUs, I resized them to 128x128 (which is power of two dimension), which will work everywhere


    I prepaired modified version for you with all the points corrected. The code for cube with multiple textures moved to file actor_MultiCube.tBasicU. This way you can manipulate your custom entity via TBGL_Entity* commands, which saves you some work. The modified rendering code (added normals) can be seen in actor_MultiCube.tBasicU file, function is named MultiCube_Render.

    For better understanding, I would recommend to do some reading on custom entities here:
    User defined entities


    Petr
    Attached Files Attached Files
    Last edited by Petr Schreiber; 09-12-2011 at 14:17.
    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

  7. #7
    I've overlooked this example, sorry, petr for late reply. thanks for expanded help and new entity examples I have to study yet for next time.

    my new question here how I can stop a moving box (running from left side to the center of scene) by a command or with timer functions? I wanted to have 9 boxes side by side in one frontier line. entity push I know already but to stop a cube without having other stop or callback buttons that's existing a special command? any suggestion? I wanted program with stopping the cube for reaching a certain angle than box will stop. do you have better idea? thanks for help, floyd (paul)

Similar Threads

  1. Image of the day
    By ErosOlmi in forum Shout Box Area
    Replies: 0
    Last Post: 08-11-2011, 18:40
  2. The ten year rule - Does this apply to programming?
    By LanceGary in forum Shout Box Area
    Replies: 0
    Last Post: 10-12-2010, 11:35
  3. ppm image format
    By zak in forum Shout Box Area
    Replies: 1
    Last Post: 14-04-2010, 18:20
  4. multiple textures on the cube faces
    By zak in forum TBGL General
    Replies: 3
    Last Post: 29-03-2010, 07:29
  5. LED Cube Fun
    By Michael Clease in forum Technology
    Replies: 6
    Last Post: 31-07-2009, 11:27

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
  •