December 04, 2020, 10:34:47 AM

Author Topic: [bb] pixel precise xoffset yoffset of a screenmesh+screentexture by RemiD [ 1+ years ago ]  (Read 658 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : pixel precise xoffset yoffset of a screenmesh+screentexture
Author : RemiD
Posted : 1+ years ago

Description : This shows how to add a pixel precise xoffset or yoffset to a screenmesh+screentexture (useful for fullscreen effects)
related to : <a href="codearcs839e.html?code=3256" target="_blank">http://www.blitzbasic.com/codearcs/codearcs.php?code=3256[/url]
If you want to remove the blured effect on the screenmesh+screentexture, you need to disable bilinear filtering ( see : <a href="../Community/posts477b.html?topic=103591" target="_blank">http://www.blitzbasic.com/Community/posts.php?topic=103591[/url] )


Code :
Code: BlitzBasic
  1. Graphics3D(1000,625,32,2)
  2. InitDX7Hack()
  3. DisableTextureFilters()
  4.  
  5. SeedRnd(MilliSecs())
  6.  
  7. Camera = CreateCamera()
  8. CameraRange(Camera,0.1,100)
  9. CameraClsColor(Camera,000,000,000)
  10.  
  11. Global ThingsCount%
  12. Dim ThingMesh(1000)
  13.  
  14. For n% = 1 To 1000 Step 1
  15.  ThingsCount = ThingsCount + 1
  16.  I% = ThingsCount
  17.  ThingMesh(I) = CreateCube()
  18.  ScaleMesh(ThingMesh(I),1.0/2,1.0/2,1.0/2)
  19.  EntityColor(ThingMesh(I),Rand(025,255),Rand(025,255),Rand(025,255))
  20.  PositionEntity(ThingMesh(I),Rnd(-15,15),Rnd(-15,15),Rnd(-15,15),True)
  21. Next
  22.  
  23. OLight = CreateLight(2)
  24. LightRange(OLight,3.0)
  25. LightColor(OLight,224,224,224)
  26.  
  27. AmbientLight(032,032,032)
  28.  
  29. ScreenMesh = CreateMesh()
  30. Surface = CreateSurface(ScreenMesh)
  31. AddVertex(Surface,-1.0,0.625,0.0)
  32. VertexTexCoords(Surface,0,Float(0)/1024,Float(0)/1024)
  33. AddVertex(Surface,1.0,0.625,0.0)
  34. VertexTexCoords(Surface,1,Float(1000)/1024,Float(0)/1024)
  35. AddVertex(Surface,-1.0,-0.625,0.0)
  36. VertexTexCoords(Surface,2,Float(0)/1024,Float(625)/1024)
  37. AddVertex(Surface,1.0,-0.625,0.0)
  38. VertexTexCoords(Surface,3,Float(1000)/1024,Float(625)/1024)
  39. AddTriangle(Surface,0,1,2)
  40. AddTriangle(Surface,2,1,3)
  41. UpdateNormals(ScreenMesh)
  42. EntityColor(ScreenMesh,255,255,255)
  43. EntityFX(ScreenMesh,1)
  44.  
  45. ScreenTexture = CreateTexture(1024,1024,16+32+256)
  46. SetBuffer(TextureBuffer(ScreenTexture))
  47.  ClsColor(255,255,255)
  48.  Cls()
  49. ;ScaleTexture(ScreenTexture,1.0,1.0)
  50. TextureBlend(ScreenTexture,1)
  51. EntityTexture(ScreenMesh,ScreenTexture)
  52.  
  53. PositionEntity(Camera,0,0,-16,True)
  54.  
  55. Const CScene% = 1
  56. Const CScreen% = 2
  57. Global RenderMode% = CScreen
  58.  
  59. Global XOffset% = 0
  60. Global YOffset% = 0
  61.  
  62. Repeat
  63.  
  64.  MXDiff% = MouseXSpeed()
  65.  MYDiff% = MouseYSpeed()
  66.  MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
  67.  TurnEntity(Camera,MYDiff*0.1,-MXDiff*0.1,0)
  68.  
  69.  If( KeyDown(203)=1 )
  70.   XOffset = XOffset - 1
  71.  Else If( KeyDown(205)=1 )
  72.   XOffset = XOffset + 1
  73.  Else If( KeyDown(208)=1 )
  74.   YOffset = YOffset - 1
  75.  Else If( KeyDown(200)=1 )
  76.   YOffset = YOffset + 1
  77.  EndIf
  78.  
  79. ; If( KeyHit(57)=1 )
  80. ;  If( RenderMode = CScene )
  81. ;   RenderMode = CScreen
  82. ;  Else If( RenderMode = CScreen )
  83. ;   RenderMode = CScene
  84. ;  EndIf
  85. ; EndIf
  86.  
  87.  PositionRotateEntityLikeOtherEntity(ScreenMesh,Camera)
  88.  MoveEntity(ScreenMesh,1.0/Float(1000)*2*XOffset,0.625/Float(625)*2*YOffset,1.0)
  89.  
  90.  WireFrame(False)
  91.  If( KeyDown(2)=1 )
  92.   WireFrame(True)
  93.  EndIf
  94.  
  95.  If( RenderMode = CScene )
  96.  
  97.   For I% = 1 To ThingsCount Step 1
  98.    ShowEntity(ThingMesh(I))
  99.   Next
  100.   HideEntity(ScreenMesh)
  101.   SetBuffer(BackBuffer())
  102.   RenderWorld()
  103.  
  104.   Color(255,255,255)
  105.   CText("RenderMode = Scene",0,0)
  106.  
  107.  Else If( RenderMode = CScreen )
  108.  
  109.   For I% = 1 To ThingsCount Step 1
  110.    ShowEntity(ThingMesh(I))
  111.   Next
  112.   HideEntity(ScreenMesh)
  113.   SetBuffer(BackBuffer())
  114.   RenderWorld()
  115.   CopyRect(0,0,GraphicsWidth(),GraphicsHeight(),0,0,BackBuffer(),TextureBuffer(ScreenTexture))
  116.  
  117.   For I% = 1 To ThingsCount Step 1
  118.    HideEntity(ThingMesh(I))
  119.   Next
  120.   ShowEntity(ScreenMesh)
  121.   SetBuffer(BackBuffer())
  122.   RenderWorld()
  123.  
  124.   Color(255,255,255)
  125.   CText("RenderMode = ScreenMesh+ScreenTexture",0,0)
  126.   CText("XOffset = "+XOffset,0,15)
  127.   CText("YOffset = "+YOffset,0,30)
  128.  
  129.  EndIf
  130.  
  131.  Flip(1)
  132.  
  133. Until( KeyDown(1)=1 )
  134.  
  135. End()
  136.  
  137. Const D3DTSS_MAGFILTER      = 16
  138. Const D3DTSS_MINFILTER      = 17
  139. Const D3DTSS_MIPFILTER      = 18
  140. Const D3DTSS_MIPMAPLODBIAS  = 19
  141. Const D3DTSS_MAXMIPLEVEL    = 20
  142.  
  143. Const D3DTFG_POINT        = 1
  144. Const D3DTFG_LINEAR       = 2
  145. Const D3DTFP_NONE         = 1
  146. Const D3DTFN_POINT        = 1
  147. Const D3DTFN_LINEAR       = 2
  148.  
  149. Function InitDX7Hack()
  150.         DX7DBF_SetSystemProperties( SystemProperty("Direct3D7"), SystemProperty("Direct3DDevice7"), SystemProperty("DirectDraw7"), SystemProperty("AppHWND"), SystemProperty("AppHINSTANCE") )
  151. End Function
  152.  
  153. Function DisableTextureFilters()
  154.         ;DX7DBF_SetMipmapLODBias( -10.0, 0 )
  155.         For Level = 0 To 7
  156.                 DX7DBF_SetTextureStageState( Level, D3DTSS_MAGFILTER, D3DTFG_POINT )
  157.                 DX7DBF_SetTextureStageState( Level, D3DTSS_MINFILTER, D3DTFN_POINT )
  158.                 DX7DBF_SetTextureStageState( Level, D3DTSS_MIPFILTER, D3DTFP_NONE  )
  159.         Next
  160. End Function
  161.  
  162. Function CText(TextStr$,PX%,PY%)
  163.  Text(PX,PY,TextStr,False,False)
  164. End Function
  165.  
  166. Function PositionEntityLikeOtherEntity(Entity,OEntity)
  167.  PositionEntity(Entity,EntityX(OEntity,True),EntityY(OEntity,True),EntityZ(OEntity,True),True)
  168. End Function
  169.  
  170. Function RotateEntityLikeOtherEntity(Entity,OEntity)
  171.  RotateEntity(Entity,EntityPitch(OEntity,True),EntityYaw(OEntity,True),EntityRoll(OEntity,True),True)
  172. End Function
  173.  
  174. Function PositionRotateEntityLikeOtherEntity(Entity,OEntity)
  175.  PositionEntity(Entity,EntityX(OEntity,True),EntityY(OEntity,True),EntityZ(OEntity,True),True)
  176.  RotateEntity(Entity,EntityPitch(OEntity,True),EntityYaw(OEntity,True),EntityRoll(OEntity,True),True)
  177. End Function


Comments :


RustyKristi(Posted 11 months ago)

 Hi RemiD,Just saw this code as you suggested but I'm not sure if you are aware of this error..
Code: [Select]
Function 'dx7dbf_setsystemproperties' not foundThanks.


RemiD(Posted 10 months ago)

 Reread the description...You need to use the external lib to desactivate bilinear filtering...But you can use the same code with bilinear filtering activated, here :
Code: [Select]
Graphics3D(1000,625,32,2)

SeedRnd(MilliSecs())

Camera = CreateCamera()
CameraRange(Camera,0.1,100)
CameraClsColor(Camera,000,000,000)

Global ThingsCount%
Dim ThingMesh(1000)

For n% = 1 To 1000 Step 1
 ThingsCount = ThingsCount + 1
 I% = ThingsCount
 ThingMesh(I) = CreateCube()
 ScaleMesh(ThingMesh(I),1.0/2,1.0/2,1.0/2)
 EntityColor(ThingMesh(I),Rand(025,255),Rand(025,255),Rand(025,255))
 PositionEntity(ThingMesh(I),Rnd(-15,15),Rnd(-15,15),Rnd(-15,15),True)
Next

OLight = CreateLight(2)
LightRange(OLight,3.0)
LightColor(OLight,224,224,224)

AmbientLight(032,032,032)

ScreenMesh = CreateMesh()
Surface = CreateSurface(ScreenMesh)
AddVertex(Surface,-1.0,0.625,0.0)
VertexTexCoords(Surface,0,Float(0)/1024,Float(0)/1024)
AddVertex(Surface,1.0,0.625,0.0)
VertexTexCoords(Surface,1,Float(1000)/1024,Float(0)/1024)
AddVertex(Surface,-1.0,-0.625,0.0)
VertexTexCoords(Surface,2,Float(0)/1024,Float(625)/1024)
AddVertex(Surface,1.0,-0.625,0.0)
VertexTexCoords(Surface,3,Float(1000)/1024,Float(625)/1024)
AddTriangle(Surface,0,1,2)
AddTriangle(Surface,2,1,3)
UpdateNormals(ScreenMesh)
EntityColor(ScreenMesh,255,255,255)
EntityFX(ScreenMesh,1)

ScreenTexture = CreateTexture(1024,1024,16+32+256)
SetBuffer(TextureBuffer(ScreenTexture))
 ClsColor(255,255,255)
 Cls()
;ScaleTexture(ScreenTexture,1.0,1.0)
TextureBlend(ScreenTexture,1)
EntityTexture(ScreenMesh,ScreenTexture)

PositionEntity(Camera,0,0,-16,True)

Const CScene% = 1
Const CScreen% = 2
Global RenderMode% = CScreen

Global XOffset% = 0
Global YOffset% = 0

Repeat

 MXDiff% = MouseXSpeed()
 MYDiff% = MouseYSpeed()
 MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
 TurnEntity(Camera,MYDiff*0.1,-MXDiff*0.1,0)

 If( KeyDown(203)=1 )
  XOffset = XOffset - 1
 Else If( KeyDown(205)=1 )
  XOffset = XOffset + 1
 Else If( KeyDown(208)=1 )
  YOffset = YOffset - 1
 Else If( KeyDown(200)=1 )
  YOffset = YOffset + 1
 EndIf

; If( KeyHit(57)=1 )
;  If( RenderMode = CScene )
;   RenderMode = CScreen
;  Else If( RenderMode = CScreen )
;   RenderMode = CScene
;  EndIf
; EndIf

 PositionRotateEntityLikeOtherEntity(ScreenMesh,Camera)
 MoveEntity(ScreenMesh,1.0/Float(1000)*2*XOffset,0.625/Float(625)*2*YOffset,1.0)

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

 If( RenderMode = CScene )

  For I% = 1 To ThingsCount Step 1
   ShowEntity(ThingMesh(I))
  Next
  HideEntity(ScreenMesh)
  SetBuffer(BackBuffer())
  RenderWorld()

  Color(255,255,255)
  CText("RenderMode = Scene",0,0)

 Else If( RenderMode = CScreen )

  For I% = 1 To ThingsCount Step 1
   ShowEntity(ThingMesh(I))
  Next
  HideEntity(ScreenMesh)
  SetBuffer(BackBuffer())
  RenderWorld()
  CopyRect(0,0,GraphicsWidth(),GraphicsHeight(),0,0,BackBuffer(),TextureBuffer(ScreenTexture))

  For I% = 1 To ThingsCount Step 1
   HideEntity(ThingMesh(I))
  Next
  ShowEntity(ScreenMesh)
  SetBuffer(BackBuffer())
  RenderWorld()

  Color(255,255,255)
  CText("RenderMode = ScreenMesh+ScreenTexture",0,0)
  CText("XOffset = "+XOffset,0,15)
  CText("YOffset = "+YOffset,0,30)

 EndIf

 Flip(1)

Until( KeyDown(1)=1 )

End()

Function CText(TextStr$,PX%,PY%)
 Text(PX,PY,TextStr,False,False)
End Function

Function PositionEntityLikeOtherEntity(Entity,OEntity)
 PositionEntity(Entity,EntityX(OEntity,True),EntityY(OEntity,True),EntityZ(OEntity,True),True)
End Function

Function RotateEntityLikeOtherEntity(Entity,OEntity)
 RotateEntity(Entity,EntityPitch(OEntity,True),EntityYaw(OEntity,True),EntityRoll(OEntity,True),True)
End Function

Function PositionRotateEntityLikeOtherEntity(Entity,OEntity)
 PositionEntity(Entity,EntityX(OEntity,True),EntityY(OEntity,True),EntityZ(OEntity,True),True)
 RotateEntity(Entity,EntityPitch(OEntity,True),EntityYaw(OEntity,True),EntityRoll(OEntity,True),True)
End Function
but since bilinear filtering is activated, the render of the screenmesh+screentexture will be slightly blurred... [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal