Results 1 to 3 of 3

Thread: display 2 textures

  1. #1
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    display 2 textures

    hello,

    simple question: what's the best way to show two different textures in one scene ?

    [code=thinbasic] '-- tbgl example with two different textures , 28.juli.2009 by lionheart

    Uses "TBGL","console"

    Dim i, j As Long

    type tCamera
    DeltaMove as double
    DeltaAngle as double
    AngleLR as double
    AngleUD as double
    PointToX as double
    PointToY as double
    PointToZ as double
    PosX as double
    PosY as double
    PosZ as double
    end type
    dim Cam as tCamera

    DIM hWnd AS DWORD = TBGL_CreateWindowEx( "My little texture play", 800, 600, 32, %TBGL_WS_WINDOWED or %TBGL_WS_MINIMIZEBOX or %TBGL_WS_CLOSEBOX)

    TBGL_ShowWindow

    tbgl_LoadTexture App_SourcePath+"Primavera.bmp", 1, %TBGL_TEX_MIPMAP
    tbgl_LoadTexture App_SourcePath+"Liebespaar.bmp", 2, %TBGL_TEX_MIPMAP

    Cam.PosY = 11.75
    Cam.PosX = -6

    %MYPLACE = 1
    %MYPLACE2 = 2

    tbgl_NewList %MYPLACE
    FlowerCity()
    tbgl_EndList

    tbgl_NewList %MYPLACE
    LoveCity()
    tbgl_EndList

    dim FrameRate as double
    TBGL_ResetKeyState()

    WHILE tbgl_IsWindow(hWnd)

    FrameRate = tbgl_GetFrameRate

    TBGL_ClearFrame
    TBGL_Camera Cam.PosX,Cam.PosY,Cam.PosZ,Cam.PosX+Cam.PointToX,Cam.PosY,Cam.PosZ+Cam.PointToZ ' Setups Camera

    TBGL_CallList %MYPLACE
    TBGL_CallList %MYPLACE2

    TBGL_DrawFrame

    if TBGL_GetWindowKeyState( hWnd, %VK_UP) then Cam.DeltaMove += 5/FrameRate
    if TBGL_GetWindowKeyState( hWnd, %VK_DOWN) then Cam.DeltaMove -= 5/FrameRate

    if TBGL_GetWindowKeyState( hWnd, %VK_PGUP) then Cam.PosY += 5/FrameRate
    if TBGL_GetWindowKeyState( hWnd, %VK_PGDN) then Cam.PosY -= 5/FrameRate

    if TBGL_GetWindowKeyState( hWnd, %VK_RIGHT) then Cam.DeltaAngle += 1/FrameRate

    if TBGL_GetWindowKeyState( hWnd, %VK_LEFT) then Cam.DeltaAngle -= 1/FrameRate

    if TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) then EXIT WHILE

    Cam.AngleLR = Cam.AngleLR + Cam.DeltaAngle
    Cam.PointToX = SIN(Cam.AngleLR)
    Cam.PointToZ = -COS(Cam.AngleLR)

    Cam.PosX = Cam.PosX + Cam.DeltaMove * Cam.PointToX
    Cam.PosZ = Cam.PosZ + Cam.DeltaMove * Cam.PointToZ

    Cam.DeltaMove = 0
    Cam.DeltaAngle = 0

    WEND

    TBGL_DestroyWindow


    Function FlowerCity() As Long

    Local i, j, height As Long

    tbgl_UseTexturing %TRUE
    tbgl_BindTexture 1
    tbgl_BindTexture 2
    For i = -40 To 40 Step 10
    For j = -40 To 40 Step 10
    height = Rnd(6, 20)

    tbgl_BeginPoly %GL_QUADS
    tbgl_Color RND(128,255),RND(128,255),RND(128,255)

    tbgl_TexCoord2D 0,0
    tbgl_Vertex -2.5+i,0,-2.5+j

    tbgl_TexCoord2D 0,1
    tbgl_Vertex 2.5+i,0,-2.5+j

    tbgl_TexCoord2D 1,1
    tbgl_Vertex 2.5+i,height,-2.5+j

    tbgl_TexCoord2D 1,0
    tbgl_Vertex -2.5+i,height,-2.5+j

    tbgl_TexCoord2D 0,0
    tbgl_Vertex -2.5+i,0,2.5+j

    tbgl_TexCoord2D 0,1
    tbgl_Vertex 2.5+i,0,2.5+j

    tbgl_TexCoord2D 1,1
    tbgl_Vertex 2.5+i,height,2.5+j

    tbgl_TexCoord2D 1,0
    tbgl_Vertex -2.5+i,height,2.5+j

    tbgl_TexCoord2D 0,0
    tbgl_Vertex 2.5+i,0,-2.5+j

    tbgl_TexCoord2D 0,1
    tbgl_Vertex 2.5+i,0,2.5+j

    tbgl_TexCoord2D 1,1
    tbgl_Vertex 2.5+i,height,2.5+j

    tbgl_TexCoord2D 1,0
    tbgl_Vertex 2.5+i,height,-2.5+j

    tbgl_TexCoord2D 0,0
    tbgl_Vertex -2.5+i,0,-2.5+j

    tbgl_TexCoord2D 0,1
    tbgl_Vertex -2.5+i,0,2.5+j

    tbgl_TexCoord2D 1,1
    tbgl_Vertex -2.5+i,height,2.5+j

    tbgl_TexCoord2D 1,0
    tbgl_Vertex -2.5+i,height,-2.5+j

    tbgl_TexCoord2D 0,0
    tbgl_Vertex -2.5+i,height,-2.5+j

    tbgl_TexCoord2D 0,1
    tbgl_Vertex -2.5+i,height,2.5+j

    tbgl_TexCoord2D 1,1
    tbgl_Vertex 2.5+i,height,2.5+j

    tbgl_TexCoord2D 1,0
    tbgl_Vertex 2.5+i,height,-2.5+j

    tbgl_EndPoly
    Next
    Next

    tbgl_UseTexturing %FALSE

    End Function

    Function LoveCity() As Long

    Local i, j, height As Long

    tbgl_UseTexturing %TRUE
    tbgl_BindTexture 2
    For i = -40 To 40 Step 10
    For j = -40 To 40 Step 10
    height = Rnd(5, 16)

    tbgl_BeginPoly %GL_QUADS
    tbgl_Color RND(128,255),RND(128,255),RND(128,255)

    tbgl_TexCoord2D 0,0
    tbgl_Vertex -2.5+i,0,-2.5+j

    tbgl_TexCoord2D 0,1
    tbgl_Vertex 2.5+i,0,-2.5+j

    tbgl_TexCoord2D 1,1
    tbgl_Vertex 2.5+i,height,-2.5+j

    tbgl_TexCoord2D 1,0
    tbgl_Vertex -2.5+i,height,-2.5+j

    tbgl_TexCoord2D 0,0
    tbgl_Vertex -2.5+i,0,2.5+j

    tbgl_TexCoord2D 0,1
    tbgl_Vertex 2.5+i,0,2.5+j

    tbgl_TexCoord2D 1,1
    tbgl_Vertex 2.5+i,height,2.5+j

    tbgl_TexCoord2D 1,0
    tbgl_Vertex -2.5+i,height,2.5+j

    tbgl_TexCoord2D 0,0
    tbgl_Vertex 2.5+i,0,-2.5+j

    tbgl_TexCoord2D 0,1
    tbgl_Vertex 2.5+i,0,2.5+j

    tbgl_TexCoord2D 1,1
    tbgl_Vertex 2.5+i,height,2.5+j

    tbgl_TexCoord2D 1,0
    tbgl_Vertex 2.5+i,height,-2.5+j

    tbgl_TexCoord2D 0,0
    tbgl_Vertex -2.5+i,0,-2.5+j

    tbgl_TexCoord2D 0,1
    tbgl_Vertex -2.5+i,0,2.5+j

    tbgl_TexCoord2D 1,1
    tbgl_Vertex -2.5+i,height,2.5+j

    tbgl_TexCoord2D 1,0
    tbgl_Vertex -2.5+i,height,-2.5+j

    tbgl_TexCoord2D 0,0
    tbgl_Vertex -2.5+i,height,-2.5+j

    tbgl_TexCoord2D 0,1
    tbgl_Vertex -2.5+i,height,2.5+j

    tbgl_TexCoord2D 1,1
    tbgl_Vertex 2.5+i,height,2.5+j

    tbgl_TexCoord2D 1,0
    tbgl_Vertex 2.5+i,height,-2.5+j

    tbgl_EndPoly
    Next
    Next

    tbgl_UseTexturing %FALSE

    End Function

    [/code]


    kind regards, lionheart
    Attached Images Attached Images
    Attached Files Attached Files
    you can't always get what you want, but if you try sometimes you might find, you get what you need

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

    Re: display 2 textures

    Hi Frank,

    what do you mean by 2 textures in one scene - like using 2 textures on one object?

    If yes, then you need to use OpenGL headers and switch texturing units.

    The rule is simple:
    - bind texture unit n ( glActiveTextureARB )
    - enable texturing ( TBGL_UseTexturing %TRUE )
    - bind texture object ( TBGL_BindTexture )

    ... for each.
    For texture coordinates, you should use glMultiTexCoord2fARB.
    You can find example on this topic in TBGL Bonus Pack in folder SpecialEffects/Multitexturing.

    I will bring multitexturing to TBGL, but I need to make more tests on Intels.

    But I think the problem in your code seems to be you are using same texture for both "cities".
    Just replace:
    [code=thinbasic]
    tbgl_BindTexture 1
    tbgl_BindTexture 2
    [/code]

    with
    [code=thinbasic]
    tbgl_BindTexture 1
    [/code]

    And you will get both flowers and woman face


    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

  3. #3
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    Re: display 2 textures

    hi petr,

    And you will get both flowers and woman face Smile
    very nice to see, but the sun was too hot for me this day so I haven't seen it.

    thank you for help, does work. my second mistake was...

    a) correct code:

    [code=thinbasic]
    tbgl_NewList %MYPLACE
    FlowerCity()
    tbgl_EndList

    tbgl_NewList %MYPLACE2
    LoveCity()
    tbgl_EndList[/code]

    b) bad code:
    I have used same %MyPLACE for flowerCity() and LoveCity() entities.

    thank you too for the exciting multitexturing example, I didn't know this example !

    I will bring multitexturing to TBGL, but I need to make more tests on Intels.
    very good! good luck, I am curious to see one of this example !

    I pick up an old idea to make a little walk through scene with my tbgl example. more to come.

    good evening, lionheart
    you can't always get what you want, but if you try sometimes you might find, you get what you need

Similar Threads

  1. Flexible display
    By ErosOlmi in forum Technology
    Replies: 1
    Last Post: 02-11-2008, 21:53

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
  •