# Hello from New Member...and Request for Help Please!

This topic is 4695 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, This is my first post here so please go easy on me. :-) I'm a professional software developer for a living (not that that's really relevant, just by way of introduction) and in my spare time I'm a keen games enthusiast, both playing, and lately, developing my own game engine. I've been working on my engine for about 1 1/2 years now, and it's almost complete. Basically it's written in VB6 using DirectX 7/8. It's a 2d engine at heart, but uses some hybrid 3d stuff in order to have translucent/rotating sprites. This means I can do some cool stuff like smoke and light effects, etc. My problem is this: The engine runs fine in full screen mode, no problems. However if I try to run it windowed, it doesn't work. I don't get any error messages of any kind, it just doesn't do anything, nothing appears in the display window. It's entirely class based and is very easy to read/use. If any one would be prepared to have a look at it for me and figure out why it doesn't work in windowed mode, I'd be eternally grateful. Due to my busy lifestyle if anyone can help, please email me either at daphydthebard@hotmail.com, or at dave@xenex.co.uk Thanks in advance.

##### Share on other sites
A completely wild guess would be that you haven't overriden the OnPaint method (and even hook the OnResize method for good measure) AND invalidated it? I'm using C# terms but I suppose VB6 will have similar methods...

##### Share on other sites
I am not quite sure how it works in VB, but try cranking the DirectX debug level up to the max and see if there are any warnings/error messages. If all else fails, throw breakpoints/message boxes throughout the program to see how far it gets before it fails. That might help you to narrow down what specifically is failing.

##### Share on other sites
Sounds to me like your DirectDraw/Direct3D isn't initialized correctly at startup. One possible reason for that is that you set a refresrate when you setup the interface. If you run in windowed mode you cannot do that, it has to be set to 0.

Thats just a quess, but it has happened to me several times when i forgot to set it to zero for windowed mode. Thats how it is for Direct3D anyhow, not sure about DirectDraw.

// Allmight

##### Share on other sites
Thanks for the replies folks.

I've run the code through in debug mode line-by-line more times than I care to remember, and it never throws up any error messages.

I've also read through so many articles and examples on-line for how to set up a windowed DirectX app and my code seems to match the examples exactly.

My Init Routine is this:

'Create the Render Device
Public Function Create(hWnd As Long, Width As Long, Height As Long, Optional FullScreen As Boolean = True) As Boolean

On Error GoTo dx_err

Create = False

'Store Display Dimensions
lWidth = Width
lHeight = Height

'Create DirectX Object
If (clsAE_DX Is Nothing) Then Set clsAE_DX = New DirectX7

'Create DirectDraw Object
If (clsAE_DD Is Nothing) Then Set clsAE_DD = clsAE_DX.DirectDrawCreate("")

'Create Clipper
Set clsAE_DD_Clipper = clsAE_DD.CreateClipper(0)
clsAE_DD_Clipper.SetHWnd hWnd

'Store Handle to Display Device Context
lWindowHandle = hWnd

'Set initial surface state to unlocked
bLocked = False

'Get the bounding rectangle of the display
If Not FullScreen Then clsAE_DX.GetWindowRect lWindowHandle, clsAE_DD_PrimarySurfaceRECT

'Create Back Buffer RECT
clsAE_DD_BackBufferRECT.Top = lHeight * 1
clsAE_DD_BackBufferRECT.Left = lWidth * 1
clsAE_DD_BackBufferRECT.Bottom = lHeight * 2
clsAE_DD_BackBufferRECT.Right = lWidth * 2

'Setup the Display
If Not FullScreen Then
clsAE_DD.SetCooperativeLevel lWindowHandle, DDSCL_NORMAL
Else
Call clsAE_DD.SetCooperativeLevel(lWindowHandle, DDSCL_FULLSCREEN Or DDSCL_EXCLUSIVE Or DDSCL_ALLOWREBOOT)
Call clsAE_DD.SetDisplayMode(lWidth, lHeight, 32, 0, DDSDM_DEFAULT)
End If

'Create Primary Surface
If Not FullScreen Then
clsAE_DD_PrimarySurfaceDESC.lFlags = DDSD_CAPS
clsAE_DD_PrimarySurfaceDESC.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
Else
clsAE_DD_PrimarySurfaceDESC.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
clsAE_DD_PrimarySurfaceDESC.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_VIDEOMEMORY Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX Or DDSCAPS_3DDEVICE
End If

clsAE_DD_PrimarySurfaceDESC.lWidth = lWidth
clsAE_DD_PrimarySurfaceDESC.lHeight = lHeight
clsAE_DD_PrimarySurfaceDESC.lBackBufferCount = 1
Set clsAE_DD_PrimarySurface = clsAE_DD.CreateSurface(clsAE_DD_PrimarySurfaceDESC)

If Not FullScreen Then clsAE_DD_PrimarySurface.SetClipper clsAE_DD_Clipper

