WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
video.cpp
Go to the documentation of this file.
1#include "video.h"
2#include "Logger.h"
3
4#define WIP_DH_SUPPORT 1
5
6#ifdef _LINUX // Linux
7 void (*wglGetProcAddress(const char *function_name))(void)
8 {
9 return glXGetProcAddress((GLubyte*)function_name);
10 }
11#endif
12
13#ifdef _WINDOWS
14// Create an OpenGL pixel format descriptor
15PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
16{
17 sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
18 1, // Version Number
19 PFD_DRAW_TO_WINDOW | // Format Must Support Window
20 PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
21 PFD_DOUBLEBUFFER, // Must Support Double Buffering
22 PFD_TYPE_RGBA, // Request An RGBA Format
23 16, // Select Our Color Depth (same as desktop)
24 0, 0, 0, 0, 0, 0, // Color Bits Ignored
25 1, // Alpha Buffer
26 0, // Shift Bit Ignored
27 0, // No Accumulation Buffer
28 0, 0, 0, 0, // Accumulation Bits Ignored
29 16, // 16Bit Z-Buffer (Depth Buffer)
30 0, // No Stencil Buffer
31 0, // No Auxiliary Buffer
32 PFD_MAIN_PLANE, // Main Drawing Layer
33 0, // Reserved
34 0, 0, 0 // Layer Masks Ignored
35};
36#endif
37
39
41
43{
44#ifdef _WINDOWS
45 // Clear the rendering context
46 wglMakeCurrent(nullptr, nullptr);
47
48 if (hRC)
49 {
50 wglDeleteContext(hRC);
51 hRC = nullptr;
52 }
53
54 if (hDC)
55 {
56 ReleaseDC(hWnd, hDC);
57 hDC = nullptr;
58 }
59#endif
60}
61
63{
64 if (init)
65 return true;
66
67 int gladVersion = gladLoaderLoadGL();
68
69 if (!gladVersion)
70 {
71 LOG_ERROR << "glad failed to initialize OpenGL loader.";
72 return false;
73 }
74 else
75 {
76 LOG_INFO << "glad successfully initiated (OpenGL " << GLAD_VERSION_MAJOR(gladVersion) << "." << GLAD_VERSION_MINOR(gladVersion) << ").";
77 }
78
79#ifdef _WINDOWS
80 if (hDC)
81 gladLoaderLoadWGL(hDC);
82#endif
83
84 // Now get some specifics on the card
85 // First up, the details
86 if (GLAD_GL_EXT_texture_filter_anisotropic)
87 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*)&AnisofilterLevel);
88 else
90
91 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&numTextureUnits);
92 vendor = ((char*)glGetString(GL_VENDOR));
93 version = ((char*)glGetString(GL_VERSION));
94 renderer = ((char*)glGetString(GL_RENDERER));
95
96 const double num = atof((char*)glGetString(GL_VERSION));
97 supportOGL20 = (num >= 2.0);
98 if (supportOGL20)
99 supportNPOT = true;
100 else
101 supportNPOT = GLAD_GL_ARB_texture_non_power_of_two;
102
103 supportFragProg = GLAD_GL_ARB_fragment_program;
104 supportVertexProg = GLAD_GL_ARB_vertex_program;
105 supportGLSL = GLAD_GL_ARB_shading_language_100;
107 supportMultiTex = GLAD_GL_ARB_multitexture;
108 supportDrawRangeElements = GLAD_GL_EXT_draw_range_elements;
109#if WIP_DH_SUPPORT > 0
110 supportVBO = false;
111#else
112 supportVBO = GLAD_GL_ARB_vertex_buffer_object;
113#endif
114 supportCompression = GLAD_GL_ARB_texture_compression && GLAD_GL_ARB_texture_cube_map && GLAD_GL_EXT_texture_compression_s3tc;
115 supportPointSprites = GLAD_GL_ARB_point_sprite && GLAD_GL_ARB_point_parameters;
116#ifdef _WINDOWS
117 supportPBO = GLAD_WGL_ARB_pbuffer && GLAD_WGL_ARB_render_texture;
118 supportAntiAlias = GLAD_WGL_ARB_multisample;
119 supportWGLPixelFormat = GLAD_WGL_ARB_pixel_format;
120#endif
121 supportFBO = GLAD_GL_EXT_framebuffer_object;
122
123 // deactivate FBO for Intel cards, glReadPixels is known to be buggy for those cards...
124 if (strcmp(vendor, "Intel") == 0)
125 supportFBO = false;
126
127 supportTexRects = GLAD_GL_ARB_texture_rectangle;
128
129 // Now output and log the info
130 LOG_INFO << "Video Renderer:" << renderer;
131 LOG_INFO << "Video Vendor:" << vendor;
132 LOG_INFO << "Driver Version:" << version;
133
134
135 if (std::string(renderer) == std::string("GDI Generic"))
136 {
137 LOG_INFO << "Warning: Running in software mode, this is not enough. Please try updating your video drivers.";
138 // bloody oath - wtb a graphics card
139 hasHardware = false;
140 }
141 else
142 {
143 hasHardware = true;
144 }
145
146 LOG_INFO << "Support wglPixelFormat:" << (supportWGLPixelFormat ? "true" : "false");
147 LOG_INFO << "Support Texture Compression:" << (supportCompression ? "true" : "false");
148 LOG_INFO << "Support Draw Range Elements:" << (supportDrawRangeElements ? "true" : "false");
149 LOG_INFO << "Support Vertex Buffer Objects:" << (supportVBO ? "true" : "false");
150 LOG_INFO << "Support Point Sprites:" << (supportPointSprites ? "true" : "false");
151 LOG_INFO << "Support Pixel Shaders:" << (supportFragProg ? "true" : "false");
152 LOG_INFO << "Support Vertex Shaders:" << (supportVertexProg ? "true" : "false");
153 LOG_INFO << "Support GLSL:" << (supportGLSL ? "true" : "false");
154 LOG_INFO << "Support Anti-Aliasing:" << (supportAntiAlias ? "true" : "false");
155 LOG_INFO << "Support Pixel Buffer Objects:" << (supportPBO ? "true" : "false");
156 LOG_INFO << "Support Frame Buffer Objects:" << (supportFBO ? "true" : "false");
157 LOG_INFO << "Support Non-Power-of-Two:" << (supportNPOT ? "true" : "false");
158 LOG_INFO << "Support Rectangle Textures:" << (supportTexRects ? "true" : "false");
159 LOG_INFO << "Support OpenGL 2.0:" << (supportOGL20 ? "true" : "false");
160
161 // Max texture sizes
162 GLint texSize;
163 // Rectangle
164 if (GLAD_GL_ARB_texture_rectangle)
165 {
166 glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize);
167 LOG_INFO << "Max Rectangle Texture Size Supported:" << texSize;
168 }
169 // Square
170 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
171 LOG_INFO << "Max Texture Size Supported:" << texSize;
172
173 // Debug:
174 //supportPointSprites = false; // Always set to false, for now.
175 //supportVBO = false;
176 //supportFBO = false;
177 //supportNPOT = false;
178 //supportPBO = false;
179 //supportCompression = false;
180 //supportTexRects = false;
181
182 init = true;
183
184 return true;
185}
186
188{
189 if (!Init())
190 return;
191
192 GLenum err = glGetError();
193 if (err)
194 LOG_ERROR << __FUNCTION__ << __FILE__ << err << "An error occured on line" << __LINE__;
195
197 {
198 glEnableClientState(GL_VERTEX_ARRAY);
199 glEnableClientState(GL_NORMAL_ARRAY);
200 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
201 }
202 else
203 {
204 glDisableClientState(GL_VERTEX_ARRAY);
205 glDisableClientState(GL_NORMAL_ARRAY);
206 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
207 }
208
210 glEnable(GL_MULTISAMPLE_ARB);
211
212 // Colour and materials
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);
218
219 // For environmental mapped meshes
220 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 18.0f);
221
222
223 // TODO: Implement a scene graph, or scene manager to optimise OpenGL?
224 // Default texture settings.
225 glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);
226 /*
227 glTexEnvf(GL_TEXTURE_ENV,GL_RGB_SCALE, 1.000000);
228 glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB, GL_PREVIOUS);
229 glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB, GL_TEXTURE);
230 glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_RGB, GL_CONSTANT);
231 glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB, GL_MODULATE);
232 glTexEnvf(GL_TEXTURE_ENV,GL_ALPHA_SCALE, 1.000000);
233 glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA, GL_PREVIOUS);
234 glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_ALPHA, GL_TEXTURE);
235 glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_ALPHA, GL_CONSTANT);
236 glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_ALPHA, GL_REPLACE);
237 */
238
239 /*
240 // Alpha blending texture settings.
241 glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);
242 glTexEnvf(GL_TEXTURE_ENV,GL_RGB_SCALE, 1.000000);
243 glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB, GL_PREVIOUS);
244 glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB, GL_TEXTURE);
245 glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_RGB, GL_CONSTANT);
246 glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB, GL_MODULATE);
247 glTexEnvf(GL_TEXTURE_ENV,GL_ALPHA_SCALE, 1.000000);
248 glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA, GL_PREVIOUS);
249 glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_ALPHA, GL_TEXTURE);
250 glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_ALPHA, GL_CONSTANT);
251 glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_ALPHA, GL_MODULATE);
252 */
253
254 glAlphaFunc(GL_GEQUAL, 0.9f);
255 glDepthFunc(GL_LEQUAL);
256 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
257
258 glPixelStorei(GL_PACK_ALIGNMENT, 1);
259 glPixelStorei(GL_PACK_SWAP_BYTES, GL_FALSE);
260 glPixelStorei(GL_PACK_LSB_FIRST, GL_FALSE);
261
262 glShadeModel(GL_SMOOTH);
263 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
264
265 err = glGetError();
266 if (err)
267 LOG_ERROR << __FUNCTION__ << __FILE__ << err << "An error occured on line" << __LINE__;
268}
269
271{
272#ifdef _WINDOWS
273 if (!hasHardware)
274 return;
275
276 // Error check
277 if (!hDC)
278 {
279 LOG_ERROR << "Unable to enumerate display modes. Invalid HDC.";
280 return;
281 }
282
283 // This is where we do the grunt work of checking the caps
284 // find out how many pixel formats we have
285 std::vector<int> iAttributes;
286 iAttributes.reserve(12);
287 std::vector<int> results;
288
289 iAttributes.push_back(WGL_NUMBER_PIXEL_FORMATS_ARB);
290 results.resize(2); // 2 elements
291 wglGetPixelFormatAttribivARB(hDC, 0, 0, 1, &iAttributes[0], &results[0]);
292 // get the number of contexts we can create
293 const size_t num_pfd = results[0];
294 iAttributes.clear();
295 results.clear();
296
297 // error check
298 if (num_pfd == 0)
299 {
300 LOG_ERROR << "Could not find any display modes. Video Card might not support the function.";
301 hasHardware = false;
302 return;
303 }
304
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);
315
316 if (GLAD_GL_ARB_multisample)
317 {
318 iAttributes.push_back(WGL_SAMPLE_BUFFERS_ARB);
319 iAttributes.push_back(WGL_SAMPLES_ARB);
320 }
321
322 results.resize(iAttributes.size());
323
324 // Reset our list of card capabilities.
325 capsList.clear();
326
327 for (size_t i = 0; i < num_pfd; i++)
328 {
329 if (!wglGetPixelFormatAttribivARB(hDC, static_cast<int>(i) + 1, 0, (UINT)iAttributes.size(), &iAttributes[0], &results[0]))
330 return;
331
332 // once we make it here we can look at the pixel data to make sure this is a context we want to use
333 // results[0] is WGL_DRAW_TO_WINDOW, since we only work in windowed mode, no need to return results for fullscreen mode
334 // results[4] is WGL_SUPPORT_OPENGL, obvious if the mode doesn't support opengl then its useless to us.
335 // results[3] is bitdepth, if it has a 0 bitdepth then its useless to us
336 if (results[0] == GL_TRUE && results[4] == GL_TRUE && results[3] > 0)
337 {
338 // what we have here is a contect which is drawable to a window, is in rgba format and is accelerated in some way
339 // so now we pull the infomation, fill a structure and shove it into our map
340 VideoCaps caps{};
341
342 if (GLAD_GL_ARB_multisample)
343 {
344 caps.sampleBuffer = results[10];
345 caps.aaSamples = results[11];
346 }
347 else
348 {
349 caps.sampleBuffer = false;
350 caps.aaSamples = 0;
351 }
352
353 caps.accum = results[9];
354 caps.alpha = results[8];
355 caps.colour = results[7];
356 //caps.pixelType = results[6]; /* WGL_TYPE_RGBA_ARB*/
357 caps.doubleBuffer = results[5];
358 caps.zBuffer = results[3];
359 caps.hwAcc = results[2];
360 /*WGL_FULL_ACCELERATION_ARB / WGL_GENERIC_ACCELERATION_ARB / WGL_NO_ACCELERATION_ARB;*/
361 caps.stencil = results[1];
362 capsList.push_back(caps); // insert into the map
363 }
364 }
365#endif
366}
367
368// This function basically just uses any available display mode
370{
371#ifdef _WINDOWS
372 render = false;
373
374 if (!hWnd)
375 return false;
376
377 // Clear the rendering context
378 wglMakeCurrent(nullptr, nullptr);
379
380 if (hRC)
381 {
382 wglDeleteContext(hRC);
383 hRC = nullptr;
384 }
385
386 if (hDC)
387 {
388 ReleaseDC(hWnd, hDC);
389 hDC = nullptr;
390 }
391
392 hDC = GetDC(hWnd); // Grab A Device Context For This Window
393 if (hDC == nullptr)
394 {
395 // Did We Get A Device Context?
396 // Failed
397 //throw std::runtime_error("Failed To Get Device Context");
398 LOG_ERROR << "Failed To Get Device Context.";
399 return false;
400 }
401
402 pixelFormat = ChoosePixelFormat(hDC, &pfd); // Find A Compatible Pixel Format
403 if (pixelFormat == 0)
404 {
405 // Did We Find A Compatible Format?
406 // Failed
407 //throw std::runtime_error("Failed To Acuire PixelFormat");
408 LOG_ERROR << "Failed To Accquire PixelFormat.";
409 return false;
410 }
411
412 if (SetPixelFormat(hDC, pixelFormat, &pfd) == false)
413 {
414 // Try To Set The Pixel Format
415 // Failed
416 //throw std::runtime_error("Failed To SetPixelFormat");
417 LOG_ERROR << "Failed To SetPixelFormat.";
418 return false;
419 }
420
421 hRC = wglCreateContext(hDC); // Try To Get A Rendering Context
422 if (hRC == nullptr)
423 {
424 // Did We Get A Rendering Context?
425 // Failed
426 //throw std::runtime_error("Failed To Get OpenGL Context");
427 LOG_ERROR << "Failed To Get OpenGL Context.";
428 return false;
429 }
430
431 SetCurrent();
432 render = true;
433#endif
434 return true;
435}
436
438{
439#ifdef _WINDOWS
440 if (!hasHardware)
441 return false;
442
443 // Ask the WGL for the clostest match to this pixel format
444 if (!hDC)
445 {
446 LOG_ERROR << "Attempted to Get a Compatible Window Mode Without a Valid Window";
447 //throw std::runtime_error("VideoSettings::GetCompatibleWinMode() : Attempted to Get a Compatible Window Mode Without a Valid Window");
448 return false;
449 }
450
451 std::vector<int> iAttributes;
452 iAttributes.reserve(22);
453 std::vector<int> results;
454 unsigned int numformats;
455 const float fAtrributes[] = {0, 0};
456
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); // min color required
463 iAttributes.push_back(WGL_ALPHA_BITS_ARB);
464 iAttributes.push_back(caps.alpha); // min alpha bits
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);
469 if (caps.aaSamples != 0)
470 {
471 iAttributes.push_back(WGL_SAMPLE_BUFFERS_ARB);
472 iAttributes.push_back(caps.sampleBuffer);
473 iAttributes.push_back(WGL_SAMPLES_ARB);
474 iAttributes.push_back(caps.aaSamples);
475 }
476 iAttributes.push_back(WGL_DOUBLE_BUFFER_ARB);
477 iAttributes.push_back(caps.doubleBuffer);
478 if (caps.accum != 0)
479 {
480 iAttributes.push_back(WGL_ACCUM_BITS_ARB);
481 iAttributes.push_back(caps.accum);
482 }
483 iAttributes.push_back(0);
484 iAttributes.push_back(0);
485
486 const int status = wglChoosePixelFormatARB(hDC, &iAttributes[0], fAtrributes, 1, &pixelFormat, &numformats);
487 // find a matching format
488 if (status == GL_TRUE && numformats)
489 {
490 // we have a matching format, extract the details
491 iAttributes.clear();
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());
502
503 if (!wglGetPixelFormatAttribivARB(hDC, pixelFormat, PFD_MAIN_PLANE, (UINT)iAttributes.size(), &iAttributes[0],
504 &results[0]))
505 {
506 //int i = GetLastError();
507 return false;
508 }
509
510 curCap.aaSamples = results[5];
511 curCap.accum = results[7];
512 curCap.alpha = results[1];
513 curCap.colour = results[0];
514 curCap.doubleBuffer = results[6];
515 curCap.sampleBuffer = results[4];
516 curCap.stencil = results[3];
517 curCap.zBuffer = results[2];
518 curCap.hwAcc = results[8];
519
520 for (size_t i = 0; i < capsList.size(); i++)
521 {
522 if (capsList[i].colour == curCap.colour &&
523 capsList[i].zBuffer == curCap.zBuffer &&
524 capsList[i].alpha == curCap.alpha &&
525 capsList[i].hwAcc == curCap.hwAcc &&
526 capsList[i].doubleBuffer == curCap.doubleBuffer &&
527 capsList[i].sampleBuffer == curCap.sampleBuffer &&
528 capsList[i].aaSamples == curCap.aaSamples)
529 {
530 capIndex = static_cast<int>(i);
531 break;
532 }
533 }
534
535 return true;
536 }
537#endif
538 return false;
539}
540
541#ifdef _WINDOWS
542void VideoSettings::SetHandle(HWND hwnd, int bpp = 16)
543{
544 hWnd = hwnd;
545 desktopBPP = bpp;
546
547 //pfd.cColorBits = desktopBPP;
548
549 if (!secondPass)
551
552 if (!init && !secondPass)
553 {
554 Init();
556 {
559 }
560 }
561
563 SetMode();
564}
565#endif
566
568{
569#ifdef _WINDOWS
570 // Clear the rendering context
571 wglMakeCurrent(nullptr, nullptr);
572
573 if (hRC)
574 {
575 wglDeleteContext(hRC);
576 hRC = nullptr;
577 }
578
579 if (hDC)
580 {
581 ReleaseDC(hWnd, hDC);
582 hDC = nullptr;
583 }
584#endif
585}
586
588{
589#ifdef _WINDOWS
590 if (!hWnd)
591 return;
592
593 // Clear the rendering context
594 wglMakeCurrent(nullptr, nullptr);
595
596 if (hRC)
597 {
598 wglDeleteContext(hRC);
599 hRC = nullptr;
600 }
601
602 if (hDC)
603 {
604 ReleaseDC(hWnd, hDC);
605 hDC = nullptr;
606 }
607
608 hDC = GetDC(hWnd);
609 if (!hDC)
610 {
611 // Did We Get A Device Context?
612 LOG_ERROR << "Can't Create A GL Device Context.";
613 return;
614 }
615
616 unsigned int numFormats;
617 const float fAttributes[] = {0, 0};
618 std::vector<int> AttributeList;
619 AttributeList.reserve(22);
620
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);
626 AttributeList.push_back(curCap.hwAcc);
627 AttributeList.push_back(WGL_COLOR_BITS_ARB);
628 AttributeList.push_back(curCap.colour);
629 AttributeList.push_back(WGL_ALPHA_BITS_ARB);
630 AttributeList.push_back(curCap.alpha);
631 AttributeList.push_back(WGL_DEPTH_BITS_ARB);
632 AttributeList.push_back(curCap.zBuffer);
633 //AttributeList.push_back(WGL_STENCIL_BITS_ARB);
634 //AttributeList.push_back(curCap.stencil);
635 AttributeList.push_back(WGL_DOUBLE_BUFFER_ARB);
636 AttributeList.push_back(curCap.doubleBuffer);
637
638 // 8229 being software mode
639 if (curCap.hwAcc != 8229 && curCap.accum != 0)
640 {
641 AttributeList.push_back(WGL_ACCUM_BITS_ARB);
642 AttributeList.push_back(curCap.accum);
643 }
644
646 {
647 AttributeList.push_back(WGL_SAMPLE_BUFFERS_ARB);
648 AttributeList.push_back(GL_TRUE);
649 AttributeList.push_back(WGL_SAMPLES_ARB);
650 AttributeList.push_back(curCap.aaSamples);
651 }
652 AttributeList.push_back(0);
653 AttributeList.push_back(0);
654
655
656 const GLboolean status = wglChoosePixelFormatARB(hDC, &AttributeList[0], fAttributes, 1, &pixelFormat, &numFormats);
657 if (status == GL_TRUE && numFormats)
658 {
659 if (SetPixelFormat(hDC, pixelFormat, &pfd) == FALSE)
660 {
661 //LOG_ERROR << "Failed To Set Requested Pixel Format.";
662 secondPass = true;
663 return;
664 }
665
666 hRC = wglCreateContext(hDC);
667 if (!hRC)
668 {
669 LOG_ERROR << "Error: Failed To Create OpenGL Context.";
670 secondPass = true;
671 render = false;
672 return;
673 }
674
675 render = true;
676 SetCurrent();
677 }
678 else
679 {
680 // Error
681 // Something went wrong, fall back to the basic opengl setup
683 }
684#endif
685}
686
687void VideoSettings::ResizeGLScene(int width, int height) // Resize And Initialize The GL Window
688{
689 if (height == 0) // Prevent A Divide By Zero By
690 height = 1; // Making Height Equal One
691
692 glViewport(0, 0, width, height); // Reset The Current Viewport
693 //glDepthRange(0.0f,1.0f);
694
695 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
696 glLoadIdentity(); // Reset The Projection Matrix
697
698 // Calculate The Aspect Ratio Of The Window
699 gluPerspective(fov, static_cast<float>(width) / static_cast<float>(height), 0.1f, 1280 * 5);
700
701 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
702 glLoadIdentity(); // Reset The Modelview Matrix
703}
704
706{
707#ifdef _WINDOWS
708 if (hDC)
709 ::SwapBuffers(hDC);
710#endif
711}
712
714{
715#ifdef _WINDOWS
716 if (!hDC || !hRC || !wglMakeCurrent(hDC, hRC))
717 {
718 // Try To Activate The Rendering Context
719 render = false;
720 }
721 else
722 {
723 render = true;
724 }
725#endif
726}
#define LOG_ERROR
Definition Logger.h:11
#define LOG_INFO
Definition Logger.h:10
Legacy OpenGL video-settings manager.
Definition video.h:33
bool supportShaders
Definition video.h:97
bool supportVBO
Definition video.h:99
void InitGL()
Definition video.cpp:187
int pixelFormat
Definition video.h:68
int desktopBPP
Definition video.h:70
float fov
Definition video.h:69
bool supportCompression
Definition video.h:93
bool GetAvailableMode()
Definition video.cpp:369
std::vector< VideoCaps > capsList
Definition video.h:73
int AnisofilterLevel
Definition video.h:77
bool supportWGLPixelFormat
Definition video.h:104
bool supportAntiAlias
Definition video.h:98
bool supportDrawRangeElements
Definition video.h:95
bool supportGLSL
Definition video.h:92
bool init
Definition video.h:61
int numTextureUnits
Definition video.h:78
void SetCurrent()
Definition video.cpp:713
void EnumDisplayModes()
Definition video.cpp:270
bool supportFBO
Definition video.h:101
void SwapBuffers()
Definition video.cpp:705
bool supportTexRects
Definition video.h:105
VideoCaps curCap
Definition video.h:74
char * renderer
Definition video.h:83
void Release()
Definition video.cpp:567
void ResizeGLScene(int width, int height)
Definition video.cpp:687
char * version
Definition video.h:82
bool supportPBO
Definition video.h:100
char * vendor
Definition video.h:81
int capIndex
Definition video.h:75
bool supportFragProg
Definition video.h:90
bool supportVertexProg
Definition video.h:91
bool render
Definition video.h:62
void SetMode()
Definition video.cpp:587
bool supportNPOT
Definition video.h:102
bool supportOGL20
Definition video.h:103
bool GetCompatibleWinMode(VideoCaps caps)
Definition video.cpp:437
bool hasHardware
Definition video.h:86
bool supportPointSprites
Definition video.h:96
bool supportMultiTex
Definition video.h:94
bool secondPass
Definition video.h:87
bool Init()
Definition video.cpp:62
Describes a single video mode's capabilities (colour depth, AA, etc.).
Definition video.h:15
int zBuffer
Depth buffer bit depth.
Definition video.h:18
int stencil
Stencil buffer bit depth.
Definition video.h:20
int hwAcc
Hardware acceleration mode.
Definition video.h:22
int alpha
Alpha buffer bit depth.
Definition video.h:17
GLboolean doubleBuffer
True if double-buffered.
Definition video.h:24
GLboolean sampleBuffer
True if an AA sample buffer is available.
Definition video.h:23
int colour
Colour buffer bit depth.
Definition video.h:16
int accum
Accumulation buffer bit depth.
Definition video.h:19
int aaSamples
Number of anti-aliasing samples.
Definition video.h:21
VideoSettings video
Definition video.cpp:38