Bullet holes added to texture.

Everything related to 3D programming
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Bullet holes added to texture.

Post by DK_PETER »

Hey.

EDIT2:
Third attempt to do bullet holes.

download the file below and unpack the texture folder.
*poof*
Link won't remain permanently since you easily can add images from your own collection.

Save the code below OUTSIDE the texture folder.

Code: Select all

;Something I would find immensely useful: 
;RemoveMaterialLayer(mat, optional LayerNumber)

;Test 3:
;Doing bullet holes...Don't know if this is the right way to do it
;but right now - it was the only thing I could come up with. 
;The bullet holes are now placed correctly...I think
;Added primitive particle to bullet hole
;The zoom function isn't finished since it only moves at the z axis.


;If someone knows a different way to do bullet holes (not sprites or anything)
;I would love to change the texture itself
;Anyway..Let me know if you have a better solution.
;TIA

;Left click - shoot
;right click - zoom
;escape - exit

InitEngine3D()
InitSprite()
InitMouse()
InitKeyboard()

DeclareModule _Holes
  Declare.i SetResolution(Width.i = 1024, Height.i = 768, Title.s = "", FullScreen.i = #False)
  Declare.i RunDemo()
EndDeclareModule

Module _Holes
  
  UsePNGImageDecoder()
  UseJPEGImageDecoder()
  Add3DArchive("texture", #PB_3DArchive_FileSystem)
  
  Declare.i MakeWalls()
  Declare.i MakeScope()
  Declare.i MakePart(x.i, y.i, z.i)
  Declare.i MakeHole(x.i, y.i, z.i)
  
  Structure _Mesh
    id.i
    ms.i
    ma.i
    hole.i[2]
    tex.i
    im.i
    tx2.i
  EndStructure
  
  Structure _Par
    id.i
    tx.i
    ma.i
  EndStructure
  
  Structure _vars
    Scope.i
    Coords.i
    Zoom.f
    Fs.i
    Win.i
    Cam.i
    Shot.i
    par.i
    parem.i
  EndStructure
  
  Global Fs.i = False
  Global va._vars
  Global wall._Mesh
  Global pa._Par
  Global gpoint.POINT
  
  Procedure.i SetResolution(Width.i = 1024, Height.i = 768, Title.s = "", FullScreen.i = #False)
    va\Fs = FullScreen
    If FullScreen = #False
      va\Win = OpenWindow(#PB_Any, 0, 0, Width, Height, Title, #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
      Scr = OpenWindowedScreen(WindowID(va\Win), 0 ,0 , Width, Height, #False, 0, 0, #PB_Screen_SmartSynchronization)
    Else
      Scr = OpenScreen(1024, 768, 32, Title,#PB_Screen_SmartSynchronization, 60)
    EndIf
    va\Cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
    MoveCamera(va\Cam, 0, 0, 0)
    va\Zoom = #False
  EndProcedure  
  
  Procedure.i MakeScope()
    Protected w.i = ScreenWidth(), h.i = ScreenHeight(), Rest.i
    va\Coords = CreateSprite(#PB_Any, 300, 50)
    Rest = (ScreenWidth()/2-ScreenHeight()/2)+52
    va\Scope = CreateSprite(#PB_Any,w, h)
    StartDrawing(SpriteOutput(va\Scope))
    Box(0, 0, ScreenWidth(), ScreenHeight(), $1)
    Circle(w/2,h/2,h/2-30,$555353)
    Circle(w/2,h/2,h/2-51, $FFF251)
    LineXY(w/2, 52, w/2, h/3, $555251)
    For y = 53 To h/3 Step 4
      LineXY(w/2-5, y, w/2+5,y, $555251)
    Next y
    LineXY(w/2, h-52, w/2, h-h/3, $555251)
    For y = h-52 To h-h/3 Step -4
      LineXY(w/2-5, y, w/2+5,y, $555251)
    Next y
    LineXY(Rest, h/2, Rest+w/4, h/2, $555251)
    For x = Rest To  (Rest+w/4) Step 4
      LineXY(x, (h/2)-5, x,(h/2)+5, $555251)
    Next x
    LineXY(w-Rest, h/2, (w/2-Rest) + w/4, h/2, $555251)
    For x = (w-Rest) To (w-Rest)-w/4  Step -4
      LineXY(x, (h/2)-5, x,(h/2)+5, $555251)
    Next x
    Circle(w/2,h/2, 2,$555251)
    StopDrawing()
    TransparentSpriteColor(va\Scope, $FFF251)
  EndProcedure
  
  Procedure.i MakeWalls()
    Protected tmptx.i
    wall\im      = LoadImage(#PB_Any, "texture\man2.jpg")
    ResizeImage(wall\im, 60, 100,#PB_Image_Smooth)
    tmptx = CreateTexture(#PB_Any, 1024, 1024)
    StartDrawing(TextureOutput(tmptx))
    DrawingMode(#PB_2DDrawing_AllChannels)
    For x = 0 To 1024 Step 80
      For y = 0 To 1024 Step 105
        DrawImage(ImageID(wall\im), x, y)
      Next y
    Next x
    StopDrawing()
    wall\hole[0] = LoadImage(#PB_Any, "texture\1a.jpg")
    wall\hole[1] = LoadImage(#PB_Any, "texture\2a.jpg")
    wall\tex     = LoadTexture(#PB_Any, "glass_grey.jpg")
    wall\ma      = CreateMaterial(#PB_Any, TextureID(wall\tex))
    MaterialBlendingMode(wall\ma, #PB_Material_Add)
    AddMaterialLayer(wall\ma, TextureID(tmptx), #PB_Material_Color)
    MaterialFilteringMode(wall\ma, #PB_Material_Anisotropic, 8)
    wall\ms = CreatePlane(#PB_Any, 1024, 1024, 1, 1, 1, 1)
    wall\id = CreateEntity(#PB_Any, MeshID(wall\ms), MaterialID(wall\ma), 0, 0, -450)
    RotateEntity(wall\id, 90, 0, 180)
  EndProcedure
  
  Procedure.i MakePart(x.i, y.i, z.i)
    pa\id = CreateParticleEmitter(#PB_Any, 15,15,200,#PB_Particle_Point, x, y, z)
    pa\tx = CreateTexture(#PB_Any,10,10)
    StartDrawing(TextureOutput(pa\tx))
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    Box(2,2,4,3, $C2F0B4A8)
    Box(6,7,2,1, $C2F0B4A8)
    StopDrawing()
    pa\ma = CreateMaterial(#PB_Any, TextureID(pa\tx))
    MaterialBlendingMode(pa\ma, #PB_Material_Add)
    ParticleEmissionRate(pa\id, 309)
    ParticleEmitterDirection(pa\id, 0, 0, 1)
    ParticleMaterial(pa\id, MaterialID(pa\ma))
    ParticleSize(pa\id, 10,10)
    ParticleTimeToLive(pa\id, 0.2, 0.9)
    ParticleVelocity(pa\id, 400, 500)
    ParticleSpeedFactor(pa\id, 5.3)
  EndProcedure
  
  Procedure.i MakeHole(x.i, y.i, z.i)
    Protected Thehole.i, tx.i, ty.i
    
    If Random(100,0) < 50
      Thehole = 0
    Else
      Thehole = 1
    EndIf
    If IsTexture(wall\tx2)
      FreeTexture(wall\tx2)
    EndIf
    wall\tx2 = CreateTexture(#PB_Any, 1024, 1024)
    StartDrawing(TextureOutput(wall\tx2))
    If x < 0
      tx = 512 - Abs(x) ;(x * -1)
    Else
      tx =  512+x
    EndIf
    
    If y < 0
      ty =  512 + Abs(y) ;(y * -1)
    Else
      ty =  512-y
    EndIf
     
    DrawImage(ImageID(wall\hole[Thehole]),tx-ImageWidth(wall\hole[Thehole])/2,ty-ImageHeight(wall\hole[Thehole])/2)
    StopDrawing()
    AddMaterialLayer(wall\ma, TextureID(wall\tx2) , #PB_Material_Color)
    ;     
    StartDrawing(SpriteOutput(va\Coords))
    Box(0,0,300, 50, $1)
    DrawText(0, 0, "x = " + Str(tx) + "  y = " + Str(ty) + "  z = " + Str(z), $50B4A8)
    StopDrawing()
  
  EndProcedure
  
  Procedure.i RunDemo()
    MakeScope()
    MakeWalls()

    va\Zoom = 0
    va\Shot = 0
    va\par  = 0
    va\parem = 500
    gpoint\x = 0
    gpoint\y = 0
    
    Repeat
      
      If va\Fs = #False
        Repeat
          ev = WindowEvent()
        Until ev = 0
      EndIf
      
      ExamineMouse()
      
      If MouseButton(#PB_MouseButton_Right) = 1 And va\Zoom > -320
        va\Zoom - 10
      ElseIf MouseButton(#PB_MouseButton_Right) = 0 And va\Zoom < 0
        va\Zoom + 10
      EndIf
      If MouseButton(#PB_MouseButton_Left) = 1 And va\Shot = 0
        ;Bang
        ret = MousePick(va\Cam, ScreenWidth()/2, ScreenHeight()/2, #PB_Ignore)
        If ret
          va\parem = ElapsedMilliseconds()
          va\par = 1
          MakeHole(PickX(),PickY(), PickZ())
          MakePart(PickX(),PickY(), PickZ())
        EndIf
        va\Shot = 1
      ElseIf MouseButton(#PB_MouseButton_Left) = 0 And va\Shot = 1
        va\Shot = 0
      EndIf
      If va\par = 1 And ElapsedMilliseconds()-va\parem > 100
        If IsParticleEmitter(pa\id)
          FreeParticleEmitter(pa\id)
          FreeMaterial(pa\ma)
          FreeTexture(pa\tx)
        EndIf
        va\par = 0
      EndIf
      MoveCamera(va\Cam, 0, 0, va\Zoom, #PB_Absolute)
      RotateCamera(va\Cam, -MouseDeltaY() * 0.03 , -MouseDeltaX() * 0.03, 0,#PB_Relative)
      ExamineKeyboard()
      
      RenderWorld()
      
      DisplayTransparentSprite(va\Scope, 0, 0)
      DisplaySprite(va\Coords, 0,0)
      FlipBuffers()
      
    Until KeyboardPushed(#PB_Key_Escape)
    
  EndProcedure
  
EndModule


_Holes::SetResolution(1024, 768, "Sniper")
_Holes::RunDemo()
Last edited by DK_PETER on Tue Oct 21, 2014 6:39 pm, edited 2 times in total.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Bullet holes added to texture.

Post by DK_PETER »

Updated first post.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Bullet holes added to texture.

Post by Kwai chang caine »

Waooouh !! cool i like it :D
Works very well !!
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: Bullet holes added to texture.

Post by Bananenfreak »

Nice work, DK_Peter!

But is there only one bullethole possible? What about 20 or more?
Image
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Bullet holes added to texture.

Post by DK_PETER »

Kwai chang caine wrote:Waooouh !! cool i like it :D
Works very well !!
Thanks for sharing 8)
:wink:

Here's test 5. I've solved it and it works as it should now.
Test 5 requires the file below, since I've added sounds ---- Just for the fun of it.
Link will dissappear soon, since you can add your own sound and images to the code.
*pliiing*

Have fun.

Code: Select all

;Test 5: 
;I think this is the best way to do it.
;Now we use transparent pngs.
;Redraws the entire material for each bullet hole and
;gathers the hole data (repaints them) from a linked list.
;This one has a lot of nice advantages..
;1. The linked list keeps track of bullet holes
;2. Everything is kept inside one extra layer
;3. No memory leaks and the sky's the limit.
;Added sounds to this test

;Doing bullet holes..A bit messy code, but what the heck..It's test 5.


;Left click - shoot
;right click - zoom
;escape - exit

InitEngine3D()
InitSprite()
InitMouse()
InitKeyboard()

DeclareModule _Holes
  Declare.i SetResolution(Width.i = 1024, Height.i = 768, Title.s = "", FullScreen.i = #False)
  Declare.i RunDemo()
EndDeclareModule

Module _Holes
  
  UsePNGImageDecoder()
  UseJPEGImageDecoder()
  UseOGGSoundDecoder()
  Add3DArchive("texture", #PB_3DArchive_FileSystem)
  
  Declare.i MakeWall()
  Declare.i MakeScope()
  Declare.i MakePart(x.i, y.i, z.i)
  Declare.i MakeHole(x.i, y.i, z.i)
  Declare.i MakeSprites()
  Declare.i ShowSprites()
  Declare.i LoadResources()
  
  Structure _Mesh
    id.i
    ms.i
    ma.i
    hole.i[2]
    tex.i
    NewLayer.i
    ManLayer.i
    glassLayer.i
    man.i
  EndStructure
  
  Structure _Par
    id.i
    tx.i
    ma.i
  EndStructure
  
  Structure _holes
    x.i
    y.i
    id.i
  EndStructure
  
  Structure _Spr
    Scope.i
    layer.i
    mem.i
    Coords.i
  EndStructure
  
  Structure _vars
    Zoom.f
    Fs.i
    Win.i
    Cam.i
    Shot.i
    par.i
    parem.i
    sp._Spr
    lgt.i
    shootsound.i
    shattersound.i
  EndStructure
  
  Global Fs.i = False
  Global va._vars
  Global wall._Mesh
  Global pa._Par
  Global NewList hol._holes()
  Global GoodSound.i = #True
  
  Procedure.i SetResolution(Width.i = 1024, Height.i = 768, Title.s = "", FullScreen.i = #False)
    va\Fs = FullScreen
    If FullScreen = #False
      va\Win = OpenWindow(#PB_Any, 0, 0, Width, Height, Title, #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
      Scr = OpenWindowedScreen(WindowID(va\Win), 0 ,0 , Width, Height, #False, 0, 0, #PB_Screen_SmartSynchronization)
    Else
      Scr = OpenScreen(1024, 768, 32, Title,#PB_Screen_SmartSynchronization, 60)
    EndIf
    va\Cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
    MoveCamera(va\Cam, 0, 0, 0)
    va\Zoom = #False
    va\lgt = CreateLight(#PB_Any, $FFFFFF, 0, 0, 0, #PB_Light_Directional)
    LightDirection(va\lgt, 0, 0, -1)
  EndProcedure  
  
  Procedure.i MakeScope()
    Protected w.i = ScreenWidth(), h.i = ScreenHeight(), Rest.i
    va\sp\Coords = CreateSprite(#PB_Any, 300, 50)
    Rest = (ScreenWidth()/2-ScreenHeight()/2)+52
    va\sp\Scope = CreateSprite(#PB_Any,w, h)
    StartDrawing(SpriteOutput(va\sp\Scope))
    Box(0, 0, ScreenWidth(), ScreenHeight(), $1)
    Circle(w/2,h/2,h/2-30,$555353)
    Circle(w/2,h/2,h/2-51, $FFF251)
    LineXY(w/2, 52, w/2, h/3, $555251)
    For y = 53 To h/3 Step 4
      LineXY(w/2-5, y, w/2+5,y, $555251)
    Next y
    LineXY(w/2, h-52, w/2, h-h/3, $555251)
    For y = h-52 To h-h/3 Step -4
      LineXY(w/2-5, y, w/2+5,y, $555251)
    Next y
    LineXY(Rest, h/2, Rest+w/4, h/2, $555251)
    For x = Rest To  (Rest+w/4) Step 4
      LineXY(x, (h/2)-5, x,(h/2)+5, $555251)
    Next x
    LineXY(w-Rest, h/2, (w/2-Rest) + w/4, h/2, $555251)
    For x = (w-Rest) To (w-Rest)-w/4  Step -4
      LineXY(x, (h/2)-5, x,(h/2)+5, $555251)
    Next x
    Circle(w/2,h/2, 2,$555251)
    StopDrawing()
    TransparentSpriteColor(va\sp\Scope, $FFF251)
  EndProcedure
  
  Procedure.i MakeWall()
    Protected tmptx.i
    wall\ma      = CreateMaterial(#PB_Any, TextureID(wall\tex))
    MaterialBlendingMode(wall\ma, #PB_Material_Add)
    MaterialFilteringMode(wall\ma, #PB_Material_Anisotropic, 8)
    wall\ms = CreatePlane(#PB_Any, 1024, 1024, 1, 1, 1, 1)
    wall\id = CreateEntity(#PB_Any, MeshID(wall\ms), MaterialID(wall\ma), 0, 0, -450)
    RotateEntity(wall\id, 90, 0, 180)
  EndProcedure
  
  Procedure.i LoadResources()
    If InitSound() = 0
      GoodSound = #False
    EndIf
    wall\man     = LoadImage(#PB_Any, "texture\man.png")
    ResizeImage(wall\Man, 60, 100,#PB_Image_Smooth)
    wall\glassLayer = LoadImage(#PB_Any, "texture\glass_grey.jpg")
    wall\ManLayer = CreateImage(#PB_Any, 1024,1024,32,#PB_Image_Transparent)
    StartDrawing(ImageOutput(wall\ManLayer))
    DrawImage(ImageID(wall\glassLayer),0,0)
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    For x = 0 To 1024 Step 80
      For y = 0 To 1024 Step 105
        DrawImage(ImageID(wall\man), x, y)
      Next y
    Next x
    StopDrawing()
    wall\hole[0] = LoadImage(#PB_Any, "texture\1a.png")
    wall\hole[1] = LoadImage(#PB_Any, "texture\2a.png")
    wall\tex = CreateTexture(#PB_Any, 1024, 1024)
    StartDrawing(TextureOutput(wall\tex))
    DrawImage(ImageID(wall\ManLayer),0,0)
    StopDrawing()
    If GoodSound = #True
      va\shattersound = LoadSound(#PB_Any, "sound\glass.ogg")
      va\shootsound   = LoadSound(#PB_Any, "sound\shot.wav")
    EndIf
  EndProcedure
  
  Procedure.i MakePart(x.i, y.i, z.i)
    pa\id = CreateParticleEmitter(#PB_Any, 15,15,200,#PB_Particle_Point, x, y, z)
    pa\tx = CreateTexture(#PB_Any,10,10)
    StartDrawing(TextureOutput(pa\tx))
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    Box(2,2,4,3, $C2F0B4A8)
    Box(6,7,2,2, $C2F0B4A8)
    StopDrawing()
    pa\ma = CreateMaterial(#PB_Any, TextureID(pa\tx))
    MaterialBlendingMode(pa\ma, #PB_Material_Add)
    ParticleEmissionRate(pa\id, 309)
    ParticleEmitterDirection(pa\id, 0, 0, 1)
    ParticleMaterial(pa\id, MaterialID(pa\ma))
    ParticleSize(pa\id, 10,10)
    ParticleTimeToLive(pa\id, 0.2, 0.9)
    ParticleVelocity(pa\id, 400, 500)
    ParticleSpeedFactor(pa\id, 5.3)
  EndProcedure
  
  Procedure.i MakeHole(x.i, y.i, z.i)
    Protected Thehole.i, tx.i, ty.i
    RemoveMaterialLayer(wall\ma)
    FreeMaterial(wall\ma)  
    
    wall\ma = CreateMaterial(#PB_Any, TextureID(wall\tex))    
    If IsTexture(wall\NewLayer) = 0
      wall\NewLayer = CreateTexture(#PB_Any, 1024, 1024)
    EndIf
    If ListSize(hol()) > 9 ;No more than 10 holes
      FirstElement(hol())
      DeleteElement(hol(),1)
      LastElement(hol())
      AddElement(hol())
    Else
      AddElement(hol()) 
    EndIf
    
    If Random(100,0) < 50
      hol()\id = 0
    Else
      hol()\id = 1
    EndIf
    
    If x < 0
      hol()\x =  512 - Abs(x) ;(x * -1)
    Else
      hol()\x =  512+x
    EndIf
    
    If y < 0
      hol()\y =  512 + Abs(y) ;(y * -1)
    Else
      hol()\y =  512-y
    EndIf
    
    StartDrawing(TextureOutput(wall\NewLayer))
    Box(0,0,1024,1024,$0)  ;Rem this line to see ALL bullet holes made...
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    ForEach hol()
      DrawImage(ImageID(wall\hole[hol()\id]), hol()\x-ImageWidth(wall\hole[hol()\id])/2, hol()\y-ImageHeight(wall\hole[hol()\id])/2)
    Next 
    StopDrawing()
    AddMaterialLayer(wall\ma, TextureID(wall\NewLayer) , #PB_Material_Color)
    SetEntityMaterial(wall\id, MaterialID(wall\ma))
    StartDrawing(SpriteOutput(va\sp\Coords))
    Box(0,0,300, 50, $1)
    DrawText(0, 0, "x = " + Str(tx) + "  y = " + Str(ty) + "  z = " + Str(z), $50B4A8)
    StopDrawing()
  EndProcedure
  
  Procedure.i MakeSprites()
    va\sp\mem = CreateSprite(#PB_Any, 300, 20)
    StartDrawing(SpriteOutput(va\sp\mem))
    Box(0, 0, 300,20, $1)
    DrawText(0, 0, "Used mem: " + Str(MemoryStatus(#PB_System_FreePhysical)), $FFFFFF)
    StopDrawing()
    va\sp\layer = CreateSprite(#PB_Any, 300,20)
  EndProcedure
  
  Procedure.i ShowSprites()
    DisplayTransparentSprite(va\sp\Scope, 0, 0)
    DisplaySprite(va\sp\Coords, 0,0)
    StartDrawing(SpriteOutput(va\sp\mem))
    Box(0, 0, 300, 20, $1)
    DrawText(0, 0, "Used mem: " + Str(MemoryStatus(#PB_System_FreePhysical)/1024) + " kb.", $FFFFFF,0)
    StopDrawing()
    DisplaySprite(va\sp\mem, 0, ScreenHeight()-40)
    StartDrawing(SpriteOutput(va\sp\layer))
    DrawText(0, 0, "Number of layers: " + Str(CountMaterialLayers(wall\ma)) + " ListCount; " + Str(ListSize(hol())), $FFFFFF,0)
    StopDrawing()
    DisplaySprite(va\sp\layer, ScreenWidth()-300, ScreenHeight()-40)
    StopDrawing()
  EndProcedure
  
  Procedure.i RunDemo()
    LoadResources()
    MakeScope()
    MakeWall()
    MakeSprites()
    
    va\Zoom = 0
    va\Shot = 0
    va\par  = 0
    va\parem = 500
    
    Repeat
      
      If va\Fs = #False
        Repeat
          ev = WindowEvent()
        Until ev = 0
      EndIf
      
      ExamineMouse()
      
      If MouseButton(#PB_MouseButton_Right) = 1 And va\Zoom > -320
        va\Zoom - 10
      ElseIf MouseButton(#PB_MouseButton_Right) = 0 And va\Zoom < 0
        va\Zoom + 10
      EndIf
      If MouseButton(#PB_MouseButton_Left) = 1 And va\Shot = 0
        ;Bang
        ret = MousePick(va\Cam, ScreenWidth()/2, ScreenHeight()/2, #PB_Ignore)
        If ret
          va\parem = ElapsedMilliseconds()
          va\par = 1
          MakeHole(PickX(),PickY(), PickZ())
          MakePart(PickX(),PickY(), PickZ())
        EndIf
        If GoodSound = #True
          PlaySound(va\shootsound)
        EndIf
        va\Shot = 1
      ElseIf MouseButton(#PB_MouseButton_Left) = 0 And va\Shot = 1
        va\Shot = 0
      EndIf
      If va\par = 1 And ElapsedMilliseconds()-va\parem > 100
        If IsParticleEmitter(pa\id)
          FreeParticleEmitter(pa\id)
          FreeMaterial(pa\ma)
          FreeTexture(pa\tx)
        EndIf
        If GoodSound = #True
          PlaySound(va\shattersound)
        EndIf
        va\par = 0
      EndIf
      MoveCamera(va\Cam, 0, 0, va\Zoom, #PB_Absolute)
      RotateCamera(va\Cam, -MouseDeltaY() * 0.03 , -MouseDeltaX() * 0.03, 0,#PB_Relative)
      ExamineKeyboard()
      
      If KeyboardReleased(#PB_Key_Space)
        ResetMaterial(#PB_Entity)
      EndIf
      RenderWorld()
      ShowSprites()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape)
    
  EndProcedure
 
EndModule
_Holes::SetResolution(1024, 768, "Sniper")
_Holes::RunDemo()
Last edited by DK_PETER on Fri Oct 24, 2014 12:38 pm, edited 1 time in total.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Bullet holes added to texture.

Post by applePi »

thanks DK_PETER for the example, i am beginnig to read about materials from about a week, i hope Comtois add more options to the AddMaterialLayer such as these listed here http://www.ogre3d.org/forums/viewtopic. ... hilit=glsl
http://web.archive.org/web/201005070220 ... l-shaders/
have you noticed that you have used #PB_Material_Color in
AddMaterialLayer(wall\ma, TextureID(wall\NewLayer) , #PB_Material_Color)
even it is not listed in the options for AddMaterialLayer in the help file in PB 5.31 b3 .
its value is 4
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Bullet holes added to texture.

Post by DK_PETER »

applePi wrote:have you noticed that you have used #PB_Material_Color in
AddMaterialLayer(wall\ma, TextureID(wall\NewLayer) , #PB_Material_Color)
even it is not listed in the options for AddMaterialLayer in the help file in PB 5.31 b3 .
its value is 4
You're absolute right. It's funny...I hadn't even noticed it myself, I simply...just...used it. :)
It does work though..An alternative is using #PB_Material_Add.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Post Reply