Setting up DirectX problems :(

Started by
3 comments, last by Samith 22 years, 2 months ago
Well, actually i didnt have any problems, just that i didnt know what i was doing. I just got the Isometric Game Programming with DirectX 7.0 book, im on chapter 5 and i dont know why we are doing the displaymode enumeration. this is the code thats bothering me:

bool Prog_Init()
{
        .
        .
        .
lpdd->SetCooperativeLevel(hWndMain,DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT);

	//enumerate the displaymodes
	dwDisplayModeCount=0;

	lpdd->EnumDisplayModes(0,NULL,NULL,EnumModesCallbackCount);

	DisplayModeList=new DisplayMode[dwDisplayModeCount];
	dwDisplayModeCount=0;

	lpdd->EnumDisplayModes(0,NULL,NULL,EnumModesCallbackList);

	//pick a display mode
	DisplayMode TestMode;
	TestMode.dwWidth=0;
	TestMode.dwHeight=0;
	TestMode.dwBPP=0;
	DWORD index;
	bool found=false;

	for(index=0;(indexTestMode.dwWidth)
			{
				TestMode.dwWidth=DisplayModeList[index].dwWidth;
				TestMode.dwHeight=DisplayModeList[index].dwHeight;
				TestMode.dwBPP=DisplayModeList[index].dwBPP;
				found=true;
			}
		}
	}

	if(!found)
	{
		return(false);
	}

	//set the display mode
	hr=lpdd->SetDisplayMode(TestMode.dwWidth,TestMode.dwHeight,TestMode.dwBPP,0,0);

	return(true);//return success
}

//enumeration-count
HRESULT WINAPI EnumModesCallbackCount(
  LPDDSURFACEDESC2 lpDDSurfaceDesc,  
  LPVOID lpContext                   
)
{
	//increment the count variable
	dwDisplayModeCount++;

	//continue the enumeration
	return(DDENUMRET_OK);
}

//enumeration-list
HRESULT WINAPI EnumModesCallbackList(
  LPDDSURFACEDESC2 lpDDSurfaceDesc,  
  LPVOID lpContext                   
)
{
	//copy applicable information to the list
	DisplayModeList[dwDisplayModeCount].dwWidth=lpDDSurfaceDesc->dwWidth;
	DisplayModeList[dwDisplayModeCount].dwHeight=lpDDSurfaceDesc->dwHeight;
	DisplayModeList[dwDisplayModeCount].dwBPP=lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount;

	//increment the count variable
	dwDisplayModeCount++;

	//continue the enumeration
	return(DDENUMRET_OK);
}
    
when i run the program it runs in a 1600x900 screen res, and i dont know why. and i dont even know why we are doing the enumerations, especially not the "EnumCallbackCount" function. what is the point of counting the display modes, and how does that function even work, all it does is say dwDisplayModeCount++ then returns, how does it use its parameters, and what is incrementing dwDisplayModeCount going to do?? thank you for trying reading this, and thanks again if you respond- Samith Edited by - Samith on February 16, 2002 3:04:14 PM Edited by - Samith on February 16, 2002 3:05:04 PM
Advertisement
I posted on irc but you didn''t respond this is what i said : change your set display mode function to this :
 hr=lpdd->SetDisplayMode(640/*width*/,480/*height*/,16/*bpp*/,0,0); 


Eric Wright o0Programmer0o

NeXe

My Homepage
Eric Wright o0Programmer0o
thank you, but, why are we deviding by width and height etc?
quote:Original post by Samith
thank you, but, why are we deviding by width and height etc?

Those are C-style comments. Anything between /* and */ is a comment.
// This is a C++-style comment. Everything to the end of this line will be ignored/* This is a C-style comment.   It can range over several lines,   and it can appear in the middle of executable code: */int main( void /* take no parameters */ ){  return 0;} 

This is just another example of the expressive power of C and C++.

I wanna work for Microsoft!
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
Enumeration of display modes is basically just listing of all display modes that are present in your system. KingsRevenge posted a way to set your display mode without knowing _all_ available display modes. Assuming that any video card can run in 640x480x16 bit (which is a good assumption), this code will always work.

However, what if you want to run in a higher resolution mode? 1024x768, or 1600x1200, for example. Not all systems may support those. Hence the need to know what video modes are present. The process of listing all those modes is called "enumeration."

It works like this: you call DDraw function EnumDisplayModes and give it a pointer to your function ("callback") that is called for each display mode present in the particular system. The LPDDSURFACEDESC2 parameter contains useful information about that display mode.

What this code does is it lists all display modes present and selects the one with highest horizontal resolution (see the most indented if statements). This explains why it was choosing 1600x900 - your system probably supports at most 1600 pixel horizontally. This code will not select 1600x1200 if it''s present.

Enumeration is done in two steps. First, the number of display modes available is determined. EnumModesCallbackCount increments a (global?) variable containing the number of modes. It does not "choose" display modes, or store any information about them (yet). Now, an array is allocated via new to store information about display modes. Then, enumeration is done again with EnumModesCallbackList as the callback function, which actually stores information about modes found in the newly allocated array.

If you don''t need/want to set your display mode to anything other than 640x480x16 bit, you probably can ignore the enumeration part of setting up DDraw and do what KingsRevenge says.
---visit #directxdev on afternet <- not just for directx, despite the name

This topic is closed to new replies.

Advertisement