'Create Back Buffer
clsAE_DD_BackBufferDESC.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
If Not FullScreen Then
clsAE_DD_BackBufferDESC.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN 'Or DDSCAPS_3DDEVICE
Else
clsAE_DD_BackBufferDESC.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
End If
clsAE_DD_BackBufferDESC.lWidth = lWidth * 3
clsAE_DD_BackBufferDESC.lHeight = lHeight * 3
Set clsAE_DD_BackBuffer = clsAE_DD.CreateSurface(clsAE_DD_BackBufferDESC)

'Create 3D Surface
If Not FullScreen Then

Dim s3D_DESC As DDSURFACEDESC2

s3D_DESC.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
s3D_DESC.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_3DDEVICE
s3D_DESC.lWidth = lWidth
s3D_DESC.lHeight = lHeight

Set clsAE_DD_BackBuffer3D = clsAE_DD.CreateSurface(s3D_DESC)

Else

Dim caps As DDSCAPS2
caps.lCaps = DDSCAPS_BACKBUFFER
Set clsAE_DD_BackBuffer3D = clsAE_DD_PrimarySurface.GetAttachedSurface(caps)

End If

Set clsAE_DD_D3D = clsAE_DD.GetDirect3D
Set clsAE_DD_DEV = clsAE_DD_D3D.CreateDevice("IID_IDirect3DHALDevice", clsAE_DD_BackBuffer3D)

Create = True
Exit Function

dx_err:
Debug.Print Err.Description

End Function

***

Like I said, it runs fine in full screen mode, but I get no visible output in windowed mode (and no errors either).

Don't know if anyone can spot anything glaringly obvious with this, but I'm stumped. And there was me thinking I was a good programmer!!

By the way, incase anyone's wondering, the reason I set up my standard backbuffer 3 times the width and height of the display is so I can have bitmaps scrolling off the screen. When I blit to the primary surface, i just take a rectangle from the "middle" of the backbuffer. It works, anyway.

I really need to get this working in windowed mode so I can test my multiplayer class on a single machine.

*cries*

##### Share on other sites
Quote:
 This is my first post here so please go easy on me.

Welcome[attention] GDNet is full of nice people, just watch out for the lounge though - they use trial-by-fire at times [grin]

Quote:
 Basically it's written in VB6 using DirectX 7/8

I *really* should be able to help here given how many years I messed with VB6/DX (6,7 and 8). Sadly my memories are fading a little [sad]

A couple of pointers:

1. Make sure you're catching all the errors, in VB6 they always appear as "Automation Error" and a huge negative number. Feed these into D3DX.GetErrorString(err.number) for a description - then use these against the SDK documentation for more details:

On Local Error Goto BailOut:'Put all your code in here as usualExit Sub 'or Exit Function as appropriateBailOut:Debug.Print err.number, err.message, D3DX.GetErrorString( err.number )End Sub 'or End Function

2. Where are you creating your device? I do remember there being some odd quirks where (for fullscreen) D3D will help you, but for windowed mode it assumes the window is set-up already and if you create your device in Form_Load() it'll die. iirc, switching it to Form_Activate() and/or using Me.Show; DoEvents before any D3D related code.

Unfortunately I'm a little too busy to dig into your actual code for you, if you can isolate the particular line(s) causing you hassle I (or others) might be able to help out [smile]

hth
Jack

##### Share on other sites
Hi, and thanks again.

For windowed mode, I'm allowing the form to load, then using a timer to call the initialisation code once the form is up and running. THen I disable the timer.

I've come across this problem before where trying to set up windowed DX in Form_Load causes it to crash.

I'm not getting any automation errors or anything, it's really wierd.

Perhaps if someone is willing, I could send my engine (zipped) for their perusal.

Thanks again for all the constructive advice.

##### Share on other sites
I think I've found my problem.

It's not that directx wasn't initialising properly, it's to do with my surface RECTS.

I found a couple of problems that I'm now working through to solve.

(a) I wasn't assigning a Clipper object to the primary surface when running in windowed mode.

(b) I don't need a backbuffer 3x the size of the screen in windowed mode using a Clipper, as this was using too much memory and causing problems.

(c) I was calculating the Destination RECT incorrectly in windowed mode when copying the secondary and tertiary buffers to the primary surface.

I haven't quite got this all working yet, however I actually managed to get something to render to the form in windowed mode, which is a start.

Back to the code....see if I can get this up and running today!

Thanks for all the help peeps.

##### Share on other sites
Woohoo!!!!!!

I've got it working!!!!

Was all to do with not setting up my source/destination RECTS correctly in windowed mode.

Now I have a fully fledged game engine, written by me, windowed or fullscreen, with rotating/translucent sprites, gamma ramp control, sound effects, music, smooth scrolling, and multiplayer capability!!!!

Yay!!!!!!

##### Share on other sites
Sounds pretty cool. I have a friend that was looking for a type of 2D game engine like that. Do you have a website or screenshots? What's your next step?

• 16
• 9
• 13
• 41
• 15