Lionheart008
29-07-2009, 13:54
hello,
simple question: what's the best way to show two different textures in one scene ?
'-- 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
kind regards, lionheart
simple question: what's the best way to show two different textures in one scene ?
'-- 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
kind regards, lionheart