Changing resolution in Direct3D9 *solved*

Started by
11 comments, last by utilae 19 years, 1 month ago
I have created my back buffer at 1024x768. I have setup my 2d ortho matrix at 1024x768. Can I change the resolution by doing this to the vertex x and y coordinates:

vertex.x=(xPos/1024)*newResoultionX
vertex.y=(yPos/768)*newResoultionY



Basically the xPos and the yPos would be coordinates set in a 1024x768 resolution. So in order to convert them to a resolution different to the default of 1024x768, I divide them by the default resolution and then multiply by the new resoltion. Is this a good idea? Would I also have to resize the back buffer and the matrix? How would I do that? Can I just change the d3d9device presentation parameters for back buffer size and can I just create the matrix again at a new size? [Edited by - utilae on March 15, 2005 11:30:25 PM]

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

Advertisement
Well, I would say if it works, it works! However, if you do change your resolution you will probably have to re-create your Direct3D Device (with a new backbuffer width and height, and the new resolution). Also, make sure your vertex.x and vertex.y are floating point numbers.

I'm not really quite sure how its done in professional games, but it might be worth giving it a try.
Yes, you simply need to change your D3DPRESENT_PARAMETERS structure and then call IDirect3DDevice9::Reset(). This will reset the size of the entire swap chain automatically. I think this is *much* easier than how you are doing it now.

Note that if you have created any rendertargets, the size of them will be unaffected.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Quote:Original post by circlesoft
Yes, you simply need to change your D3DPRESENT_PARAMETERS structure and then call IDirect3DDevice9::Reset(). This will reset the size of the entire swap chain automatically.

Ok, sweet.

Quote:Original post by circlesoft
I think this is *much* easier than how you are doing it now.

Are you refering to this:
vertex.x=(xPos/1024)*newResoultionX
vertex.y=(yPos/768)*newResoultionY

If I don't do it that way how would I specify where a vertex is in pixels? eg if I want a vertex at 100,100 and another at 200,200 I specify the coordinates on the 1024x768 scale. If the current resolution is different, then the forumla converts the coordinates of the vertices to the right resolution.

Is there a better way?

[Edited by - utilae on March 14, 2005 9:46:07 PM]

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

How do I set the display mode?

I can use g_pD3DDevice9->GetAdapterDisplayMode to find out what display mode the user has, so I was wondering how you could set their display mode?

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

Quote:Original post by utilae
I can use g_pD3DDevice9->GetAdapterDisplayMode to find out what display mode the user has, so I was wondering how you could set their display mode?

All of the display mode stuff can be updated by changing the appropriate members of D3DPRESENT_PARAMETERS and calling IDirect3DDevice9::Reset().
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
The problem is that when I change the display mode to 800x600 (using the reset device method), the screen appears as a yellow 800x600 area (my background is yellow) within a black 1024x768 area.

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

If you're using a Ortho projection, you don't need to do that scaling yourself. You've set the projection to use 1024 virtual units along the X axis and they will be mapped to real units automatically.

Presumably you think you're seeing an 800x600 block in a 1024x768 screen, when you're actually seeing a scaled block in a 800x600 screen.
Stay Casual,KenDrunken Hyena
Quote:Original post by DrunkenHyena
If you're using a Ortho projection, you don't need to do that scaling yourself. You've set the projection to use 1024 virtual units along the X axis and they will be mapped to real units automatically.

Ok, that's cool. I'll get rid of the code that adjusts the vertices then.

Quote:Original post by DrunkenHyena
Presumably you think you're seeing an 800x600 block in a 1024x768 screen, when you're actually seeing a scaled block in a 800x600 screen.

I'm still having problems with a 800x600 block (yellow) inside a 1024x768 screen (black). I can use my monitor controls to stretch the 800x600 block to fit to the screen, but I souldn't have to do that.

Here's my code:
//at the very start I set the presentation parameters//g_nDefaultResoultionX=1024,g_nDefaultResoultionY=768	//set the presentation parameters	ZeroMemory(&g_d3dpp, sizeof(g_d3dpp));	g_d3dpp.BackBufferWidth=g_nDefaultResoultionX;	g_d3dpp.BackBufferHeight=g_nDefaultResoultionY;	g_d3dpp.BackBufferCount=1;	g_d3dpp.BackBufferFormat=D3DFMT_R5G6B5;	g_d3dpp.MultiSampleType=D3DMULTISAMPLE_NONE; //No multi-sampling	g_d3dpp.MultiSampleQuality=0;  	g_d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;	g_d3dpp.hDeviceWindow=hWndMain;	g_d3dpp.Windowed=false;	g_d3dpp.EnableAutoDepthStencil=true;//z buffer	g_d3dpp.AutoDepthStencilFormat=D3DFMT_D16;//z buffer	g_d3dpp.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT;	g_d3dpp.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;//setup 2d ortho matrixvoid SetupOrthoMatrix(void){	//setup matrix	D3DXMATRIX Ortho2D;		D3DXMATRIX Identity;	//1024x768 2d perspective (0 is near, 1 is far)	D3DXMatrixOrthoOffCenterLH(&Ortho2D,0,g_d3dpp.BackBufferWidth,g_d3dpp.BackBufferHeight,0,0.0,1.0);	D3DXMatrixIdentity(&Identity);	HRESULT hrProj=g_pD3DDevice9->SetTransform(D3DTS_PROJECTION,&Ortho2D);	HRESULT hrWorld=g_pD3DDevice9->SetTransform(D3DTS_WORLD,&Identity);	HRESULT hrView=g_pD3DDevice9->SetTransform(D3DTS_VIEW,&Identity);	//log errors	g_Log<<endl<<"SetupOrthoMatrix() Set Projection: "<<DXGetErrorString9(hrProj)<<endl;	g_Log<<"SetupOrthoMatrix() Set World: "<<DXGetErrorString9(hrWorld)<<endl;	g_Log<<"SetupOrthoMatrix() Set View: "<<DXGetErrorString9(hrView)<<endl<<endl;}void ChangeResolution(const int &newResoultionX,const int &newResoultionY,CTextureManager &TextureManager){	//set the size of the backbuffer to the new resolution	g_d3dpp.BackBufferWidth=newResoultionX;	g_d3dpp.BackBufferHeight=newResoultionY;	//FREE VOLATILE RESOURCES ( update as FreeVolatileResources() )	//free font resources	g_pFont->OnLostDevice();	//reset drd9 device	g_pD3DDevice9->Reset(&g_d3dpp);	HRESULT hr=g_pD3DDevice9->Reset(&g_d3dpp);	g_Log<<"Change resolution to "<<newResoultionX<<"x"<<newResoultionY<<": DeviceReset() "<<DXGetErrorString9(hr)<<endl;	if(SUCCEEDED(hr))	{		//INIT VOLATILE RESOURCES ( update as InitVolatileResources() )		//reset font resources		g_pFont->OnResetDevice();		//setup 2d ortho matrix		SetupOrthoMatrix();		//setup render states		SetupRenderStates();		//set last active texture or if the game is just starting set the default active texture		if(g_sLastActiveTexture=="")			TextureManager.SetTexture(g_sDefaultActiveTexture);		else			TextureManager.SetTexture(g_sLastActiveTexture);	}}



Can someone help me? Thanks

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

Anyone able to help? Drunken Hyena?

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

This topic is closed to new replies.

Advertisement