• Advertisement

Archived

This topic is now archived and is closed to further replies.

User specified resolution

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

At the moment, I am choosing the display mode for when my app switches to full screen as follows:
	// get the number of modes we have on the device
	UINT num = m_pD3D->GetAdapterModeCount(D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8);
	// enumerate available devices
	m_pD3D->EnumAdapterModes(D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8, num-1, &m_display);  
Im using the assumption that the last mode is the highest resolution and bit depth. This seems to be the case and it works great, except for on my laptop where the LCD cant display the highest resolution supported. What I want to do is have a setup file where the resolution is stored. What I want to know is how do I change the above code to get the best mode in a defined resolution? --- The second question is that I currently compile with the following line of code:
	// Create the Direct3D device
	// Assumptions made: using default adapter
	//                   the card can support hardware vertex processing
	if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_HARDWARE_VERTEXPROCESSING, &m_d3dpp, &m_pd3dDevice)))
			return E_FAIL;							// failure 
I would like to change it so that it will use hardware vertex processing when it is supported by the graphics card in the system, otherwise use software vertex processing. How would I do this? --- Thanks in advance. Kieran [edited by - Kieran on January 13, 2004 9:53:18 AM]

Share this post


Link to post
Share on other sites
Advertisement
Well,
I cant say much about your first problem as i am new to DX myself.

As for the second problem , the following code should solve it.

if( FAILED( g_pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &m_D3DCaps ) ) )
{
return (g_pError->HandleError( "HRESULT CRoadMaxApp::InitializeD3D()" , ERROR_TYPE_D3D ) );
}
DWORD VertexProcessing = 0;

if(m_D3DCaps.VertexProcessingCaps != 0)
VertexProcessing |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
else
VertexProcessing |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;

if you dont know, then first we get the D3DCAPS ffrom GetDeviceCaps() and then test the DeviceCaps for vertexprocessing. if not zero, then your system supports HARDWARE_VERTEXPROCESSING else software. Now ,use variable VertexProcessing in the foloowing code

if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd,
VertexProcessing,
&m_d3dpp, &g_pD3DDevice)))

where, m_d3dpp is a D3DPRESENT_PARAMETERS structure

Share this post


Link to post
Share on other sites
I thought that EnumAdapterModes() only returned modes that would work with your configuration, but maybe they are not guaranteed to work with the monitor, just the device. Maybe CheckDeviceFormat() would work

Share this post


Link to post
Share on other sites
iron_monkey: That works great, thanks. I was just wondering, why use
|= 
instead of just
= 
when assigning the vertex processing type? I can see that it works, but is there a reason that = isnt used?

circlesoft: On most systems, the returned modes are OK, but my laptop (possibly down to a bad monitor driver) thinks it can do higher resolutions than the monitor will handle. I looked into CheckDeviceFormat(), but thats not really what Im looking for. I simply want to enumerate at a specific resolution that I specify (via a setup file).

Thanks for the help so far!
Kieran

Share this post


Link to post
Share on other sites
Ahh okay I see.

What you need to do then is use the std library or some other file input/output library to read the info in from your file. I know that with std::ifstream it is very easy. Look around for some tutorials maybe

Share this post


Link to post
Share on other sites
Yes, but how do I get DirectX to just enumerate modes that match a certain resolution?

[edit] After a think about it, I wont use a setup file. What I want it to do is use the resolution that is set on the desktop of the computer. So now, the question is, how do we retreive this information, and still, how do we enumerate only the modes matching that resolution?[/edit]

[edited by - Kieran on January 13, 2004 2:43:06 PM]

Share this post


Link to post
Share on other sites
I have worked it out. Very easy actually:

// go through the modes finding the correct one
for (UINT i=num; i>0; i--)
{
// enumerate available devices
m_pD3D->EnumAdapterModes(D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8, i-1, &m_display);
if (m_display.Width == 800 && m_display.Height == 600) break;
}


