Graphics3D(800,600,32,2)

;initialize DX7 lib
InitDX7()

;disable bilinear filtering
DisableTextureFilters()

Origine = CreateCube()
ScaleMesh(Origine,0.01/2,0.01/2,0.01/2)

Global Camera = CreateCamera()
CameraRange(Camera,0.1,1000)
CameraClsColor(Camera,000,000,000)

TMesh = CreateMesh()
Surface = CreateSurface(TMesh)
AddVertex(Surface, 0.0, 0.0, 10.0, 0.000, 0.000)
AddVertex(Surface, 10.0, 0.0, 10.0, 100.0/128, 0.000)
AddVertex(Surface, 0.0, 0.0, 0.0, 0.000, 100.0/128)
AddVertex(Surface, 10.0, 0.0, 0.0, 100.0/128, 100.0/128)
AddTriangle(Surface,0,1,2)
AddTriangle(Surface,2,1,3)
UpdateNormals(TMesh)
 
TImage = CreateImage(100,100)
SetBuffer(ImageBuffer(TImage))
 ClsColor(000,000,000)
 Cls()
 For i% = 1 To 100
  Color(Rand(025,250),Rand(025,250),Rand(025,250))
  PWidth% = 10
  PHeight% = 10
  PX% = Rand(0+1,100-1-PWidth)
  PY% = Rand(0+1,100-1-PHeight)
  Rect(PX,PY,PWidth,PHeight,0)
  Color(125,125,125)
  Line(0,0,99,0)
  Line(0,99,99,99)
  Line(0,0,0,99)
  Line(99,0,99,99)
 Next
SetBuffer(BackBuffer())

TTexture = CreateTexture(128,128,16+32)
CopyRect(0,0,100,100,0,0,ImageBuffer(TImage),TextureBuffer(TTexture))

TBrush = CreateBrush()
BrushColor(TBrush,255,255,255)
BrushAlpha(TBrush,1.0)
BrushFX(TBrush,1)
BrushTexture(TBrush,TTexture)
PaintSurface(GetSurface(TMesh,1),TBrush)
FreeBrush(TBrush)

PositionEntity(Camera,5,5,-2.5)
RotateEntity(Camera,45,0,0)

While(KeyDown(1)<>1)

 If(KeyDown(2)=1)
  WireFrame(True)
 Else
  WireFrame(False)
 EndIf

 SetBuffer(BackBuffer())
 RenderWorld()

 DrawImage(TImage,0,0)

 Color(250,250,250)
 Text(0,0,"Triangles = "+Str(TrisRendered()))
 TextStr$ = "The texture looks sharp ! Same than the image !"
 Text(GraphicsWidth()/2-StringWidth(TextStr)/2,0,TextStr)

 Flip(1) 

Wend

End

Function InitDX7()

	DX7_SetSystemProperties( SystemProperty("Direct3D7"), SystemProperty("Direct3DDevice7"), SystemProperty("DirectDraw7"), SystemProperty("AppHWND"), SystemProperty("AppHINSTANCE") )

End Function

Function DisableTextureFilters()

 D3DTSS_MAGFILTER      = 16
 D3DTSS_MINFILTER      = 17
 D3DTSS_MIPFILTER      = 18
 D3DTSS_MIPMAPLODBIAS  = 19
 D3DTSS_MAXMIPLEVEL    = 20

 D3DTFG_POINT        = 1
 D3DTFG_LINEAR       = 2
 D3DTFP_NONE         = 1
 D3DTFN_POINT        = 1
 D3DTFN_LINEAR       = 2

 ;DX7_SetMipmapLODBias( -10.0, 0 )
 For Level = 0 To 7
  DX7_SetTextureStageState( Level, D3DTSS_MAGFILTER, D3DTFG_POINT )
  DX7_SetTextureStageState( Level, D3DTSS_MINFILTER, D3DTFN_POINT )
  DX7_SetTextureStageState( Level, D3DTSS_MIPFILTER, D3DTFP_NONE  )
 Next
	
End Function