using ddraw in directx9.0

Started by
8 comments, last by sakky 19 years, 7 months ago
I'm having a problem with using the CDisplay and CSurface classes. The images I have created flicker so I think that I'm not flipping correctly BUT isn't that all handled by the CDisplay class using: Present() ? Anyway, I'm loading bitmaps like this: TotalScreen->CreateSurfaceFromBitmap(&tmpFrame,PathName,width,height); and TotalScreen->Clear(0); TotalScreen->Blt(xPos,yPos,Surface_1, 0); TotalScreen->Blt(xPos,yPos,Surface_2, 0); ... TotalScreen->Blt(xPos,yPos,Surface_n, 0); TotalScreen->Present(); Then I read something that said you can't flip unless your in full screen mode (is this true?)so I changed : if(FAILED(TotalScreen->CreateWindowedDisplay(hWnd,640,480))) ... to if(FAILED(TotalScreen->CreateFullScreenDisplay(hWnd,640,680,16))) which Failed, returning my message "Failed to Initialize DirectDraw" Am I missing something and/or have I got the right idea?
Don't mug ya self!
Advertisement
I havn't used those classes particularly, but I do remember in directdraw if you didn't set the cooperative level or something correctly, you could not set the fullscreen bitsperpixel to anything different than what the desktop colors were set to. Alot of games seemed to have this problem actually (And I'm quite surprised). I havn't used directdraw in over 6 years, so I can't remember the exact incarnation.
I think that it is true, you cannot flip in windowed mode. If you don't create your full screen window with the proper window properties (WS_MAXIMIZED and the one that specifies always on top and possibly something else), then it can flicker in full screen because windows desktop is trying to refresh over it. Does it flicker all of the time, when no movement is present? Or does it only flicker on the objects you draw each frame? If it flickers when they move, it could be tearing or shearing, which means you're trying to update the screen faster than your monitor's refresh rate.

Chris
Chris ByersMicrosoft DirectX MVP - 2005
In windowed mode the blitted frames are static (just a series of stationary bitmaps displayed on the screen). In full screen mode VC++ crashes on linking.
If i only show 3 or 4 bitmaps at once its OK but when I try to display 20 or so it starts flckering and even slows down to a scroll up the screen with more.
check out the classes in ddutil.h from the directx 9.0 sdk
I got this technique from an article on this site, it was called something like "Direct Draw the Easy Way"
Does my technique seem correct?

Don't mug ya self!
I'm confused about something. You said Visual C++ crashes on linking when you change to full screen mode? What do you mean? And this problem only occurs in full screen mode, correct?

EDIT: Nevermind, I went back and read your first message. I think you meant it crashed at run-time. Anyway, (hWnd,640,680,16) should read (hWnd,640,480,16) instead. If you attempt to create a fullscreen window with odd width/height combinations, it won't work. Only the supported screen resolutions will be valid, i.e. 640x480x8, 640x480x16, 800x600x32, etc.

Chris
Chris ByersMicrosoft DirectX MVP - 2005
OH MY GOD!
You wouldn't believe how many times I have read through this code and I didn't see that.
Sorry I'm and idiot.
Thanks heaps for that.
However I am still getting the flicker. It's faster in the full screen mode but it's very evident.
Any ideas?
Don't mug ya self!
Did you check into the requirements for creating your window that I mentioned previously. Specifically, show me your window creation and registration code.

EDIT: I just noticed you said it's faster in full screen mode, so you must be getting it in windowed mode too. It could be that y ou are trying to update the screen faster than your monitor's vertical refresh rate. Put a timer between frames to render only at 30 FPS (33 ms). Don't keep it, it's just for trying to determine if that's the problem.

Chris
Chris ByersMicrosoft DirectX MVP - 2005
Quote:
Supernat02
I think that it is true, you cannot flip in windowed mode. If you don't create your full screen window with the proper window properties (WS_MAXIMIZED and the one that specifies always on top and possibly something else), then it can flicker in full screen because windows desktop is trying to refresh over it.


That is crap! You do not need to specify any special maximized window properties or always on-top properties. DirectDraw takes over whole screen, hence, the user of set cooperative level so that windows and DirectDraw are not fighting over the display surfaces.

LOOK! Stop using those classes and implement your own DirectDraw code! None of this information is going to be of use to you if your using some sort of wrapper class that doesn’t let you configure DirectDraw your self (most of them don’t).

Take from me, the only thing you need from your window really, is the handle. Look at my code.
// Like the DirectDraw liraries manually// I hate dealing with project settings//#pragma comment ( lib, "DXGUID.LIB" )#pragma comment ( lib, "DDRAW.LIB" )#include <WINDOWS.H>#include <DDRAW.H>LPDIRECTDRAWSURFACE 	g_lpDDSPrimary 	= NULL;LPDIRECTDRAWSURFACE 	g_lpDDSBack	= NULL;LPDIRECTDRAW		g_lpDD		= NULL;LPCSTR			g_szClassName	= "IVAN";// Initialize DirectDraw//HRESULT DDInitializeFullscreen( HWND hWnd ){	DDSURFACEDESC	ddsd;	HRESUTL		hRet;	// Ussally I wouldn't put the window initialization code with	// the DirectDraw intialization code, but for you sake, I'll do it!	// I wanted to prove to you that you did not need special creation flags	// I’ve never used them	//	hWnd = CreateWindow( g_szClassName,			     "This is a test",			     WS_POPUP,			     0, 			     0, 			     640, 			     480,			     NULL,			     NULL,			     hInstance,			     NULL );	// Make sure the window was created	//	if ( !hWnd )	{		return E_FAIL;	}	else	{		ShowWindow( hWnd, SW_SHOW );		UpdateWindow( hWnd );	}	// Create parent DirectDraw interface	//	if ( FAILED( hRet = DirectDrawCreate( NULL, &g_lpDD, NULL ) ) )	{		return hRet;	}	// Make sure to cooperate with Windows in full screen mode	//	if ( FAILED( hRet = g_lpDD->SetCooperativeLevel( hWnd,		DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE ) ) )	{		return hRet;	}	// Lets set htedisplay mode to something easy to deal with	//	if ( FAILED( hRet = g_lpDD->SetDisplayMode( 640, 480, 16 ) ) )	{		return hRet;	}	// Setup the display surface parameters	//	memset( &ddsd, 0, sizeof( DDSURFACEDESC ) );		ddsd.dwSize		= sizeof( DDSURFACEDESC );	ddsd.dwFlags		= DDSD_CAPS | DDSD_BACKBUFFERCOUNT;	ddsd.ddsCaps.dwCaps	= DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_PRIMARYSURFACE;	ddsd.dwBackBufferCount	= 1;		// Create the primary surface	//	if ( FAILED( hRet = g_lpDD->CreateSurface( &ddsd, &g_lpDDSPrimary, NULL ) ) )	{		return hRet;	}	// Attach the back buffer now	//	ddsd.ddsCaps.dwCaps	= DDSCAPS_BACKBUFFER;	if ( FAILED( hRet = g_lpDDSPrimary->GetAttachedSurface( &ddsd.ddsCaps, &g_lpDDSBack ) ) )	{		return hRet;	}	// We are done :) Now we have a full screen DirectDraw application ready to // do some drawing, so return success	//	return DD_OK;}


I just coded that with Notepad in 3 minutes. I’ve done DirectDraw so many times I got sick of it and moved to Direct3D (now DirectGraphics).

One problem that can make you application flicker would be the incorrect use of the primary display surfaces. IF you have a back buffer, use it. Draw to the back buffer only, NOT THE PRIMARY SURFACE! The user the primary surface to flip. But just because you did this, does not mean you can draw to the primary surface. You always ONLY draw to the back buffer, then flip using the primary surface. Unless you are in windowed mode or not using double buffered surfaces. If you are not using double buffered surfaces, then that is why you are probably having the flicker problem.

Let me see your code! Email it to me and I will take a look at it.
Take back the internet with the most awsome browser around, FireFox
You are entitled to your opinion, even if it is wrong. I do not just post any old crap on the board. This is from my experience with DirectDraw as well as a lot of research. Feel free to browse the following websites I've found on the topic, and next time you THINK you are right and that the rest of the world is wrong, why don't you be a LOT more polite about it. I may not always post the right answer, but I certainly try not to make a habit of offending others on the site. If it were up to me, you'd be banned.

Website 1
Website 2
Website 3
Website 4
Website 5

I hope these help you out too Tadobie.

Chris
Chris ByersMicrosoft DirectX MVP - 2005
Now listen son. It’s not like now one was never rude to me on this site. You take things the wrong way! I never met to offend you, but if you think I should be banned, I’m glad I did. I was just trying to show why I though you were wrong. True, I could have been a lot nicer about it.

You assume too much. I don’t think I’m, right and every one else is wrong. In fact I think more the opposite of that, but oh well. All I try to do is help and give out information, just like you. I see you said something wrong so I called you on it. I should have been nicer, but I’m sorry.

Even if I do get banned or put on probation again, every thing is still the same. I’ve helped other people a lot and they appreciated it. I’m sure you have too. But I knew your statement was wrong so I called you one it. Next time I’ll be nicer……………..

I guess I let a little anger and frustration out on you. You doc me so I doc you. So let’s shake hands and call it good. I kid a lot and some times I get to out of hand and don’t realize it, so sorry again Chris. But I guess I deserved that, but you can stop now. I’m man enough to admit that I was wrong.

But oh well…..
Take back the internet with the most awsome browser around, FireFox

This topic is closed to new replies.

Advertisement