Jump to content

  • Log In with Google      Sign In   
  • Create Account

sunnysideup

Member Since 01 Nov 2012
Offline Last Active Aug 21 2013 10:42 PM

Topics I've Started

A question about wglChoosePixelFormatARB()

21 August 2013 - 02:30 PM

I'm a little confused. Whenever I call wglChoosePixelFormatARB() what exactly am I supposed to do with the returned pixel format? Should I call SetPixelFormat() passing int the returned pixel format as the second paramater? If so should I pass NULL for the PIXELFORMATDESCRIPTOR parameter?

 

Here's the bit of code in question:

UINT pixFormatCount = 0;

// Specify the desired pixel attributes for frame buffer.
int pixAttribs [] =
{
	WGL_DRAW_TO_WINDOW_ARB,                       1,  // Can be drawn to window.
	WGL_DEPTH_BITS_ARB,                          24,  // 24 bits for depth buffer.
	WGL_STENCIL_BITS_ARB,                         8,  // 8 bits for stencil buffer.
	WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,  // Use hardware acceleration.
	WGL_SWAP_METHOD_ARB,      WGL_SWAP_EXCHANGE_ARB,  // Exchange front and back buffer instead of copy.
	WGL_SAMPLES_ARB,                              4,  // 4x MSAA.
	WGL_SUPPORT_OPENGL_ARB,                       1,  // Support OpenGL rendering.
	WGL_DOUBLE_BUFFER_ARB,                        1,  // Enable double-buffering.
	WGL_PIXEL_TYPE_ARB,           WGL_TYPE_RGBA_ARB,  // RGBA color mode.
	WGL_COLOR_BITS_ARB,                          32,  // 32 bit color.
	WGL_RED_BITS_ARB,                             8,  // 8 bits for red.
	WGL_GREEN_BITS_ARB,                           8,  // 8 bits for green.
	WGL_BLUE_BITS_ARB,                            8,  // 8 bits for blue.
	WGL_ALPHA_BITS_ARB,                           8,  // 8 bits for alpha.
	0                                              
};

int pixelFormat = 0;

// Find pixel formats that match our pixel attributes.
BOOL result = wglChoosePixelFormatARB(m_hDC, 
	                              &pixAttribs[0], 
                                      NULL, 
                                      1, 
				      &pixelFormat, 
				      &pixFormatCount);
		
// <-- What do I do now?
SetPixelFormat(m_hDC, pixelFormat, NULL); // <-- Is this correct?

The book I'm reading explains how to choose a pixel format, how to enumerate available pixel formats, and how to query individual attributes, but it doesn't explain what I'm supposed to do with the pixel format.


D3D11CreateDevice returns wrong feature level

27 July 2013 - 04:15 AM

I have a GTX 570 graphics card which SHOULD support DirectX 11, but the highest feature level that D3D11CreateDevice selects is 10_1. I had a look around on these forums and it seems that other people have had this problem and that it might be Nvidia Optimus selecting the Intel integrated graphics chipset instead of the dedicated Nvidia GPU. So I added my .exe to the list of programs in the Nvidia control panel and then used the following code to iterate through the available adapters to hopefully select the correct adapter.

 

Here's the code:

	/* Create the dxgi factory. */
	Microsoft::WRL::ComPtr<IDXGIFactory1> dxgi_factory;
	HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory2), (void**)&dxgi_factory);

	if (FAILED(hr)) {
		throw std::runtime_error("Failed to create dxgi factory.");
	}

	if (FAILED(dxgi_factory.As(&m_dxgi_factory))) {
		throw std::runtime_error("Failed to obtain IDXGIFactory2 interface.");
	}

	D3D_FEATURE_LEVEL feature_levels[] = 
	{
		D3D_FEATURE_LEVEL_11_1,
		D3D_FEATURE_LEVEL_11_0,
		D3D_FEATURE_LEVEL_10_1,
		D3D_FEATURE_LEVEL_10_0,
		D3D_FEATURE_LEVEL_9_3
	};

    int num_feature_levels = ARRAYSIZE(feature_levels);

	Microsoft::WRL::ComPtr<ID3D11Device> device;
	Microsoft::WRL::ComPtr<ID3D11DeviceContext> context;
	
	/* Iterate through each feature level. */
	for (int f = 0; f < num_feature_levels; f++) {

		/* Iterate through available adapters. */
		while (m_dxgi_factory->EnumAdapters1(f, &m_dxgi_adapter) != DXGI_ERROR_NOT_FOUND) { 

			hr = D3D11CreateDevice(m_dxgi_adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, 0, 
				create_device_flags, feature_levels, num_feature_levels, D3D11_SDK_VERSION, 
				&device, &m_feature_level, &context);

			/* If success break out of loop. */
			if(SUCCEEDED(hr))
				break;
		}

		if(SUCCEEDED(hr))
			break;
	}

This still doesn't work. Someone on these forums also suggested looking in the DirectX caps viewer and in the DXGI 1.1 > NVIDIA GeForce GTX 570 > Direct3D 11 folder it only lists D3D_FEATURE_LEVEL_10_1. It's like my gpu isn't being recognized as a DirectX 11 capable device.

 

Does anyone have any suggestions? Thanks.


My lowly triangle will not render :(

27 January 2013 - 08:55 PM

Hello, I'm having some trouble getting a simple triangle to render. I've done this before (yesterday actually with a cube), but I must have lost it or something. Looking in PIX it looks like the vertices all get set to zero after the vertex shader stage. I don't understand why, but I'm a noob so I don't understand this stuff. I was hoping somebody might take a look at the code and see if they can't help me out, I'd really appreciate it. Thanks.


How do I keep the screen from squishing and stretching?

06 November 2012 - 12:08 AM

I've programmed a simple little app that renders a triangle to the screen. Whenever I maximize the screen or drag the resize bars the triangle squishes and stretches along with the window. I wrote a function that uses IDXGISwapChain::ResizeBuffers() to resize the swap chain's buffers in response to a WM_SIZE message but it doesn't seem to fix the distortion. Am I misunderstanding the purpose of IDXGISwapChain::ResizeBuffers()?

Here's my OnResize() function. I'm either doing something wrong, or ResizeBuffers doesn't do what I though it did. Sorry if this is a dumb question Posted Image

[source lang="cpp"]HRESULT OnResize(LPARAM lParam){ g_pImmediateContext->OMSetRenderTargets(0, 0, 0); // Release any extraneous instances of swap chain's buffers. The render // target view typically holds references to swap chain's buffers. g_pRenderTargetView->Release(); UINT width = LOWORD(lParam); UINT height = HIWORD(lParam); // Resize swap chain's buffers. HRESULT hr = g_pSwapChain->ResizeBuffers(1, width, height, DXGI_FORMAT_R8G8B8A8_UNORM, 0); if(FAILED(hr)) { MessageBox(NULL, "[ERROR] Failed to resize buffers.\nOnResize() in rederer.cpp", "ERROR", MB_ICONERROR | MB_OK); return hr; } // Get buffer and create render target view. ID3D11Texture2D* pBackBuffer = nullptr; hr = g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer); if(FAILED(hr)) { MessageBox(NULL, "[ERROR] Failed to get back buffer.\nOnResize() in renderer.cpp", "ERROR", MB_ICONERROR | MB_OK); return hr; } hr = g_pD3DDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_pRenderTargetView); pBackBuffer->Release(); if(FAILED(hr)) { MessageBox(NULL, "[ERROR] Failed to create render target view." "\nOnResize() in renderer.cpp", "ERROR", MB_ICONERROR | MB_OK); return hr; } g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, NULL); // Set up viewport. D3D11_VIEWPORT vp; vp.Width = (float)width; vp.Height = (float)height; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0; vp.TopLeftY = 0; g_pImmediateContext->RSSetViewports(1, &vp); return S_OK;}[/source]


And here's the little snippet inside of WndProc() where I call it.

[source lang="cpp"]case WM_SIZE: if(g_pSwapChain) { OnResize(lParam); } return 0;[/source]


Thanks for the help.

Does anyone know how I can get rid of these annoying compiler warnings?

04 November 2012 - 04:40 PM

Does anyone know how I can get rid of these macro redefinition warnings in Visual Studio 2012 Express?
1>------ Build started: Project: Game Framework, Configuration: Debug Win32 ------
1> WinMain.cpp
1> RenderView.cpp
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(12): warning C4005: 'DXGI_STATUS_OCCLUDED' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49449) : see previous definition of 'DXGI_STATUS_OCCLUDED'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(13): warning C4005: 'DXGI_STATUS_CLIPPED' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49458) : see previous definition of 'DXGI_STATUS_CLIPPED'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(14): warning C4005: 'DXGI_STATUS_NO_REDIRECTION' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49467) : see previous definition of 'DXGI_STATUS_NO_REDIRECTION'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(15): warning C4005: 'DXGI_STATUS_NO_DESKTOP_ACCESS' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49476) : see previous definition of 'DXGI_STATUS_NO_DESKTOP_ACCESS'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(16): warning C4005: 'DXGI_STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49485) : see previous definition of 'DXGI_STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(17): warning C4005: 'DXGI_STATUS_MODE_CHANGED' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49494) : see previous definition of 'DXGI_STATUS_MODE_CHANGED'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(18): warning C4005: 'DXGI_STATUS_MODE_CHANGE_IN_PROGRESS' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49503) : see previous definition of 'DXGI_STATUS_MODE_CHANGE_IN_PROGRESS'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(21): warning C4005: 'DXGI_ERROR_INVALID_CALL' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49518) : see previous definition of 'DXGI_ERROR_INVALID_CALL'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(22): warning C4005: 'DXGI_ERROR_NOT_FOUND' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49527) : see previous definition of 'DXGI_ERROR_NOT_FOUND'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(23): warning C4005: 'DXGI_ERROR_MORE_DATA' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49536) : see previous definition of 'DXGI_ERROR_MORE_DATA'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(24): warning C4005: 'DXGI_ERROR_UNSUPPORTED' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49545) : see previous definition of 'DXGI_ERROR_UNSUPPORTED'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(25): warning C4005: 'DXGI_ERROR_DEVICE_REMOVED' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49554) : see previous definition of 'DXGI_ERROR_DEVICE_REMOVED'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(26): warning C4005: 'DXGI_ERROR_DEVICE_HUNG' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49563) : see previous definition of 'DXGI_ERROR_DEVICE_HUNG'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(27): warning C4005: 'DXGI_ERROR_DEVICE_RESET' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49573) : see previous definition of 'DXGI_ERROR_DEVICE_RESET'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(28): warning C4005: 'DXGI_ERROR_WAS_STILL_DRAWING' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49582) : see previous definition of 'DXGI_ERROR_WAS_STILL_DRAWING'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(29): warning C4005: 'DXGI_ERROR_FRAME_STATISTICS_DISJOINT' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49592) : see previous definition of 'DXGI_ERROR_FRAME_STATISTICS_DISJOINT'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(30): warning C4005: 'DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49601) : see previous definition of 'DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(31): warning C4005: 'DXGI_ERROR_DRIVER_INTERNAL_ERROR' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49611) : see previous definition of 'DXGI_ERROR_DRIVER_INTERNAL_ERROR'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(32): warning C4005: 'DXGI_ERROR_NONEXCLUSIVE' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49620) : see previous definition of 'DXGI_ERROR_NONEXCLUSIVE'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(33): warning C4005: 'DXGI_ERROR_NOT_CURRENTLY_AVAILABLE' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49629) : see previous definition of 'DXGI_ERROR_NOT_CURRENTLY_AVAILABLE'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(34): warning C4005: 'DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49639) : see previous definition of 'DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\dxgitype.h(35): warning C4005: 'DXGI_ERROR_REMOTE_OUTOFMEMORY' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49648) : see previous definition of 'DXGI_ERROR_REMOTE_OUTOFMEMORY'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\d3d11.h(917): warning C4005: 'D3D11_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49817) : see previous definition of 'D3D11_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\d3d11.h(918): warning C4005: 'D3D11_ERROR_FILE_NOT_FOUND' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49826) : see previous definition of 'D3D11_ERROR_FILE_NOT_FOUND'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\d3d11.h(919): warning C4005: 'D3D11_ERROR_TOO_MANY_UNIQUE_VIEW_OBJECTS' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49836) : see previous definition of 'D3D11_ERROR_TOO_MANY_UNIQUE_VIEW_OBJECTS'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\d3d11.h(920): warning C4005: 'D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49845) : see previous definition of 'D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\d3d10.h(608): warning C4005: 'D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49793) : see previous definition of 'D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS'
1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\d3d10.h(609): warning C4005: 'D3D10_ERROR_FILE_NOT_FOUND' : macro redefinition
1> c:\program files (x86)\windows kits\8.0\include\shared\winerror.h(49802) : see previous definition of 'D3D10_ERROR_FILE_NOT_FOUND'
1> GameApp.cpp
1> Exception.cpp
1> Generating Code...
1> Game Framework.vcxproj -> C:\Users\Cole\Documents\Dev\Game Framework\Debug\Game Framework.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Thanks Posted Image .

PARTNERS