In the following image you can see black borders around the viewport, this happens when I resize the window. it starts alright on my desktop but on my laptop it also starts out like this.
Does anyknow a solution to this?
The create form method
// styles for normal window
DWORD nStyle = WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME;
DWORD exStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
RECT windowRect = {0};
PIXELFORMATDESCRIPTOR pfd = {0};
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
pfd.iLayerType = PFD_MAIN_PLANE;
// set the rect for the window dimensions
windowRect.left = 0;
windowRect.right = mWidth;
windowRect.top = 0;
windowRect.bottom = mHeight;
AdjustWindowRectEx(&windowRect, nStyle, false, exStyle);
// set the new window width and height
mWidth = windowRect.right - windowRect.left;
mHeight = windowRect.bottom - windowRect.top;
// create DUMMY window
HWND dummyWindow = ::CreateWindowEx(exStyle,
mWindowName,
mWindowName,
nStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
0,0,
mWidth, mHeight,
NULL,
NULL,
mHInstance,
NULL);
// get the device context for the DUMMY window
mWindowDC = GetDC(dummyWindow);
// create a dummy window and opengl Context and initialize glew
if( !InitGlew(pfd) )
return false;
// now that the extensions are setup we can delete the window and start over
wglMakeCurrent(NULL, NULL);
wglDeleteContext(mGLRC);
ReleaseDC(dummyWindow, mWindowDC);
DestroyWindow(dummyWindow);
// lets create the main window
mMWindow = ::CreateWindowEx(exStyle,
mWindowName,
mWindowName,
nStyle,
CW_USEDEFAULT, CW_USEDEFAULT,
mWidth, mHeight,
0, 0,
mHInstance,
this);
// return false if the window could not be created
if(mMWindow == 0)
return false;
// get the new HDC
mWindowDC = GetDC(mMWindow);
// create the rendering context
if( !CreateRenderingContext(pfd) )
return false;
// set OpenGL state
SetOpenGLState();
// show & update the window
ShowWindow(mMWindow, true);
UpdateWindow(mMWindow);
return true;
}
The InitGlew method
bool CGameForm::InitGlew(PIXELFORMATDESCRIPTOR& pfd)
{
// choose the most appropiate pixelformat
int pxFormat = ChoosePixelFormat(mWindowDC, &pfd);
// set the current pixelformat DUMMY
SetPixelFormat(mWindowDC, pxFormat, &pfd);
// create openGL rendering context and make it current
mGLRC = wglCreateContext(mWindowDC);
wglMakeCurrent(mWindowDC, mGLRC);
// initialize GLEW, we can because we have created an openGL Rendering Device
GLenum err = glewInit();
if(err != GLEW_OK)
{
return false;
}
// error check
if(mWindowDC == 0 || mGLRC == 0)
{
return false;
}
return true;
}
Create rendering Context method
// tries to create the OpenGL rendering context
bool CGameForm::CreateRenderingContext(PIXELFORMATDESCRIPTOR& pfd)
{
unsigned int nPixCount = 0;
int pixelFormats = 0;
// specify the attributes we want for the pixel format of the rendering context
int pixAttribs[] = {
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_COLOR_BITS_ARB, 32,
WGL_DEPTH_BITS_ARB, 24,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
0};
// get a pixelformat for our rendering context
wglChoosePixelFormatARB(mWindowDC, &pixAttribs[0], NULL, 1, &pixelFormats, &nPixCount);
// check if we could load a valid pixelformat
if(pixelFormats != -1)
{
// set the pixel format
SetPixelFormat(mWindowDC, pixelFormats, &pfd);
// attribute list for the renderin context
int attribs33[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
0
};
// attribute list for the renderin context
int attribs32[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 2,
0
};
// create the openGL rendering context
// check if it succeeded
if((mGLRC = wglCreateContextAttribsARB(mWindowDC, 0, attribs33)) == 0)
{
if((mGLRC = wglCreateContextAttribsARB(mWindowDC, 0, attribs32)) == 0)
{
return false;
}
}
// make the rendering context the current one
wglMakeCurrent(mWindowDC, mGLRC);
}
else{
return false;
}
return true;
}
Piece of message handler code
// the message handler
LRESULT CGameForm::ProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
LONG nStyle = GetWindowLong(mMWindow, GWL_STYLE);
LONG exStyle = GetWindowLong(mMWindow, GWL_EXSTYLE);
PAINTSTRUCT ps;
switch(msg)
{
case WM_SIZE:
mWindowDim.right = LOWORD(wParam);
mWindowDim.bottom = HIWORD(wParam);
// Get the new window dimensions with the styles specified
AdjustWindowRectEx(&mWindowDim, nStyle, false, exStyle);
// change the openGL viewport dimensions
glViewport(0, 0, mWindowDim.right, mWindowDim.bottom);
GetClientRect(mMWindow, &mWindowDim);
break;