Thread: Windowed Mode Output

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    17

    Windowed Mode Output

    Ive got an program using DirectDraw in a window. Everything initializes correctly, DD object, the front and back buffers, and clipper (All this is on the window's OnInitDialog).

    My question is how do I get the primary surface to draw to the window?

    Say i do some drawing on the back buffer... then I Blit it to the front buffer (since flipping doesnt work in windowed), shouldnt the surface be drawn on the window?

    Sorry, if this question seems obvious, Im new to DX.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Your backbuffer should be an offscreen surface that is the same size as your client area and not an attached surface and your primary will be a regular primary surface with NO backbuffers attached. Each loop blit a DDBLTFX color fill of black to clear your backbuffer, blit your graphics to your backbuffer, then blit your backbuffer to your primary surface.
    Last edited by jdinger; 06-13-2002 at 02:50 PM.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    17
    Does this code do it right?
    Code:
        HRESULT r;
    	r = DirectDrawCreateEx (0,(void**)&ddMain,IID_IDirectDraw7,0);
    	if FAILED(r) return false;
    
        r = ddMain->SetCooperativeLevel( m_hWnd, DDSCL_NORMAL );
        if FAILED(r) return false;
    	
    
    	// Create the primary surface
        DDSURFACEDESC2 ddsd;						    
        ZeroMemory( &ddsd, sizeof( ddsd ) );
        ddsd.dwSize = sizeof( ddsd );
        ddsd.dwFlags = DDSD_CAPS;
        ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
    
        r = ddMain->CreateSurface(&ddsd,&dsFront,NULL);
    	if FAILED(r) return false;
    	//---------------------------
    
    
    	// Create the backbuffer surface
        ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;        
        ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
        ddsd.dwWidth = dwWidth;
        ddsd.dwHeight = dwHeight;
    
    	r = ddMain->CreateSurface(&ddsd,&dsBack,NULL);
    	if FAILED(r) return false;
    	//------------------------------

  4. #4
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    As far as initialization code is concerned, yes that is right. Assuming that all your variables are initialized with valid values (dwWidth, m_hWnd, etc.) then that will set them up. But you would still need at least one other additional surface to hold your image(s).

    But this will handle just initialization. Do you have a main program loop that handles your blitting?

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    17
    Right now, all I need is to update the screen a few times every second, so I have a timer set to 250 milliseconds and the OnTimer code is simply:

    dsFront->Blt( NULL, dsBack, NULL, DDBLT_WAIT, NULL );

    Im kinda gettin it to work. My next question is this... I have another thread plotting pixels to dsBack by doin Lock(), then writing to the video memory, and then Unlock() (is there any other way?). This process takes 5-20sec usually, so I wanna redraw the screen a few times during this. However blitting the back buffer to the front doesn't work while its locked does it? Is there any way I could go about this without Locking/Unlocking the back buffer after every pixel, thats just unpractical.

    Could I skip this whole back buffer/front buffer thing and simply plot pixels directly to the front one. Will the screen still update while front buffer is locked??

    Also... do I need to set the clipper to the back surface as well??

    Thanks for all the help too, btw.
    Last edited by phatslug; 06-13-2002 at 09:16 PM.

  6. #6
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    It's an unfortunate fact that locking/unlocking surfaces slows things down quite a bit. The only other way that I know of to plot pixels would be using GDI which would be slower than DirectX. And, no, you don't need (or want for that matter) a clipper on the backbuffer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. console mode and service mode
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 06-01-2008, 01:42 AM
  2. Showing the directory sturcture
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 03-26-2002, 04:46 PM
  3. Implementing "ls -al"
    By pdstatha in forum Linux Programming
    Replies: 11
    Last Post: 03-20-2002, 04:39 AM
  4. Implementing "ls -al"
    By pdstatha in forum C Programming
    Replies: 7
    Last Post: 03-06-2002, 05:36 PM
  5. can someone check this out and let me know ?
    By javaz in forum C Programming
    Replies: 5
    Last Post: 01-21-2002, 02:13 PM