Ive decided to go against my last post and have a setup file as it will be better if the user can change to the resolution they want.

My questions are pretty much answered now, so thanks a lot all.

One last thing though, from above, why |= and not = ?


[edited by - Kieran on January 13, 2004 2:54:48 PM]

[edited by - Kieran on January 13, 2004 2:55:45 PM]

Share this post


Link to post
Share on other sites
If anyone is interested, this is how I have loaded the resolutions from file:

	// open resolution setup file
std::ifstream inputf("setup/res.txt");
// if file not open, try other folder
if (!inputf.is_open())
{
// try opening file again
std::ifstream inputf("..\\setup/res.txt");
// if still not open, quit
if (!inputf.is_open()) PostQuitMessage(0);
}
// to hold width and height
UINT w, h;
inputf >> w;
inputf >> h;
// close file
inputf.close();


Then this finds the best mode at that resolution:

	// go through the modes finding the correct one
for (UINT i=num; i>0; i--)
{
// enumerate available devices
m_pD3D->EnumAdapterModes(D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8, i-1, &m_display);
if (m_display.Width == w && m_display.Height == h) break;
}

Share this post


Link to post
Share on other sites
Well keiran , you could use ''='' sign as well. I use this ''|='' convention only when you can assign several values to a variable such as for example dwFlags type which the values is the result of ''OR''ing individual values. I just used it y''know, since i too i am new in DX, there are so many things that can be assigned so many values by ''OR''ing them. So, i thought what if Vertex processing could have other values? So, you could OR them( if they could be ) and you will get the required result.

Share this post


Link to post
Share on other sites
That sounds sensible. Out of interest, which is the faster operation, ''|='' or ''='' ? I woulc have thought that it is ''='' as ''|='' requires a comparison between all the bits?

Share this post


Link to post
Share on other sites
Well Keiran, I think the assignment operator '=' runs faster than '|=' operation.Not because it requires comparison....your processor can handle that very well in a single cycle of execution( at the processor level ) If you know a bit of ASM( Assembly Level Language ), then an assignment requires the following one instruction only say:

MOV Mem1,VAL1

where Mem1 is the address of memory location having your DWORD VertexProcessing variable and VAL1 the value to assign to that memory location.Whereas, '|=' could be in ASM as say:

MOV EAX,Mem1
OR EAX,VAL1
MOV Mem1,EAX

As far as i know( I left ASM Programming for quite a while ).
All Calculations concering mathematical or logical operations must contain atleast one operand in a CPU register( The Accumulator ). So,we need to transfer Mem1 to EAX as,the result of an operation is indicated by contents of accumulator and status flags and so,as the final result'|=' should be in Mem1, so is the operation. then perform ORing with the Value and then copy final contents of Acc. to Mem1.

So, Technically speaking, we are saving a few CPU clock cycles in the first case.

[edited by - iron_monkey on January 14, 2004 11:32:38 AM]

Share this post


Link to post
Share on other sites
But lets be honest, who really cares as its outside the rendering loop! Thanks for the reply though.

[edited by - Kieran on January 14, 2004 2:40:54 PM]

Share this post


Link to post
Share on other sites
Based on the way that Intel architecture works, I''d be surprised if there was a measurable difference between the speed of "=" and "|=" even in a tight loop. I''d be interested to see results though if someone wanted to run them

Share this post


Link to post
Share on other sites
Andy : Ofcourse there is no visual measurable difference in these operations....If you were going to calculate time in nanoseconds or microseconds then these things count.Unless you meant to run your program at an epic time-scale like say a milion years or more ,then only some ''measurable'' difference would occur and that too in say some seconds or less.

As for keiran: The reply was meant for the difference in the execution speed of both operations and was for a more technical understanding rather than saving ''Measurable'' processing times . It has nothing meaningful to do with program development as time difference is negligible( That is why i said "TECHNICALLY" ). As for AMD, i dont know its architecture at all so cant comment on this.

Share this post


Link to post
Share on other sites

  • Advertisement