Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // OpenGL context initialization ------------------------------------------------------
- bool Device::Initialize(HWND hwnd, int screenWidth, int screenHeight, float screenDepth, float screenNear, bool vsync)
- {
- int attributeListInt[19];
- int pixelFormat;
- unsigned int formatCount;
- int result;
- PIXELFORMATDESCRIPTOR pixelFormatDescriptor;
- int attributeList[5];
- float fieldOfView, screenAspect;
- char *vendorString, *rendererString;
- // Get the device context for this window
- mDeviceContext = GetDC(hwnd);
- if(!mDeviceContext) {return false;}
- pixelFormatDescriptor = {
- sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
- 1, // version number
- PFD_DRAW_TO_WINDOW | // support window
- PFD_SUPPORT_OPENGL | // support OpenGL
- PFD_DOUBLEBUFFER, // double buffered
- PFD_TYPE_RGBA, // RGBA type
- 24, // 24-bit color depth
- 0, 0, 0, 0, 0, 0, // color bits ignored
- 0, // no alpha buffer
- 0, // shift bit ignored
- 0, // no accumulation buffer
- 0, 0, 0, 0, // accum bits ignored
- 32, // 32-bit z-buffer
- 0, // no stencil buffer
- 0, // no auxiliary buffer
- PFD_MAIN_PLANE, // main layer
- 0, // reserved
- 0, 0, 0 // layer masks ignored
- };
- // get the device context's best, available pixel format match
- pixelFormat = ChoosePixelFormat(mDeviceContext, &pixelFormatDescriptor);
- // If the video card/display can handle our desired pixel format then we set it as the current one.
- result = SetPixelFormat(mDeviceContext, pixelFormat, &pixelFormatDescriptor);
- if(result != 1) {return false;}
- // Create a OpenGL 4.0 rendering context.
- mRenderContext = wglCreateContext(mDeviceContext);
- if(mRenderContext == NULL) {return false;}
- // Set the rendering context to active
- result = wglMakeCurrent(mDeviceContext, mRenderContext);
- if(result != 1) {return false;}
- // Set the depth buffer to be entirely cleared to 1.0 values
- glClearDepth(1.0f);
- // Enable depth testing
- glEnable(GL_DEPTH_TEST);
- // Set the polygon winding to front facing for the left handed system
- glFrontFace(GL_CW);
- // Enable back face culling
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- // Initialize the world/model matrix to the identity matrix
- BuildIdentityMatrix(mWorldMatrix);
- // Set the field of view and screen aspect ratio
- fieldOfView = 3.14159265358979323846f / 4.0f;
- screenAspect = (float)screenWidth / (float)screenHeight;
- // Build the perspective projection matrix
- BuildPerspectiveFovLHMatrix(mProjectionMatrix, fieldOfView, screenAspect, screenNear, screenDepth);
- // Get the name of the video card
- vendorString = (char*)glGetString(GL_VENDOR);
- rendererString = (char*)glGetString(GL_RENDERER);
- // Store the video card name in a class member variable so it can be retrieved later
- strcpy_s(mVideoCardDescription, vendorString);
- strcat_s(mVideoCardDescription, " - ");
- strcat_s(mVideoCardDescription, rendererString);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment