MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / CreateDevice

Method CreateDevice

olcPixelGameEngine.h:5340–5410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5338 }
5339
5340 olc::rcode CreateDevice(std::vector<void*> params, bool bFullScreen, bool bVSYNC) override
5341 {
5342#if defined(OLC_PLATFORM_WINAPI)
5343 // Create Device Context
5344 glDeviceContext = GetDC((HWND)(params[0]));
5345 PIXELFORMATDESCRIPTOR pfd =
5346 {
5347 sizeof(PIXELFORMATDESCRIPTOR), 1,
5348 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
5349 PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5350 PFD_MAIN_PLANE, 0, 0, 0, 0
5351 };
5352
5353 int pf = 0;
5354 if (!(pf = ChoosePixelFormat(glDeviceContext, &pfd))) return olc::FAIL;
5355 SetPixelFormat(glDeviceContext, pf, &pfd);
5356
5357 if (!(glRenderContext = wglCreateContext(glDeviceContext))) return olc::FAIL;
5358 wglMakeCurrent(glDeviceContext, glRenderContext);
5359
5360 // Remove Frame cap
5361 wglSwapInterval = (wglSwapInterval_t*)wglGetProcAddress("wglSwapIntervalEXT");
5362 if (wglSwapInterval && !bVSYNC) wglSwapInterval(0);
5363 bSync = bVSYNC;
5364#endif
5365
5366#if defined(OLC_PLATFORM_X11)
5367 using namespace X11;
5368 // Linux has tighter coupling between OpenGL and X11, so we store
5369 // various "platform" handles in the renderer
5370 olc_Display = (X11::Display*)(params[0]);
5371 olc_Window = (X11::Window*)(params[1]);
5372 olc_VisualInfo = (X11::XVisualInfo*)(params[2]);
5373
5374 glDeviceContext = glXCreateContext(olc_Display, olc_VisualInfo, nullptr, GL_TRUE);
5375 glXMakeCurrent(olc_Display, *olc_Window, glDeviceContext);
5376
5377 XWindowAttributes gwa;
5378 XGetWindowAttributes(olc_Display, *olc_Window, &gwa);
5379 glViewport(0, 0, gwa.width, gwa.height);
5380
5381 glSwapIntervalEXT = nullptr;
5382 glSwapIntervalEXT = (glSwapInterval_t*)glXGetProcAddress((unsigned char*)"glXSwapIntervalEXT");
5383
5384 if (glSwapIntervalEXT == nullptr && !bVSYNC)
5385 {
5386 printf("NOTE: Could not disable VSYNC, glXSwapIntervalEXT() was not found!\n");
5387 printf(" Don't worry though, things will still work, it's just the\n");
5388 printf(" frame rate will be capped to your monitors refresh rate - javidx9\n");
5389 }
5390
5391 if (glSwapIntervalEXT != nullptr && !bVSYNC)
5392 glSwapIntervalEXT(olc_Display, *olc_Window, 0);
5393#endif
5394
5395#if defined(OLC_PLATFORM_GLUT)
5396 mFullScreen = bFullScreen;
5397 if (!bVSYNC)

Callers 4

CreateGraphicsMethod · 0.45
CreateGraphicsMethod · 0.45
CreateGraphicsMethod · 0.45
CreateGraphicsMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected