Advertisement
Guest User

Untitled

a guest
May 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #include <windows.h>
  2. #include <d3d11.h>
  3.  
  4. #include <assert.h>
  5.  
  6. #pragma comment(lib, "Opengl32.lib")
  7.  
  8. int main(int argc, char **argv)
  9. {
  10. auto d3D11Module = LoadLibraryA("d3d11.dll");
  11. auto createDeviceFunc = reinterpret_cast<PFN_D3D11_CREATE_DEVICE>(GetProcAddress(d3D11Module, "D3D11CreateDevice"));
  12.  
  13. ID3D11Device *d3D11Device;
  14. HRESULT result = createDeviceFunc(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION, &d3D11Device, nullptr, nullptr);
  15. assert(SUCCEEDED(result));
  16.  
  17. WNDCLASSA classDesc = { 0 };
  18. classDesc.style = CS_OWNDC;
  19. classDesc.lpfnWndProc = DefWindowProc;
  20. classDesc.cbClsExtra = 0;
  21. classDesc.cbWndExtra = 0;
  22. classDesc.hInstance = GetModuleHandle(nullptr);
  23. classDesc.hIcon = nullptr;
  24. classDesc.hCursor = nullptr;
  25. classDesc.hbrBackground = 0;
  26. classDesc.lpszMenuName = nullptr;
  27. classDesc.lpszClassName = "dummy";
  28. auto windowClass = RegisterClassA(&classDesc);
  29. assert(windowClass);
  30.  
  31. HWND window = CreateWindowExA(0, reinterpret_cast<const char *>(windowClass), "Dummy Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr, nullptr, nullptr);
  32. assert(window);
  33.  
  34. HDC dc = GetDC(window);
  35. assert(dc);
  36.  
  37. PIXELFORMATDESCRIPTOR pfd = { 0 };
  38. pfd.nSize = sizeof(pfd);
  39. pfd.nVersion = 1;
  40. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_GENERIC_ACCELERATED | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  41. pfd.iPixelType = PFD_TYPE_RGBA;
  42. pfd.cColorBits = 24;
  43. pfd.cAlphaBits = 8;
  44. pfd.cDepthBits = 24;
  45. pfd.cStencilBits = 8;
  46. pfd.iLayerType = PFD_MAIN_PLANE;
  47. int pixelFormat = ChoosePixelFormat(dc, &pfd);
  48. assert(pixelFormat != 0);
  49.  
  50. BOOL setPixelFormatResult = SetPixelFormat(dc, pixelFormat, &pfd);
  51. assert(setPixelFormatResult);
  52.  
  53. HGLRC wglContext = wglCreateContext(dc);
  54. assert(wglContext);
  55.  
  56. BOOL makeCurrentResult = wglMakeCurrent(dc, wglContext);
  57. assert(makeCurrentResult);
  58.  
  59. typedef HANDLE(WINAPI * PFNWGLDXOPENDEVICENVPROC) (void *dxDevice);
  60. auto wglDXOpenDeviceNV = reinterpret_cast<PFNWGLDXOPENDEVICENVPROC>(wglGetProcAddress("wglDXOpenDeviceNV"));
  61.  
  62. HANDLE d3dDeviceHandle = wglDXOpenDeviceNV(d3D11Device);
  63. assert(d3dDeviceHandle);
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement