Here it is:
1) DirectDraw works, my background shows up nicely, even the image I place on top of background is visible, but, the mouse cursor isn't visible when I don't move the mouse, and when I do move the mouse, the cursor flickers in the background....any ideas? :)
2) Whenever I bring bitmaps, whatever colours I'm using, it stays the same, but much brighter (I'm using 32-bit and the pictures are drawn with 256 colors) and even if I try to change the colours in the bitmaps, it will still display the new colours brighter....is it just a DirectDraw thing or am I doing something wrong?
If I need to explain better or show some code then please tell me :)
Thanks
ardman 02-22-2002, 04:54 AM Could we see the code you are using.
'Direct X Objects
Public DX As New DirectX7
Public DD As DirectDraw7 'DirectDraw7 - The main Direct Draw Object
Public Primary As DirectDrawSurface7 'DirectDrawSurface7 - The Primary will be the main surface which we see.
Public BackBuffer As DirectDrawSurface7 ' The BackBuffer is a hidden surface which we draw to.
Public BackDrop As DirectDrawSurface7 ' The BackDrop is where we hold a loaded bitmap.
Public Character As DirectDrawSurface7
Public DDSD1 As DDSURFACEDESC2 'DDSURFACEDESC2 - This type stores information about a surface.
Public DDSD2 As DDSURFACEDESC2 ' One is dimmed for each surface.
Public DDSD3 As DDSURFACEDESC2
Public CHARDesc As DDSURFACEDESC2
'Used to check things along the way
Global bInit As Boolean
Global bRunning As Boolean
'Character Cell Position Variables
Global CTop, CBottom, CLeft, CRight As Integer
'Character Position Variables
Global XLeft, YDown As Integer
Public Function InitDD(lWidth As Long, lHeight As Long) As Boolean
Set DD = DX.DirectDrawCreate("") 'Sets DirectDraw (DD). ("") Means the default driver
RPG.Show 'Displays the Form
'The next two lines set up DirectDraw to draw on Form1. EXCLUSIVE means that the app has complete
'control over DirectDraw (Stuff from other windows is left out). FULLSCREEN means fullscreen mode
'will be used. The second line sets the display (ResolutionX, ResolutionY, Colours, 0, DDSDM_DEFAULT)
Call DD.SetCooperativeLevel(RPG.hWnd, DDSCL_FULLSCREEN Or DDSCL_ALLOWMODEX Or DDSCL_EXCLUSIVE)
Call DD.SetDisplayMode(lWidth, lHeight, 32, 0, DDSDM_DEFAULT)
'Initializes the surface called Primary to be the displayed surface. Sets up 1 BackBuffer.
DDSD1.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
DDSD1.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX
DDSD1.lBackBufferCount = 1
Set Primary = DD.CreateSurface(DDSD1)
'To complete the DirectDraw set up, the surface BackBuffer is initialized
Dim CAPS As DDSCAPS2
CAPS.lCaps = DDSCAPS_BACKBUFFER
Set BackBuffer = Primary.GetAttachedSurface(CAPS)
BackBuffer.GetSurfaceDesc DDSD3
'To use backgrounds and BITMAPS, set up BackDrop. This means that BackDrop has been made into an
'OFFSCREENPLAIN surface, once which is not ever seen, but holds an image of some sort. The parts with
'ddsd2 and ddsd3 are just making the bitmap the same size as the screen.
DDSD2.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
DDSD2.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
DDSD2.lWidth = DDSD3.lWidth
DDSD2.lHeight = DDSD3.lHeight
Set BackDrop = DD.CreateSurfaceFromFile(App.Path & "\backdrop.bmp", DDSD2)
'Setting up the character Surface
CHARDesc.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
CHARDesc.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
CHARDesc.lWidth = 60
CHARDesc.lHeight = 60
Set Character = DD.CreateSurfaceFromFile(App.Path & "\sc.bmp", CHARDesc)
CTop = 0
CLeft = 0
CBottom = 60
CRight = 60
XLeft = 0
YDown = 0
InitDD = True
bInit = True
End Function
Public Sub CleanUp()
'The following lines clears the DirectDraw settings
Call DD.FlipToGDISurface
Call DD.RestoreDisplayMode
Call DD.SetCooperativeLevel(RPG.hWnd, DDSCL_NORMAL)
Set Primary = Nothing
Set BackBuffer = Nothing
Set BackDrop = Nothing
Set DD = Nothing
End Sub
Private Sub Form_Load()
'Initialise Variables and Surfaces
bRunning = InitDD(1280, 1024)
Do While bRunning
DrawPic
DoEvents
Loop
CleanUp
Unload Me
End Sub
Public Sub DrawBack()
'A rectangle (RECT) is setup to the size of the screen (ddsd3) as a source and then the contents of
'BackDrop are pasted to it on the BackBuffer using the BltFast call. Simple. Then, the flip occurs.
'Set up the destination rectangle to be the size
'of the picture, otherwise it will chop bits off
'which is quite bad
Dim rBack As RECT
rBack.Bottom = DDSD2.lHeight
rBack.Right = DDSD2.lWidth
'Draw it
Call BackBuffer.BltFast(0, 0, BackDrop, rBack, DDBLTFAST_WAIT)
End Sub
Private Sub DrawPic()
'Draw Background
DrawBack
'Drawing a person
Dim PersonRect As RECT
PersonRect.Top = CTop
PersonRect.Left = CLeft
PersonRect.Bottom = CBottom
PersonRect.Right = CRight
Call BackBuffer.BltFast(XLeft, YDown, Character, PersonRect, DDBLTFAST_WAIT)
'Flip it
Primary.Flip Nothing, DDFLIP_WAIT
End Sub
Most of it is with help from Squirm's Tutorial :)
Squirm 02-23-2002, 06:28 AM The reason it is flickering is because you are not clearing the device between flips. This is essential really, and when you get into things like Z-buffering, failing to clear the buffer can cause some really weird effects. It doesnt take much code, something like this:
Public Sub ClearDevice()
Dim ClearRect(0 To 0) As D3DRECT
ClearRect(0).X2 = lWidth 'Width of screen (640)
ClearRect(0).Y2 = lHeight 'Height of screen (480)
Device.Clear 1, ClearRect, D3DCLEAR_TARGET, 0, 0, 0
End Sub
Now you ask why I have an array of RECTs with only one item. That is because of the way the Clear call is made, and you would need another rect in the array if you wanted to clear a z-buffer, for example.
:D
I don't quite get how I'm supposed to use the procedure....should I call it after I Draw and Flip Surfaces?
What does clearing the device mean (what's a device?) :)
How does clearing ClearRect affect my Primary, BackBuffer, and Character Surfaces? How are they linked? :)
(If you didn't already guess....I'm a newbie when it comes to DirectDraw) :)
Thanks
Squirm 02-23-2002, 01:49 PM Sorry I'm being dense. This is DirectDraw not Direct3D. Ignore me..... :eek:
Squirm 02-24-2002, 05:47 AM I was unable to replicate your mouse problem. The best I could come up with was this:
Private Sub Form_Load()
'Initialise Variables and Surfaces
bRunning = InitDD(1280, 1024)
'Define a screen-sized rectangle
Dim rClear As RECT
rClear.Right = 1280
rClear.Bottom = 1024
Do While bRunning
'Fill the rectangle with black
BackBuffer.BltColorFill rClear, 0
DrawPic
DoEvents
Loop
CleanUp
Unload Me
End Sub
Give it a try..... :)
:( nope.....I'm still getting the same problem. This way is actually better though because for now I'm using solid colour backgrounds and it saves me loading a half-meg bitmap into a surface :)
unfortunately, the mouse still hides and flickers, and the colours still become super bright....i'm beginning to think my video card might be the problem..... :(
if anybody has any more ideas then please say :)
Thanks
|