67 int gladVersion = gladLoaderLoadGL();
71 LOG_ERROR <<
"glad failed to initialize OpenGL loader.";
76 LOG_INFO <<
"glad successfully initiated (OpenGL " << GLAD_VERSION_MAJOR(gladVersion) <<
"." << GLAD_VERSION_MINOR(gladVersion) <<
").";
81 gladLoaderLoadWGL(hDC);
86 if (GLAD_GL_EXT_texture_filter_anisotropic)
92 vendor = ((
char*)glGetString(GL_VENDOR));
93 version = ((
char*)glGetString(GL_VERSION));
94 renderer = ((
char*)glGetString(GL_RENDERER));
96 const double num = atof((
char*)glGetString(GL_VERSION));
101 supportNPOT = GLAD_GL_ARB_texture_non_power_of_two;
109#if WIP_DH_SUPPORT > 0
112 supportVBO = GLAD_GL_ARB_vertex_buffer_object;
114 supportCompression = GLAD_GL_ARB_texture_compression && GLAD_GL_ARB_texture_cube_map && GLAD_GL_EXT_texture_compression_s3tc;
117 supportPBO = GLAD_WGL_ARB_pbuffer && GLAD_WGL_ARB_render_texture;
124 if (strcmp(
vendor,
"Intel") == 0)
135 if (std::string(
renderer) == std::string(
"GDI Generic"))
137 LOG_INFO <<
"Warning: Running in software mode, this is not enough. Please try updating your video drivers.";
164 if (GLAD_GL_ARB_texture_rectangle)
166 glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize);
167 LOG_INFO <<
"Max Rectangle Texture Size Supported:" << texSize;
170 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
171 LOG_INFO <<
"Max Texture Size Supported:" << texSize;
192 GLenum err = glGetError();
194 LOG_ERROR << __FUNCTION__ << __FILE__ << err <<
"An error occured on line" << __LINE__;
198 glEnableClientState(GL_VERTEX_ARRAY);
199 glEnableClientState(GL_NORMAL_ARRAY);
200 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
204 glDisableClientState(GL_VERTEX_ARRAY);
205 glDisableClientState(GL_NORMAL_ARRAY);
206 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
210 glEnable(GL_MULTISAMPLE_ARB);
213 glEnable(GL_COLOR_MATERIAL);
214 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
215 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
216 glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION);
217 glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
220 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 18.0f);
225 glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);
254 glAlphaFunc(GL_GEQUAL, 0.9f);
255 glDepthFunc(GL_LEQUAL);
256 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
258 glPixelStorei(GL_PACK_ALIGNMENT, 1);
259 glPixelStorei(GL_PACK_SWAP_BYTES, GL_FALSE);
260 glPixelStorei(GL_PACK_LSB_FIRST, GL_FALSE);
262 glShadeModel(GL_SMOOTH);
263 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
267 LOG_ERROR << __FUNCTION__ << __FILE__ << err <<
"An error occured on line" << __LINE__;
279 LOG_ERROR <<
"Unable to enumerate display modes. Invalid HDC.";
285 std::vector<int> iAttributes;
286 iAttributes.reserve(12);
287 std::vector<int> results;
289 iAttributes.push_back(WGL_NUMBER_PIXEL_FORMATS_ARB);
291 wglGetPixelFormatAttribivARB(hDC, 0, 0, 1, &iAttributes[0], &results[0]);
293 const size_t num_pfd = results[0];
300 LOG_ERROR <<
"Could not find any display modes. Video Card might not support the function.";
305 iAttributes.push_back(WGL_DRAW_TO_WINDOW_ARB);
306 iAttributes.push_back(WGL_STENCIL_BITS_ARB);
307 iAttributes.push_back(WGL_ACCELERATION_ARB);
308 iAttributes.push_back(WGL_DEPTH_BITS_ARB);
309 iAttributes.push_back(WGL_SUPPORT_OPENGL_ARB);
310 iAttributes.push_back(WGL_DOUBLE_BUFFER_ARB);
311 iAttributes.push_back(WGL_PIXEL_TYPE_ARB);
312 iAttributes.push_back(WGL_COLOR_BITS_ARB);
313 iAttributes.push_back(WGL_ALPHA_BITS_ARB);
314 iAttributes.push_back(WGL_ACCUM_BITS_ARB);
316 if (GLAD_GL_ARB_multisample)
318 iAttributes.push_back(WGL_SAMPLE_BUFFERS_ARB);
319 iAttributes.push_back(WGL_SAMPLES_ARB);
322 results.resize(iAttributes.size());
327 for (
size_t i = 0; i < num_pfd; i++)
329 if (!wglGetPixelFormatAttribivARB(hDC,
static_cast<int>(i) + 1, 0, (UINT)iAttributes.size(), &iAttributes[0], &results[0]))
336 if (results[0] == GL_TRUE && results[4] == GL_TRUE && results[3] > 0)
342 if (GLAD_GL_ARB_multisample)
345 caps.aaSamples = results[11];
349 caps.sampleBuffer =
false;
353 caps.accum = results[9];
354 caps.alpha = results[8];
355 caps.colour = results[7];
357 caps.doubleBuffer = results[5];
358 caps.zBuffer = results[3];
359 caps.hwAcc = results[2];
361 caps.stencil = results[1];
446 LOG_ERROR <<
"Attempted to Get a Compatible Window Mode Without a Valid Window";
451 std::vector<int> iAttributes;
452 iAttributes.reserve(22);
453 std::vector<int> results;
454 unsigned int numformats;
455 const float fAtrributes[] = {0, 0};
457 iAttributes.push_back(WGL_DRAW_TO_WINDOW_ARB);
458 iAttributes.push_back(GL_TRUE);
459 iAttributes.push_back(WGL_ACCELERATION_ARB);
460 iAttributes.push_back(caps.
hwAcc);
461 iAttributes.push_back(WGL_COLOR_BITS_ARB);
462 iAttributes.push_back(caps.
colour);
463 iAttributes.push_back(WGL_ALPHA_BITS_ARB);
464 iAttributes.push_back(caps.
alpha);
465 iAttributes.push_back(WGL_DEPTH_BITS_ARB);
466 iAttributes.push_back(caps.
zBuffer);
467 iAttributes.push_back(WGL_STENCIL_BITS_ARB);
468 iAttributes.push_back(caps.
stencil);
471 iAttributes.push_back(WGL_SAMPLE_BUFFERS_ARB);
473 iAttributes.push_back(WGL_SAMPLES_ARB);
476 iAttributes.push_back(WGL_DOUBLE_BUFFER_ARB);
480 iAttributes.push_back(WGL_ACCUM_BITS_ARB);
481 iAttributes.push_back(caps.
accum);
483 iAttributes.push_back(0);
484 iAttributes.push_back(0);
486 const int status = wglChoosePixelFormatARB(hDC, &iAttributes[0], fAtrributes, 1, &
pixelFormat, &numformats);
488 if (status == GL_TRUE && numformats)
492 iAttributes.push_back(WGL_COLOR_BITS_ARB);
493 iAttributes.push_back(WGL_ALPHA_BITS_ARB);
494 iAttributes.push_back(WGL_DEPTH_BITS_ARB);
495 iAttributes.push_back(WGL_STENCIL_BITS_ARB);
496 iAttributes.push_back(WGL_SAMPLE_BUFFERS_ARB);
497 iAttributes.push_back(WGL_SAMPLES_ARB);
498 iAttributes.push_back(WGL_DOUBLE_BUFFER_ARB);
499 iAttributes.push_back(WGL_ACCUM_BITS_ARB);
500 iAttributes.push_back(WGL_ACCELERATION_ARB);
501 results.resize(iAttributes.size());
503 if (!wglGetPixelFormatAttribivARB(hDC,
pixelFormat, PFD_MAIN_PLANE, (UINT)iAttributes.size(), &iAttributes[0],
520 for (
size_t i = 0; i <
capsList.size(); i++)
594 wglMakeCurrent(
nullptr,
nullptr);
598 wglDeleteContext(hRC);
604 ReleaseDC(hWnd, hDC);
612 LOG_ERROR <<
"Can't Create A GL Device Context.";
616 unsigned int numFormats;
617 const float fAttributes[] = {0, 0};
618 std::vector<int> AttributeList;
619 AttributeList.reserve(22);
621 AttributeList.push_back(WGL_DRAW_TO_WINDOW_ARB);
622 AttributeList.push_back(GL_TRUE);
623 AttributeList.push_back(WGL_SUPPORT_OPENGL_ARB);
624 AttributeList.push_back(GL_TRUE);
625 AttributeList.push_back(WGL_ACCELERATION_ARB);
627 AttributeList.push_back(WGL_COLOR_BITS_ARB);
629 AttributeList.push_back(WGL_ALPHA_BITS_ARB);
631 AttributeList.push_back(WGL_DEPTH_BITS_ARB);
635 AttributeList.push_back(WGL_DOUBLE_BUFFER_ARB);
641 AttributeList.push_back(WGL_ACCUM_BITS_ARB);
647 AttributeList.push_back(WGL_SAMPLE_BUFFERS_ARB);
648 AttributeList.push_back(GL_TRUE);
649 AttributeList.push_back(WGL_SAMPLES_ARB);
652 AttributeList.push_back(0);
653 AttributeList.push_back(0);
656 const GLboolean status = wglChoosePixelFormatARB(hDC, &AttributeList[0], fAttributes, 1, &
pixelFormat, &numFormats);
657 if (status == GL_TRUE && numFormats)
659 if (SetPixelFormat(hDC,
pixelFormat, &pfd) == FALSE)
666 hRC = wglCreateContext(hDC);
669 LOG_ERROR <<
"Error: Failed To Create OpenGL Context.";
692 glViewport(0, 0, width, height);
695 glMatrixMode(GL_PROJECTION);
699 gluPerspective(
fov,
static_cast<float>(width) /
static_cast<float>(height), 0.1f, 1280 * 5);
701 glMatrixMode(GL_MODELVIEW);