Jump to content
Xtreme .Net Talk

DX9 Windowed Issue - Draw area is 'detached' from window


Recommended Posts

Posted

I'm trying to enable my engine to start up in windowed or fullscreen mode mased on the initialize call... Fullscreen works great, when I draw something at 0,0 it shows up in the upper left corner as intended...

 

If I start up in windowed mode, and draw to 0,0 the image is still drawn to 0,0 on my screen, even if my window is at, say 200,200... I literally have to move the window up to the upper left corner of my screen to see the drawn image. Basically everything is drawn as if the app IS in fullscreen, even when the window is in a different position.

 

I'm not sure where I went wrong. Here's the code I've got for initialization.

 

Public Sub Initialize(f as Form, Windowed As Boolean)
       m_VideoDevice = New DirectDraw.Device(DirectDraw.CreateFlags.Default)

       If Windowed Then
               f.FormBorderStyle = FormBorderStyle.FixedToolWindow
               m_VideoDevice.SetCooperativeLevel(f, DirectDraw.CooperativeLevelFlags.Normal)
       Else
               f.FormBorderStyle = FormBorderStyle.None
               m_VideoDevice.SetCooperativeLevel(f, DirectDraw.CooperativeLevelFlags.FullscreenExclusive)
               m_VideoDevice.SetDisplayMode(1024, 768, 16, 60, True)
       End If

       Dim Caps As New DirectDraw.SurfaceCaps()
       Dim surfBack, surfFront As DirectDraw.SurfaceDescription

       Caps.PrimarySurface = True

       surfFront = New DirectDraw.SurfaceDescription(Caps)

       Primary = New DirectDraw.Surface(surfFront, m_VideoDevice)
       Primary.Clipper = New DirectDraw.Clipper(m_VideoDevice)
       Primary.Clipper.Window = f

       Caps.Clear()
       Caps.OffScreenPlain = True
       'Caps.SystemMemory = True  <-- drops my fps by 75% (yuck)

       surfBack = New DirectDraw.SurfaceDescription(Caps)

       surfBack.Width = f.Width
       surfBack.Height = f.Height

       f.Show()

       Backbuffer = New DirectDraw.Surface(surfBack, m_VideoDevice)

       LoadResources()

End Sub

 

On a side note, I remember using .Flip back in VB + DX7... Would it be better here performance-wise? I got this code from createdbyx.com, the rendering is all done with the following (after the .Draw calls):

 

objDestRect = New Rectangle(0, 0, 1024, 768)
Primary.Draw(objDestRect, Backbuffer, DirectDraw.DrawFlags.Wait)

 

Last, createdbyx has a windowed example on his site that works perfectly with a picturebox. As a test, I removed the picturebox and changed the code to directly draw to the form. Still worked perfect, with no need to offset x/y... Yet when I take that working initialization code and throw it in my engine class (after updating variable names), doesn't work :\

 

 

Forgive any errors in the code, I had the subs separated out into separate subs for windowed and fullscreen and just reconstructed my original sub that used a boolean to choose between the two (since I have no problem with fullscreen).

 

Thanks in advance,

 

Lyc

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...