|
-
Jun 24th, 2001, 04:26 AM
#1
Thread Starter
Addicted Member
Blitting Direct Draw?
It will not draw my sprite. What did I do Wrong.
Code:
Dim DirectX As New DirectX7
Dim DirectDraw As DirectDraw7
'surfaces
Dim PrimarySurf As DirectDrawSurface7
Dim BackSurf As DirectDrawSurface7
'Surface Descriptions
Dim PrimarySDesc As DDSURFACEDESC2
'Offscreen Surface
Dim Sprt As DirectDrawSurface7
Private Sub Form_Load()
ChDir (App.Path)
Me.Show
Me.WindowState = 2
Init_DD
LoadSprite "ball.bmp"
DrawSprite
PrimarySurf.Flip Nothing, DDFLIP_WAIT
End Sub
Sub Init_DD()
Set DirectDraw = DirectX.DirectDrawCreate("")
Call DirectDraw.SetCooperativeLevel(Me.hWnd, DDSCL_FULLSCREEN Or _
DDSCL_EXCLUSIVE Or _
DDSCL_ALLOWREBOOT)
Call DirectDraw.SetDisplayMode(640, 480, 8, 0, DDSDM_DEFAULT)
'Primary surface
PrimarySDesc.lFlags = DDSD_BACKBUFFERCOUNT Or DDSD_CAPS
PrimarySDesc.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or _
DDSCAPS_FLIP Or _
DDSCAPS_COMPLEX
PrimarySDesc.lBackBufferCount = 1
Set PrimarySurf = DirectDraw.CreateSurface(PrimarySDesc)
'Back buffer
Dim BackCaps As DDSCAPS2
BackCaps.lCaps = DDSCAPS_BACKBUFFER
Set BackSurf = PrimarySurf.GetAttachedSurface(BackCaps)
BackSurf.SetForeColor vbWhite 'set font collor
ClearBackBuffer
End Sub
Sub ShutDown()
Set Sprt = Nothing
Set PrimarySurf = Nothing
Set BackSurf = Nothing
Call DirectDraw.RestoreDisplayMode
Call DirectDraw.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)
End Sub
Private Sub Form_Unload(Cancel As Integer)
ShutDown
End Sub
Public Sub DrawSprite()
Dim SRect As RECT
Dim DRect As RECT
With SRect
.Left = 0
.Top = 0
.Bottom = 64
.Top = 64
End With
With DRect
.Left = 0
.Top = 0
.Bottom = 64
.Top = 64
End With
BackSurf.Blt DRect, Sprt, SRect, DDBLT_KEYSRC Or DDBLT_WAIT
End Sub
Public Sub LoadSprite(Path As String)
Dim ddsd As DDSURFACEDESC2
Dim ckey As DDCOLORKEY
ddsd.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsd.lWidth = 64
ddsd.lHeight = 64
Set Sprt = DirectDraw.CreateSurfaceFromFile(Path, ddsd)
ckey.high = vbBlack
ckey.low = vbBlack
Sprt.SetColorKey DDCKEY_SRCBLT, ckey
End Sub
Public Sub ClearBackBuffer()
Dim BackRect As RECT
With BackRect
.Left = 0
.Top = 0
.Right = 640
.Bottom = 480
End With
BackSurf.BltColorFill BackRect, 0
End Sub
-
Jun 24th, 2001, 07:30 AM
#2
Frenzied Member
Hum... there are some things I don't get:
1) Didn't VB give you an error in this line: "ChDir (App.Path)"? You shouldn't use brackets... it should be "ChDir App.Path"
2) Anyway, you shouldn't be using ChDir. I'd do it this way:
LoadSprite App.Path & "\ball.bmp"
3) What error does it give you, and in what line?
-
Jun 24th, 2001, 07:36 AM
#3
Frenzied Member
Another thing (and this is probably your problem )
You should use a "main loop". Your form_load sub should look like this:
VB Code:
Dim ExitProgram As Boolean
Private Sub Form_Load()
ChDir (App.Path)
Me.Show
Me.WindowState = 2
Init_DD
LoadSprite "ball.bmp"
Do Until ExitProgram
DoEvents
DrawSprite
PrimarySurf.Flip Nothing, DDFLIP_WAIT
'Here you should check if the user pressed Escape or some key so you know when to set ExitProgram to True and the program exits.
Loop
End Sub
Last edited by Jotaf98; Jun 24th, 2001 at 07:47 AM.
-
Jun 24th, 2001, 02:08 PM
#4
Thread Starter
Addicted Member
The code does not give any erros, it does not draw the sprite and I don't know why.
I didn't want to loop it yet I just wanted to flip the surface once so I can see the sprite. I draw boxes and text and stuff but I cant draw another surface.
the chirdir since the brackets don't matter. since ther a space between method and the (. Its just an exprsion like
a = (5)
it dosen't matter if there a bracket around the 5 or not the value is still 5.
-
Jun 24th, 2001, 02:12 PM
#5
Frenzied Member
Ok. Anyway, did you try to use a loop?
-
Jun 24th, 2001, 08:34 PM
#6
Thread Starter
Addicted Member
if it didn't draw it once it wont draw it a hundred or a thousand times.
-
Jun 25th, 2001, 03:09 AM
#7
Frenzied Member
if it didn't draw it once it wont draw it a hundred or a thousand times.
Dont be so sure about that man. Bill has his dirty fingers everywhere (PARANOIA)
well I have another suspicion though
see if the source rectangle is not a single rect bigger than the original picture, that you dont blit out of the window without a clipper. and try bltfast. In most cases it does the best (easiest) job.
(sorry if you have a clipper or stuff i skimmed through your code very fast)
Sanity is a full time job
Puh das war harter Stoff!
-
Jun 25th, 2001, 03:17 AM
#8
Frenzied Member
hey uhm looked over it again.
I can't say it is wrong, because I never tried it, but still it seems wierd, that you give the width and lenght width before loading the surface from a file. It seems very unecessary.
good luck 
keep on trying
Sanity is a full time job
Puh das war harter Stoff!
-
Jun 25th, 2001, 04:08 AM
#9
Thread Starter
Addicted Member
Thats they way it was in the demo I was copying it from. I'm thinking I don't have a DD flag set right or I'm skipping a big step or something...
-
Jun 25th, 2001, 04:23 PM
#10
Thread Starter
Addicted Member
it still wont draw the sprite, even with a main loop. Something wrong with the Direct Draw code.
-
Jun 26th, 2001, 12:18 AM
#11
PowerPoster
Code:
Do Until ExitProgram
DoEvents
DrawSprite
PrimarySurf.Flip Nothing, DDFLIP_WAIT
'Here you should check if the user pressed
Escape or some key so you know when to set ExitProgram
to True and the program exits.
Loop
<--- I hate that code!!!
use this instead: (won't solv your problem but I had so say 
Code:
While Not ExitProgram
'Here you should check if the user pressed
Escape or some key so you know when to set ExitProgram
to True and the program exits.
DrawSprite
PrimarySurf.Flip Nothing, DDFLIP_WAIT
DoEvents
Wend
Fox, who didn't ever use other loops than For and While
-
Jun 26th, 2001, 01:34 AM
#12
Frenzied Member
hey fox
what is so good about while wend?
isn't that a little outdated?
Sanity is a full time job
Puh das war harter Stoff!
-
Jun 26th, 2001, 01:40 AM
#13
Thread Starter
Addicted Member
For crying out loud I know how to do loops!
-
Jun 26th, 2001, 02:17 AM
#14
PowerPoster
I just hate the Do loops... and the Until of course... oh and not to forget the Loop statement *argh*
-
Jun 26th, 2001, 10:05 AM
#15
Addicted Member
unless this is a typo your kick yourself for making a stupid mistake...
Here is the code that is wrong
Code:
Dim SRect As RECT
Dim DRect As RECT
With SRect
.Left = 0
.Top = 0
.Bottom = 64
.Top = 64
End With
With DRect
.Left = 0
.Top = 0
.Bottom = 64
.Top = 64
End With
Notice anything wrong with it?
it should be:
[code]
Dim SRect As RECT
Dim DRect As RECT
With SRect
.Left = 0
.Top = 0
.Bottom = 64
.Right = 64
End With
With DRect
.Left = 0
.Top = 0
.Bottom = 64
.Right = 64
End With
Some Days, i just get this feeling that i'm helping to write dozens of Viruses...
-
Jun 26th, 2001, 10:10 AM
#16
Frenzied Member
-
Jun 26th, 2001, 10:14 AM
#17
Frenzied Member
-
Jun 26th, 2001, 06:22 PM
#18
Thread Starter
Addicted Member
Thank you very much. Now it works.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|