Making a Sprite Glow?

Advanced game related topics
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Making a Sprite Glow?

Post by DriakTravo »

Is there a way to make a sprite glow without slowing the program down much?
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Make 2 sprites...

One simple and another with and outlined glow (yellow).... :D
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post by Codemonger »

the fastest would be to create a glow effect around the sprite with a series of animated sprites ... like these:

Image
Image
Image

the glow sprites would be alphablended and rendered first then the main object sprite would be rendered on top of the glow .. the glow sprites would be animated through the sequence. Although their isn't much frames the effect looks just fine and is fairly simple.
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

Thanks. These are great Ideas. The only problem is that you need to have a solid color background for these ideas to work. Because under the glow would be black if you had a textured background. This is why I need a way to do real-time glowing.
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

the glow sprites would be alphablended
I believe this implies that the glow sprites would have per-pixel alpha information that would treat the black (in this example) as 100% transparent and the white as mostly opaque....grays would be in-between...
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post by Codemonger »

This might help a bit, I whipped this up tonight. Heres a link to download the file with images included in exe as binaries

http://codemonger.com/uploads/CodeBlend.exe

heres the code .. uncommented as i just threw it together quickly... Also you could change the sprite3dblendmode to get some cool effects. Anyway hope this helps :wink:

Code: Select all



Result = OpenWindow(0, 100, 200, 400, 400, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "Codemonger Blend Test")

 
UseJPEGImageDecoder() 

InitSprite()
InitSprite3D() 


OpenWindowedScreen(Result, 0, 0, 400, 400, AutoStretch, 0, 0)
CatchSprite(0, ?CodemongerLogo,#PB_Sprite_Texture)  
CatchSprite(1, ?RightArrow) 
CatchSprite(2, ?RightGlow1,#PB_Sprite_Texture) 
CatchSprite(3, ?RightGlow2,#PB_Sprite_Texture) 
CatchSprite(4, ?RightGlow3,#PB_Sprite_Texture) 
CatchSprite(5, ?RightGlow4,#PB_Sprite_Texture) 


CreateSprite3D(0, 0) 
 
CreateSprite3D(2, 2) 
CreateSprite3D(3, 3) 
CreateSprite3D(4, 4) 
CreateSprite3D(5, 5) 

 GlowVar = 2
 GlowMod = 1
 


  Repeat
    
    
    XOffset = WindowMouseX() - 11
    YOffset = WindowMouseY() - 13
   
    
    If CurrentTime - OldTime > 50
      OldTime = CurrentTime
      GlowVar = GlowVar + GlowMod
    EndIf
    
     Start3D()      
       ZoomSprite3D(0, 400, 400) 
       Sprite3DQuality(1)
       DisplaySprite3D(0,0,0,255)
       
       Sprite3DQuality(0)
       Sprite3DBlendingMode(5, 7)
  
       If GlowVar <> 1 
         DisplaySprite3D(GlowVar, -18+XOffset, -13+YOffset,255)          
       EndIf
    Stop3D()
     
     

    Select GlowVar
      Case 5
        GlowMod = -1
      Case 1
        GlowMod = 1
    EndSelect
     
       DisplayTransparentSprite(1,XOffset,YOffset) 
       FlipBuffers() 

        CurrentTime = timeGetTime_()
        FPS = FPS + 1
        If CurrentTime-OldFPSTime => 1000            
          FPSCount = FPS 
          FPS = 0
          OldFPSTime = timeGetTime_()                  
        EndIf
        
        StartDrawing(WindowOutput())
          DrawText("FPS: " + Str(FPSCount)) 
        StopDrawing()
       
     
        
       EventID.l = WindowEvent()


     


   
   
  Until EventID = #PB_Event_CloseWindow 




End 
  
CodemongerLogo: IncludeBinary "CodemongerLogo.bmp"
RightGlow1: IncludeBinary "RightGlow1.jpg"
RightGlow2: IncludeBinary "RightGlow2.jpg"
RightGlow3: IncludeBinary "RightGlow3.jpg"
RightGlow4: IncludeBinary "RightGlow4.jpg"
RightArrow: IncludeBinary "RightArrow.bmp"




<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

Wow! That really helped. Thanks
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post by Codemonger »

If u need any other help, let me know, glad to assist. :)
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

As a token of my thanks, I have created 2 small programs demonstrating what you have tought me about the glow effect. You can download them here:

http://www.1matthew.com/downloads/Samples.zip (about 40KB zipped)

Thanks again! I am going to make a game also using my newly learned glow effect and the ability to includebinary which I also picked up from your code. :D

Image


Image


Image
vanleth
User
User
Posts: 79
Joined: Sat Jun 28, 2003 4:39 am
Location: Denmark - Valby

Post by vanleth »

Cool effect's, and I love pixel exploding space games.

Looking forward to see more. :P
monkeyx
User
User
Posts: 11
Joined: Fri Jul 16, 2004 1:19 pm

Running demos

Post by monkeyx »

:cry: Why is that I have problems getting a lot of example code to run on my machine? I was interested in this product but find that 50% of the game/graphics examples do not work!

I have P4, 512MB ram and Fx5600 card.
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

Here are a few questions I have.

- What version of DirectX are you using?
- Do you have the most recent drivers for your video card?
- What Operating System are you running.
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post by Codemonger »

DriakTravo very cool examples, makes for great plasma or laser effects :!:
Why is that I have problems getting a lot of example code to run on my machine? I was interested in this product but find that 50% of the game/graphics examples do not work!

I have P4, 512MB ram and Fx5600 card.
maybe you need your nvidia graphics drivers updated ... i have a fx5200 and works great here.
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
monkeyx
User
User
Posts: 11
Joined: Fri Jul 16, 2004 1:19 pm

Post by monkeyx »

I have just tried it on my home PC (Athlon 700) and it works fine here. The only difference between the machines is possibly the directx version I have 9.0b at home. I will have check the version number at work.
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post by Codemonger »

If you are having the same or similar problems as monkeyx pls refer to this thread

viewtopic.php?t=11717
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
Post Reply