   320x240 resolution - standby
  Hi guys, im trying to create a RPG with DX9, using polygones to render 16x16 tiles and sprites, like good old snes style. I decided to make it in 320x240 resolution cuz im a horrible artist ^^, and small tiles are easier to draw. Its running really really good on my pc, and most other pc's i tried, but still on some systems i got a problem. When i try to start the game there and it sets the 320x240 mode, the CreateDevice returns an error, that there was an invalide call, OR and thats pretty strange, it shuts of the monitor to standby 8[. It works ok if i change the res to 640x480, but there the game is ugly "small". Anyone got an idea why that happens?maybe the initialization code helps a little, it just loads the resolution and fullscreen options from ini, set to 320 240 truebool ILSN_D3D::Initialize (HINSTANCE a_mainInstance,    ILSN_String a_windowClassName,    ILSN_Ini_Node* a_node, bool a_initByDialog){HRESULT result;int n  = 0;int n2 = 0;m_mainInstance = a_mainInstance;// Create the D3D object.s_d3D = Direct3DCreate9(D3D_SDK_VERSION);if (s_d3D == NULL) return false;ILSN_Log ("Initializing DirectGraphics9\n");//////////////////////////////////////////////////////////////////////// Load the enviroment//////////////////////////////////////////////////////////////////////// First get adapters_enviroment.m_numAdapter = s_d3D->GetAdapterCount();Assert (s_enviroment.m_numAdapter < 5,"To many Adapter found, only 5 will be shown");Assert (s_enviroment.m_numAdapter != 0,"No 3D Accelerator found!");ILSN_Log ("%i 3dCards found\n",s_enviroment.m_numAdapter);for (n = 0; n < s_enviroment.m_numAdapter; n ++){result = s_d3D->GetAdapterIdentifier (n,0,&s_enviroment.m_adapter [n].m_adapter);}// Next the res-modesint numValidFormats32 = 2;int numValidFormats16 = 3;const D3DFORMAT validFormats32[] ={   D3DFMT_A8R8G8B8,   D3DFMT_X8R8G8B8,    };const D3DFORMAT validFormats16[] ={D3DFMT_A1R5G5B5,   D3DFMT_X1R5G5B5,   D3DFMT_R5G6B5,    };    // Find a good pixelformat for every bitrate and adapter.// Then find every display modeD3DDISPLAYMODE desktopMode;s_d3D->GetAdapterDisplayMode(0, &desktopMode );s_enviroment.m_refreshRate = desktopMode.RefreshRate;    for(n = 0; n < s_enviroment.m_numAdapter; n ++)    {s_enviroment.m_adapter [n].m_format16 = D3DFMT_UNKNOWN;s_enviroment.m_adapter [n].m_format32 = D3DFMT_UNKNOWN;s_enviroment.m_adapter [n].m_formatDesktop = desktopMode.Format;// Get best 32 bit display formatfor (n2 = 0; n2 < numValidFormats32; n2 ++){if( SUCCEEDED( s_d3D->CheckDeviceType( n, D3DDEVTYPE_HAL, validFormats32[n2], validFormats32[n2], false ))){s_enviroment.m_adapter [n].m_format32 = validFormats32[n2];break;}}// Get 32 bit display modess_enviroment.m_adapter [n].m_numDisplayModes32 = s_d3D->GetAdapterModeCount(n, s_enviroment.m_adapter [n].m_format32);for (n2 = 0; n2 < s_enviroment.m_adapter [n].m_numDisplayModes32; n2 ++){D3DDISPLAYMODE newMode;s_d3D->EnumAdapterModes (n, s_enviroment.m_adapter [n].m_format32, n2,&newMode);if (newMode.RefreshRate == s_enviroment.m_refreshRate)s_enviroment.m_adapter [n].m_DisplayModes32.push_back (newMode);}s_enviroment.m_adapter [n].m_numDisplayModes32 =s_enviroment.m_adapter [n].m_DisplayModes32.size();std::sort(s_enviroment.m_adapter [n].m_DisplayModes32.begin(),  s_enviroment.m_adapter [n].m_DisplayModes32.end(),  Less());// Get best 16 bit formatfor (n2 = 0; n2 < numValidFormats16; n2 ++){if( SUCCEEDED( s_d3D->CheckDeviceType( n, D3DDEVTYPE_HAL, validFormats16[n2], validFormats16[n2], false ))){s_enviroment.m_adapter [n].m_format16 = validFormats16[n2];break;}}// Get 16 bit display modess_enviroment.m_adapter [n].m_numDisplayModes16 = s_d3D->GetAdapterModeCount(n, s_enviroment.m_adapter [n].m_format16);for (n2 = 0; n2 < s_enviroment.m_adapter [n].m_numDisplayModes16; n2 ++){D3DDISPLAYMODE newMode;s_d3D->EnumAdapterModes (n, s_enviroment.m_adapter [n].m_format16, n2,&newMode);if (newMode.RefreshRate == s_enviroment.m_refreshRate)s_enviroment.m_adapter [n].m_DisplayModes16.push_back (newMode);}s_enviroment.m_adapter [n].m_numDisplayModes16 =s_enviroment.m_adapter [n].m_DisplayModes16.size();std::sort(s_enviroment.m_adapter [n].m_DisplayModes16.begin(),  s_enviroment.m_adapter [n].m_DisplayModes16.end(),  Less());// Get desktop display modes (windowed)s_enviroment.m_adapter [n].m_numDisplayModesDesktop = s_d3D->GetAdapterModeCount(n, s_enviroment.m_adapter [n].m_formatDesktop);for (n2 = 0; n2 < s_enviroment.m_adapter [n].m_numDisplayModesDesktop; n2 ++){D3DDISPLAYMODE newMode;s_d3D->EnumAdapterModes (n, s_enviroment.m_adapter [n].m_formatDesktop, n2,&newMode);if (newMode.RefreshRate == s_enviroment.m_refreshRate)s_enviroment.m_adapter [n].m_DisplayModesDesktop.push_back (newMode);}s_enviroment.m_adapter [n].m_numDisplayModesDesktop =s_enviroment.m_adapter [n].m_DisplayModesDesktop.size();std::sort(s_enviroment.m_adapter [n].m_DisplayModesDesktop.begin(),  s_enviroment.m_adapter [n].m_DisplayModesDesktop.end(),  Less());    }ILSN_Log ("Best display formats found\n");//////////////////////////////////////////////////////////////////////// Create the device//////////////////////////////////////////////////////////////////////if (a_initByDialog){ILSN_Log ("Initializing by Dialog\n");if (!InitDeviceByDialog ()){ILSN_Log ("Initialize failed\n");return false;}}else {ILSN_Log ("Initializing by ini\n");if (!InitDeviceByIni (a_node)){ILSN_Log ("Initialize failed\n");return false;}}// at last we have to find a textureformat for the current mode// Now find a good texture formatint numValidTextureFormats = 3;const D3DFORMAT validTextureFormats[] ={   D3DFMT_A8R8G8B8,   D3DFMT_A4R4G4B4,   D3DFMT_A1R5G5B5,    };    // Find a format that is supported as a texture map for the current mode    for(n = 0; n < numValidTextureFormats; n++ )    {   if( SUCCEEDED( s_d3D->CheckDeviceFormat( s_enviroment.m_currentAdapter, D3DDEVTYPE_HAL, s_enviroment.m_format, 0, D3DRTYPE_TEXTURE, validTextureFormats[n])))   {  s_enviroment.m_textureFormat = validTextureFormats[n];  break;   }    }ILSN_Log ("found best texture format\n");// Now create the windowDWORD style;if(s_enviroment.m_fullScreen){style  = WS_POPUP;}else{style  = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME |  WS_MINIMIZEBOX | WS_VISIBLE;}// calc fixed window rectRECT rc;SetRect( &rc, 0, 0, s_enviroment.m_screenWidth, s_enviroment.m_screenHeight );AdjustWindowRect( &rc, style, false);ILSN_Log ("Creating window\n");m_mainWindow = CreateWindow (a_windowClassName.c_str(),  a_windowClassName.c_str(), style, CW_USEDEFAULT, CW_USEDEFAULT, (rc.right-rc.left), (rc.bottom-rc.top), 0, 0,   m_mainInstance, 0);if (m_mainWindow == NULL){Assert (false,"Couldn't init Main Window");return false;}ShowWindow   (m_mainWindow,SW_SHOW);UpdateWindow (m_mainWindow);SetFocus(m_mainWindow);// Create the devices_d3D->GetDeviceCaps(s_enviroment.m_currentAdapter,D3DDEVTYPE_HAL, &s_enviroment.m_adapterDeviceCaps);// Check stencilbuffer availableresult = s_d3D->CheckDepthStencilMatch(s_enviroment.m_currentAdapter,D3DDEVTYPE_HAL, s_enviroment.m_format, s_enviroment.m_format,D3DFMT_D32);if (result == S_OK) {s_enviroment.m_stencilFormat = D3DFMT_D32;}else{ILSN_Log ("Stencil format or Stencil buffer may be false\n");result = s_d3D->CheckDepthStencilMatch(s_enviroment.m_currentAdapter,D3DDEVTYPE_HAL, s_enviroment.m_format, s_enviroment.m_format,D3DFMT_D16);if (result == S_OK) s_enviroment.m_stencilFormat = D3DFMT_D16;}    D3DPRESENT_PARAMETERS d3dpp;ZeroMemory( &d3dpp, sizeof(d3dpp) );if (s_enviroment.m_fullScreen){d3dpp.BackBufferWidth  = s_enviroment.m_screenWidth;d3dpp.BackBufferHeight = s_enviroment.m_screenHeight;}d3dpp.hDeviceWindow = m_mainWindow;    d3dpp.Windowed = !s_enviroment.m_fullScreen;    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    d3dpp.BackBufferFormat = s_enviroment.m_format;    d3dpp.EnableAutoDepthStencil = true;    d3dpp.AutoDepthStencilFormat = s_enviroment.m_stencilFormat;ILSN_Log ("Creating device\n");    result = s_d3D->CreateDevice( s_enviroment.m_currentAdapter,  D3DDEVTYPE_HAL, m_mainWindow,D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp, &s_d3DDevice );    if (result != S_OK){switch (result){case D3DERR_INVALIDCALL:Assert (false,"Invalid call to CreateDevice! Parameter may be invalid");break;case D3DERR_NOTAVAILABLE:Assert (false,"Device is not available, maybe wrong DirectX version");break;case D3DERR_OUTOFVIDEOMEMORY:Assert (false,"Out of Videomemory");break;default:Assert (false,"Unknown error during D3D Device initialization");break;}// give it another tryresult = s_d3D->CreateDevice( s_enviroment.m_currentAdapter,  D3DDEVTYPE_HAL, m_mainWindow,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp, &s_d3DDevice );if (result != S_OK){switch (result){case D3DERR_INVALIDCALL:Assert (false,"Invalid call to CreateDevice! Parameter may be invalid");break;case D3DERR_NOTAVAILABLE:Assert (false,"Device is not available, maybe wrong DirectX version");break;case D3DERR_OUTOFVIDEOMEMORY:Assert (false,"Out of Videomemory");break;default:Assert (false,"Unknown error during D3D Device initialization");break;}return false;}}}
  Use 640x480, then render everything scaled in 2x.   ;  There is a Device->Present method that takes a rectangle as a parameter. Set the display to 640x480, but have Present only display the top-left 320x240 area.   ;  Or you might be able to try and make a matrix that automatically scales the images.Something like:   D3DXMATRIX Ortho2D;D3DXMATRIX Identity;D3DXMatrixOrthoLH(&Ortho2D, 320.0f, 240.0f, 0.0f, 1.0f);D3DXMatrixIdentity(&Identity);m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &Ortho2D);m_pD3DDevice->SetTransform(D3DTS_WORLD, &Identity);m_pD3DDevice->SetTransform(D3DTS_VIEW, &Identity);in your D3D Init function. Im kinda new to it all, so im not sure if it will completely work, buts its been working for me so far. This way, no matter what resolution you set it at, the images will automatically be stretched to the screen size while the 'relative' resolution is still 320x240. This is also good for LCD's which have to have their native resolution for optimal image quality (thats the main reason im doing it).Cheers!   ;  The easiest way I see is to do what I do.  Create your screen resolution at 640x480, then set up your orthographic projection to use the resolution of 320x240.  That way, all of your drawing is done in a 320x240 space, but you still have the higher resolution, so if you have filtering of the textures on, your graphics will still be 320x240, but not as blocky.[Edit]Dyamios beat me to it =P   ;  Hehehe, well, atleast I know im not alone with that method :P   ;  You can also work with a 320x240 render target, then stretch it to whatever display you want. This will give you the precise pixel rendering you might want, and allow you to do some other effects with that render target, like fading.   ;  thx guys, all those methods worked ^^, but i decided to stretch the tiles by myself and set the screenmode to 640x480. That way i can get up a menu with betterresolution, fonts as well, and i can zoom around a bit, or use a minimap in real size tiles :D.   ;  Make your code work in any resolution -- one of the coolest features of D3D, and it's easy! (compared to say DDraw where this would be a LOT more work.)  Also I have had problems setting things to small resolutions if the refresh rate is invalid somehow (ie, screwed with in NVidia Refresh Tool or something like that.)   