Screensaver probs
Blitz3D Forums/Blitz3D Programming/Screensaver probs
| ||
The screensaver I made is doing strange things: 1. Every once in awhile it's just a black screen 2. It reverts to the default screensaver sometime 3. It says "Memory Access Violation" sometimes 4. And other times it works fine. Here's the code. Note it's messy and using that clouds system that I forgot the name of. ; -------------------------------------------------------------------------------------------- ; | | ; | Tutorial: How to create a Blitz Screensaver by Grisu v1.00 | ; | | ; | File: "SS_Tutorial1.bb" | ; | | ; -------------------------------------------------------------------------------------------- ; | | ; | This code serves as (empty) base for your Screensaver. | ; | | ; | 1. Simply insert your own program code into "Configure()" or "Start()". | ; | | ; | 2. Compile and rename the executable to "*.scr". | ; | | ; | 3. Copy your Screensaver (& Datafiles) to the Windows Rootfolder. | ; | | ; -------------------------------------------------------------------------------------------- ; | | ; | Known Issues when making Blitz Screensavers: | ; | | ; | - It's impossible to show a preview of your Screensaver inside the Windows Display Box. | ; | | ; | - When starting your Screensaver a small GFX Window might be visible at first. | ; | | ; -------------------------------------------------------------------------------------------- Include "skies.bb" Type ri Field s Field a# Field sp# End Type Type bu Field s End Type AppTitle "Birds" ; The Name of your Screensaver Global m#,rip,sdd,tt#=255.0,ttt,al#=1,at#=0,up,uu,bob Const cloudcount = 440 Dim cloudtex(8) Dim cloudpuff(cloudcount) ChangeDir SystemProperty$("appdir") ; IMPORTANT ; Needed to run your Screensaver under Windows!!!. ; It changes the runtime Dir to where the Screensaver is located. ; Disable it while testing, because "appdir" of Blitz is "\bin". ; else your program might just crash!!! :) ; Checking Parameters that Windows uses for handling Screensavers If CommandLine$() <> "" Then ; If Parameter is present then If Upper(Left$(CommandLine$(),2)) = "/C" Then Configure() ; check if Screensaver Configuration shall be executed If Upper(Left$(CommandLine$(),2)) = "/S" Then Start() ; or Screensaver itself should be started EndIf ; <> "" End ; End program... bye bye Function Configure() ; -------------------------------------------------------------------------------------------- ; | | ; | Insert Code for your Configuration Screen. | ; | If needed, execute an external application. Written in VB, Delphi or whatever. | ; | | ; -------------------------------------------------------------------------------------------- SetBuffer BackBuffer() ; Display of Confguration Options such as: Resolution, Detail Level etc. Print "No Configuration Settings" Flip Repeat Until GetKey()<>0 Or GetMouse()<>0 End Function ; of Configure() Function Start() ; -------------------------------------------------------------------------------------------- ; | | ; | Insert Code for your Screensaver program | ; | | ; -------------------------------------------------------------------------------------------- ; Set GFX-Mode and load Data... (placed before main loop!) FlushKeys() ; clean keyboardbuffer FlushMouse() ; clean mousebuffer MoveMouse 0,0 ; move mouse to 0,0 for later check Graphics3D 800,600,32,1 SeedRnd MilliSecs() cam=CreateCamera() MoveEntity cam,2,2,-5 CameraFogMode cam,1 CameraFogRange cam,100,1000 l=CreateLight() MoveEntity l,0,3,5 d1=LoadAnimMesh("duck.b3d") ;anim 0 MoveEntity d1,0,0,3 RotateEntity d1,0,180,0 d2=LoadAnimMesh("duck.b3d") ;anim 0 MoveEntity d2,1,0,1 RotateEntity d2,0,180,0 d3=LoadAnimMesh("duck.b3d") ;anim 0 MoveEntity d3,-1,0,1 RotateEntity d3,0,180,0 d_tex=LoadTexture("duck.bmp") EntityTexture d1,d_tex EntityTexture d2,d_tex EntityTexture d3,d_tex plane=CreatePlane() EntityAlpha plane,.6 EntityColor plane,0,10,200 EntityShininess plane,1 pt=LoadTexture("water1.jpg") EntityTexture plane,pt ht=LoadTerrain("height.jpg") PositionEntity ht,0,-20,0 ScaleEntity ht,500,500,500 bo=LoadMesh("bouy.3ds") PositionEntity bo,-3,0.1,100 HideEntity bo btex=LoadTexture("bouy.bmp") EntityTexture bo,btex rip=LoadSprite("ripple.bmp") SpriteViewMode rip,2 EntityAlpha rip,.9 TurnEntity rip,90,0,0 ScaleSprite rip,.7,.7 HideEntity rip dome=Skybox("nightsky",".png",200) MoveEntity dome,0,10,0 EntityColor dome,100,100,100 sks=Rand(0,2) If sks=1 Then m=SkyBox("sky",".bmp") If sks=0 Then m=SkyBox("sky",".jpg") If sks=2 Then m=SkyBox("sun",".jpg") ;clouds Local tmp# cloudtex(1)=LoadTexture ("cloud1.png",1+2) ; color plus alpha cloudtex(2)=LoadTexture ("cloud2.png",1+2) ; color plus alpha cloudtex(3)=LoadTexture ("cloud3.png",1+2) ; color plus alpha cloudtex(4)=LoadTexture ("cloud4.png",1+2) ; color plus alpha cloudtex(5)=LoadTexture ("cloud5.png",1+2) ; color plus alpha cloudtex(6)=LoadTexture ("cloud6.png",1+2) ; color plus alpha cloudtex(7)=LoadTexture ("cloud7.png",1+2) ; color plus alpha cloudtex(8)=LoadTexture ("cloud8.png",1+2) ; color plus alpha ;; turn this loop on To make the clouds use additive mixing ;For loop = 1 To 8 ;TextureBlend cloudtex(loop),3 ;Next cloudmaster = CreatePivot() For loop = 1 To cloudcount cloudpuff(loop) = CreateSprite(cloudmaster) PositionEntity cloudpuff(loop),Rnd(-55,55),Rnd(7.0,25.0),Rnd(-10.0,55.0) tmp = Rnd(4.0,8.0) ScaleSprite cloudpuff(loop),tmp,tmp EntityTexture cloudpuff(loop),cloudtex(Rnd(1,8)) EntityAlpha cloudpuff(loop),.1 ; make the puffs a bit more transparent. helps hipe some of the "popping" EntityFX cloudpuff(loop),1 ;fullbright Next ;;;;;;;;;;;;;;;;;; MoveEntity cloudmaster,3,0,20 MoveEntity m,0,10,0 Repeat ; Main loop for your Screensaver Code TurnEntity cloudmaster,0,.02,0 If Not Animating(d1) Then Animate d1,1,.5,0,20 If Not Animating(d2) Then Animate d2,1,.6,0,20 If Not Animating(d3) Then Animate d3,1,.7,0,20 ;Update Particles sdd=sdd+1 If sdd=25 Then r.ri=New ri r\s=CopyEntity(rip) PositionEntity r\s,EntityX(d1),EntityY(d1),EntityZ(d1)-.5 r\a#=.5 r\sp#=-.04 rn#=Rnd(.5,1) ScaleSprite r\s,rn#,rn# r.ri=New ri r\s=CopyEntity(rip) PositionEntity r\s,EntityX(d2),EntityY(d2),EntityZ(d2)-.5 r\a#=.5 r\sp#=-.04 rn#=Rnd(.5,1) ScaleSprite r\s,rn#,rn# r.ri=New ri r\s=CopyEntity(rip) PositionEntity r\s,EntityX(d3),EntityY(d3),EntityZ(d3)-.5 r\a#=.5 r\sp#=-.04 rn#=Rnd(.5,1) ScaleSprite r\s,rn#,rn# sdd=0 EndIf For r.ri=Each ri MoveEntity r\s,0,r\sp#,0 r\a#=r\a#-.01 EntityAlpha r\s,r\a# If r\a#=<0 Then HideEntity(r\s):Delete r Next x#=x#+.01 RotateEntity m,0,x#,0 If ttt=0 Then tt#=tt#-.01 If ttt=1 Then tt#=tt#+.01 EntityColor m,tt#,tt#,tt# If tt#<0 Then ttt=1 If tt#>255 Then ttt=0 If tt#<100 And tt#>99 Then at=1 If tt#>101 And tt#<102 Then at=2 If at=2 Then If al#<1 Then al#=al#+.002 If al#>1 Then al#=1 EntityAlpha m,al# If al#=1 Then at=0 EndIf If at=1 Then If al#>0 Then al#=al#-.002 If al#<0 Then al#=0 EntityAlpha m,al# EndIf If up=0 Then MoveEntity d1,0,-.01,0 MoveEntity d2,0,-.01,0 MoveEntity d3,0,-.01,0 uu=uu+1 If uu=10 Then uu=0:up=1 Else up=1 MoveEntity d1,0,.01,0 MoveEntity d2,0,.01,0 MoveEntity d3,0,.01,0 uu=uu+1 If uu=10 Then uu=0:up=0 EndIf bob=bob+1 If bob=300 b.bu=New bu b\s=CopyEntity(bo) move=Rand(0,2) If move=1 Then MoveEntity b\s,6,0,0 If move=2 Then MoveEntity b\s,10,0,0 bob=0 EndIf For b.bu=Each bu MoveEntity b\s,0,0,-.2 If EntityZ(b\s)<-10 Then HideEntity b\s:Delete b Next UpdateWorld RenderWorld Flip Delay 1 ; secure that the CPU usage is not 100% all time! Until GetMouse() <> 0 Or MouseX() <> 0 Or MouseY() <> 0 Or GetKey() <> 0 ; check if user makes a move :) End Function ; of Start() I turned debug OFF and compiled it to a .scr file, put everything in the windows root folder. It works fine if I hit preview on the screensaver window. Has anyone had this problem And is there some faster running screensaver code (my FPS is like 5 in the begining and slowly increases to 20) |
| ||
Maybe you should check if another instance of the screensaver is running. I tried making one in Delphi for Win98, so I don't know if this is still the case, but win98 started a new instance of the screensaver program every minute (when the delay was set to 1). If this is the problem, use api_FindWindow in user32.dll: http://www.blitzbasic.com/Community/posts.php?topic=39665 If findwindow returns a non-zero value, the screensaver is allready running and the program should exit. And maybe use Graphics3D 800, 600, 0, 1 instead. |
| ||
first at all: an include file is missing, and the media is missing, too. so we cant help you at all. you dont have to put it into the windows root folder, but in "c\windows\system32\". i don't know what "compiling to scr" means, but i compile it and rename "exe" into "scr" and that works. |
| ||
Dare i say it, I think I have written more commercial screen savers in Blitz3D than anyone else (apart from Joe Retro perhaps). Anyhow zip up the entire project including models and includes to me and I'll look at it for you. |
| ||
Boiled, it does the heart good to see this kinda offer - top dude. This is what this community should be all about :) IPete2. |
| ||
Here's the data files sorry it took so long: http://filecities.com/files/65/Birds.zip |
| ||
It still misses 3 files: the duck texture, the water sprite and ripple.bmp |
| ||
Anyhow zip up the entire project including models and includes to me and I'll look at it for you. |