PDA

View Full Version : display 2 textures



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

Petr Schreiber
29-07-2009, 17:57
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 (http://www.thinbasic.com/index.php?option=com_jdownloads&Itemid=95&task=viewcategory&catid=5) 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:


tbgl_BindTexture 1
tbgl_BindTexture 2


with


tbgl_BindTexture 1


And you will get both flowers and woman face :)


Petr

Lionheart008
29-07-2009, 19:31
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:



tbgl_NewList %MYPLACE
FlowerCity()
tbgl_EndList

tbgl_NewList %MYPLACE2
LoveCity()
tbgl_EndList

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