Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Picboxes instead of files (graphics)
#1
Im new to this blt stuff, and i was wondering if someone could tell me how I could perhaps make direct x draw from a picture box instead of a file.

Im working on a new Day and night method, which will use light sources too (which will be released in basic as a tutorial once its finished). So I was wondering if anyone could give me any pointers... and also if its possible to have transparency in the like... tiles... (night thing)... so that it will looks alot better with the light sources (so its light at the centre of the light source and the further from it the more faded it is kinda thing (this will take awhile lol).

Thanks for any assistance
Reply
#2
Im no good at blting, but i think it already does draw from a picture box.. It loads the file into memory, then places that data into a picture box.. Then it loads it from the picture box.. This is what im assuming..
Reply
#3
No, the way it is currently setup, it does not place the data from memory to a picturebox.

Just a little information, this will greatly increase your executable size. If you don't care just keep reading.

Add this sub to your project.

Code:
Public Sub LoadFromPictureBox(DDSURF As DirectDrawSurface7, pBox As PictureBox)
    Dim DC As Long
    Dim DDSD As DDSURFACEDESC2
    Dim Key As DDCOLORKEY
    
    With DDSD
        .lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
        .ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_VIDEOMEMORY 'or DDSCAPS_SYSTEMMEMORY whichever you prefer
        .lHeight = pBox.Height
        .lWidth = pBox.Width
    End With
  
    Set DDSURF = DD.CreateSurface(DDSD)
  
    DC = DDSURF.GetDC
    BitBlt DC, 0, 0, pBox.Width, pBox.Height, pBox.hdc, 0, 0, vbSrcCopy
    DDSURF.ReleaseDC DC
    
    DDSURF.SetColorKey DDCKEY_SRCBLT, Key
End Sub

And from your initsurfaces sub, make sure you change where it loads from file to this:

Code:
Call LoadFromPicturebox(thesurf, frmWhatever.pb)

Ok, now on the form where the pictureboxes are, make sure both the form and the pictureboxes scalemode are pixels. Set the pictureboxes autoredraw to true.

[edit]Oh and forgot to mention, after you've loaded all the images you want from the pictureboxes. I would also suggest doing the following:

Code:
frmWhatever.pb.Picture = Nothing

Just so you don't have multiple copies of the image in memory.[/edit]
Reply
#4
oh sweet, thanks dude, this will help alot (not sarcastic lol)

i'm thinking if it checks each square for a player, and if there is it makes like diff shade depending on how far away from the source it is... or something lol

Edit: ok, i'm very confused now... i can't get it to work... well it loads it to memory but i can't get it to draw onto the screen like i can with other blt... :S
Reply
#5
it should be working but it just isn't... it's decided to hate me... i'll try again from scratch lol. if anyone can see any errors in the code BigRed kindly provided, please tell me. thanks... =/
Reply
#6
what do you mean not working, error, not loading properly, what?
Reply
#7
funkynut Wrote:what do you mean not working, error, not loading properly, what?

sorry, i kinda didn't say did i? lol

i mean it's loading to the memory fine, but it's not being blt'ed on screen.... i'm very noob at blt so it's probably a noob error.

to test blt'ing it i've used this code:
Code:
Sub DrawNightSky()
    rec.top = 0
    rec.Bottom = 32
    rec.Left = 0
    rec.Right = 32

    Dim dark1 As Long
    Dim dark2 As Long
    
    dark1 = GetPlayerX(MyIndex) * PIC_X + Player(MyIndex).XOffset + Int(PIC_X) - 10
    dark2 = GetPlayerY(MyIndex) * PIC_Y + Player(MyIndex).YOffset - Int(PIC_Y) + 25


    Call DD_BackBuffer.BltFast(dark1, dark2, DD_DARKSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
    
End Sub

is that right for the thing i'm trying to do? (and note: the place it blts to is just a test, it's not meant to be like... in right place/s yet lol)

edit: and yes, i've got the thing being called... i'm not THAT noobie.... anymore Wink
Reply
#8
Now that I'm home I can actually test this. Hm, yea, it doesn't seem to work as is for me either. Gimme a few minutes and I'll figure it out.

[edit]
Ok, updated the first post with changes. There was a small error in the code, and I forgot the colorkey, if it's used...Anyway, check right under where I tell you to how to call it.
[/edit]
Reply
#9
BigRed Wrote:Now that I'm home I can actually test this. Hm, yea, it doesn't seem to work as is for me either. Gimme a few minutes and I'll figure it out.

[edit]
Ok, updated the first post with changes. There was a small error in the code, and I forgot the colorkey, if it's used...Anyway, check right under where I tell you to how to call it.
[/edit]

thanks again Smile

edit: works perfectly, thanks millions dude Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)