Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <d3d11.h>
- #include <assert.h>
- #pragma comment(lib, "Opengl32.lib")
- int main(int argc, char **argv)
- {
- auto d3D11Module = LoadLibraryA("d3d11.dll");
- auto createDeviceFunc = reinterpret_cast<PFN_D3D11_CREATE_DEVICE>(GetProcAddress(d3D11Module, "D3D11CreateDevice"));
- ID3D11Device *d3D11Device;
- HRESULT result = createDeviceFunc(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION, &d3D11Device, nullptr, nullptr);
- assert(SUCCEEDED(result));
- WNDCLASSA classDesc = { 0 };
- classDesc.style = CS_OWNDC;
- classDesc.lpfnWndProc = DefWindowProc;
- classDesc.cbClsExtra = 0;
- classDesc.cbWndExtra = 0;
- classDesc.hInstance = GetModuleHandle(nullptr);
- classDesc.hIcon = nullptr;
- classDesc.hCursor = nullptr;
- classDesc.hbrBackground = 0;
- classDesc.lpszMenuName = nullptr;
- classDesc.lpszClassName = "dummy";
- auto windowClass = RegisterClassA(&classDesc);
- assert(windowClass);
- 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);
- assert(window);
- HDC dc = GetDC(window);
- assert(dc);
- PIXELFORMATDESCRIPTOR pfd = { 0 };
- pfd.nSize = sizeof(pfd);
- pfd.nVersion = 1;
- pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_GENERIC_ACCELERATED | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
- pfd.iPixelType = PFD_TYPE_RGBA;
- pfd.cColorBits = 24;
- pfd.cAlphaBits = 8;
- pfd.cDepthBits = 24;
- pfd.cStencilBits = 8;
- pfd.iLayerType = PFD_MAIN_PLANE;
- int pixelFormat = ChoosePixelFormat(dc, &pfd);
- assert(pixelFormat != 0);
- BOOL setPixelFormatResult = SetPixelFormat(dc, pixelFormat, &pfd);
- assert(setPixelFormatResult);
- HGLRC wglContext = wglCreateContext(dc);
- assert(wglContext);
- BOOL makeCurrentResult = wglMakeCurrent(dc, wglContext);
- assert(makeCurrentResult);
- typedef HANDLE(WINAPI * PFNWGLDXOPENDEVICENVPROC) (void *dxDevice);
- auto wglDXOpenDeviceNV = reinterpret_cast<PFNWGLDXOPENDEVICENVPROC>(wglGetProcAddress("wglDXOpenDeviceNV"));
- HANDLE d3dDeviceHandle = wglDXOpenDeviceNV(d3D11Device);
- assert(d3dDeviceHandle);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement