I can't figure this one out for the life of me.
I draw a shape from 6 triangles (it ends up 3 boxes joined together). 2 of the boxes texture correctly, the first one doesn't. Can someone please run the following code and see if they can figure out the problem? Use a 32x32 image of anything to see the problem. It's a problem with the u and v values for the texture, but I can't work out why the other boxes texture correctly and the first one doesn't.
Thanks for your help!!!
Shane
----------------------------------------------------------------
Global ScreenWidth = 800
Global ScreenHeight = 600
Global ScreenDepth = 16
Global ScreenMode = 2
Graphics3D ScreenWidth,ScreenHeight,ScreenDepth,ScreenMode
SetBuffer BackBuffer() ; Switch to Back Buffer for Double Buffered drawing.
; Setup the lighting...
AmbientLight 200,200,200
; Setup the texture
ShapeBrush=LoadBrush("c:\my_texture.png")
If ShapeBrush = 0
RuntimeError ("cannot open my_texture.png")
EndIf
; Setup the camera.
Global MainCamera = CreateCamera()
CameraViewport MainCamera,0,0,ScreenWidth,ScreenHeight
WireframeState=0
MoveEntity (MainCamera,10,5,-8)
TurnEntity (MainCamera,0,45,0)
;######################################################################
; Draw Shape
ShapeMesh = CreateMesh()
ShapeSurface = CreateSurface(ShapeMesh)
Restore ShapeData
For VertexLoop=1 To 18
Read TempX
Read TempY
Read TempZ
v4=AddVertex(ShapeSurface,TempX,TempY,TempZ)
VertexTexCoords ShapeSurface, v4,TempX,TempY
Next
For v0 = 0 To 15 Step 3
v1 = v0 + 1
v2 = v1 + 1
AddTriangle(ShapeSurface,v0,v1,v2)
AddTriangle(ShapeSurface,v2,v1,v0)
Next
PaintMesh (ShapeMesh,ShapeBrush)
;######################################################################
Repeat ; Main Game Loop
UpdateWorld
RenderWorld
ModifyCamera()
;
Flip
Until KeyDown(1) Or Terminate
End
;######################################################################
Function ModifyCamera()
If KeyDown(200) Then
MoveEntity MainCamera,0,0,1
EndIf
If KeyDown(208) Then
MoveEntity MainCamera,0,0,-1
EndIf
If KeyDown(203) Then
TurnEntity MainCamera,0,1.0,0
EndIf
If KeyDown(205) Then
TurnEntity MainCamera,0,-1.0,0
EndIf
If KeyDown(30) Then
TurnEntity MainCamera,1.0,0,0
EndIf
If KeyDown(44) Then
TurnEntity MainCamera,-1.0,0,0
EndIf
If KeyDown(44) Then
TurnEntity MainCamera,-1.0,0,0
EndIf
End Function
;######################################################################
.ShapeData ; x,y,z triplets for triangles
Data 7,1,5,7,0,5,6,0,5
Data 6,1,5,7,1,5,6,0,5
Data 5,1,6,6,1,5,6,0,5
Data 5,1,6,6,0,5,5,0,6
Data 5,1,7,5,1,6,5,0,6
Data 5,0,7,5,1,7,5,0,6
I draw a shape from 6 triangles (it ends up 3 boxes joined together). 2 of the boxes texture correctly, the first one doesn't. Can someone please run the following code and see if they can figure out the problem? Use a 32x32 image of anything to see the problem. It's a problem with the u and v values for the texture, but I can't work out why the other boxes texture correctly and the first one doesn't.
Thanks for your help!!!
Shane
----------------------------------------------------------------
Global ScreenWidth = 800
Global ScreenHeight = 600
Global ScreenDepth = 16
Global ScreenMode = 2
Graphics3D ScreenWidth,ScreenHeight,ScreenDepth,ScreenMode
SetBuffer BackBuffer() ; Switch to Back Buffer for Double Buffered drawing.
; Setup the lighting...
AmbientLight 200,200,200
; Setup the texture
ShapeBrush=LoadBrush("c:\my_texture.png")
If ShapeBrush = 0
RuntimeError ("cannot open my_texture.png")
EndIf
; Setup the camera.
Global MainCamera = CreateCamera()
CameraViewport MainCamera,0,0,ScreenWidth,ScreenHeight
WireframeState=0
MoveEntity (MainCamera,10,5,-8)
TurnEntity (MainCamera,0,45,0)
;######################################################################
; Draw Shape
ShapeMesh = CreateMesh()
ShapeSurface = CreateSurface(ShapeMesh)
Restore ShapeData
For VertexLoop=1 To 18
Read TempX
Read TempY
Read TempZ
v4=AddVertex(ShapeSurface,TempX,TempY,TempZ)
VertexTexCoords ShapeSurface, v4,TempX,TempY
Next
For v0 = 0 To 15 Step 3
v1 = v0 + 1
v2 = v1 + 1
AddTriangle(ShapeSurface,v0,v1,v2)
AddTriangle(ShapeSurface,v2,v1,v0)
Next
PaintMesh (ShapeMesh,ShapeBrush)
;######################################################################
Repeat ; Main Game Loop
UpdateWorld
RenderWorld
ModifyCamera()
;
Flip
Until KeyDown(1) Or Terminate
End
;######################################################################
Function ModifyCamera()
If KeyDown(200) Then
MoveEntity MainCamera,0,0,1
EndIf
If KeyDown(208) Then
MoveEntity MainCamera,0,0,-1
EndIf
If KeyDown(203) Then
TurnEntity MainCamera,0,1.0,0
EndIf
If KeyDown(205) Then
TurnEntity MainCamera,0,-1.0,0
EndIf
If KeyDown(30) Then
TurnEntity MainCamera,1.0,0,0
EndIf
If KeyDown(44) Then
TurnEntity MainCamera,-1.0,0,0
EndIf
If KeyDown(44) Then
TurnEntity MainCamera,-1.0,0,0
EndIf
End Function
;######################################################################
.ShapeData ; x,y,z triplets for triangles
Data 7,1,5,7,0,5,6,0,5
Data 6,1,5,7,1,5,6,0,5
Data 5,1,6,6,1,5,6,0,5
Data 5,1,6,6,0,5,5,0,6
Data 5,1,7,5,1,6,5,0,6
Data 5,0,7,5,1,7,5,0,6