Author Topic: Space Demos  (Read 2125 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Space Demos
« on: April 01, 2012, 05:53:05 AM »
Deleted
« Last Edit: April 11, 2015, 10:32:26 AM by Peter »

Charles Pegge

  • Guest
Re: Space Demos
« Reply #1 on: April 02, 2012, 05:03:50 AM »
Thanks Peter,

I've written a jpeg / png loader for you.

Extracted from then GDIplus jungle, and embedded in your example:

It uses night.jpg attached below.

Code: [Select]
include "win64.inc"
Window "SPACE WATER",800,600,1

'====================
'GDIPLUS IMAGE LOADER
'====================

  typedef struct tagGDIStartup {
    dword          GdiplusVersion;
    sys            DebugEventCallback;
    bool           SuppressBackgroundThread;
    bool           SuppressExternalCodecs;
  } GdiplusStartupInput;

  typedef struct {
    sys NotificationHookProc
    sys NotificationUnhookProc
  } GdiplusStartupOutput;

  extern library "gdiplus.dll"
  long GdiplusStartup( dword *token, GdiplusStartupInput*input,  GdiplusStartupOutput *output)
  long void GdiplusShutdown(dword*token)
  long GdipLoadImageFromFile(wstring filename, sys*image)
  long GdipCreateBitmapFromFile(wstring filename, sys*bitmap)
  long GdipCreateHBITMAPFromBitmap(sys bitmap, sys*hbmReturn, dword backgroundColor)
  long GdipDisposeImage(sys image)
  end extern

Function LoadBmpPlus(string File, sys Frames) as sys
    iF Frames=0 or Frames <0 Then Frames =1
    static id as sys
    iF id <512 Then id +=1
    'iHnd(id) = LoadImage(0,File + ".bmp",0,0,0,16)'
    sys     hstatus,pImage,hbitmap
    wstring strFileName
    '
    strFileName = File
    hStatus = GdipLoadImageFromFile strFileName, pImage
    hstatus=GdipCreateHBITMAPFromBitmap(pImage,hbitmap,0)
    iHnd(id)=hBitMap
    iHdc(id) = CreateCompatibleDC(sys_hdc)
    SelectObject iHdc(id), iHnd(id)
    GetObject iHnd(id), sizeof info, &info
    BmpWidth (id) = info.bmWidth /Frames
    BmpHeight(id) = info.bmHeight        
    BmpFrame (id) = Frames
    if pImage then GdipDisposeImage pImage
    Return id
End Function        

sys hr,token
GdiplusStartupInput StartupInput

StartupInput.GdiplusVersion = 1
hr=GdiplusStartup token, StartupInput, byval 0
'
if hr then
  print "Error initializing GDIplus: " hex hr
end if

'======



Type pType
     single lifespan
     single x
     single y
     single xv
     single yv
End Type
Dim Particle(10000) as pType
sys pic,xstart, ystart, i, mx=10000
pic = LoadBmpPlus("night.jpg",0)

Sub ParticleInit()
Xstart = Width  \ 10
Ystart = Height \ 10
For i = 0 To mx
    Particle(i).lifespan = Rand 1,500
    Particle(i).x  = Xstart
    Particle(i).y  = Ystart
    Particle(i).yv = Rand(1,4)
    Particle(i).xv = Rand(1,8)
Next
End Sub

ParticleInit()
While EscKey()=0
'ClsColor (200,200,200)
SetBmp (pic,0,0,800,600,0)
For i=0 To mx
RoundBox Particle(i).x, Particle(i).y,12,10,10,10, 0,Rand(32,64),Rand(200,255)
Particle(i).x  = Particle(i).x + Particle(i).xv
Particle(i).y  = Particle(i).y + Particle(i).yv
Particle(i).yv = Particle(i).yv + 0.96
iF Particle(i).y >= Height  
   Particle(i).yv = -(Particle(i).yv * 0.46)
   Particle(i).y  =  Height
End iF
Particle(i).LifeSpan = Particle(i).LifeSpan -1
iF Particle(i).LifeSpan <=0
   Particle(i).LifeSpan = Rand(1,500)
   Particle(i).x = Xstart
   Particle(i).y = Ystart
   Particle(i).yv = Rand(1,4)
   Particle(i).xv = Rand(1,8)
End iF
Next
FlipBuffer
WaitFPS 14
Wend

GdiplusShutdown token
WinEnd


Aurel

  • Guest
Re: Space Demos
« Reply #2 on: April 02, 2012, 11:02:24 AM »
Quote
I've written a jpeg / png loader for you.

This sounds great Charles, so we can now load png images to.

Charles Pegge

  • Guest
Re: Space Demos
« Reply #3 on: April 02, 2012, 11:47:25 AM »

Yes, I've put all the necessary code in this example. I extracted it mostly from inc/ImgWin.inc and cleaned up the prototypes.

GDIplus originated in MS dinosaur epoch :)

Charles