Jump to content
  • Advertisement
Sign in to follow this  
Wilds

OpenGL No Full viewport

This topic is 2639 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there fellow OpenGL users!

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?
screenproblem00.th.jpg

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;
Edited by Wilds

Share this post


Link to post
Share on other sites
Advertisement
You need to show the code that is relevant to the behavior you describe. You say that it's a problem with the viewport, but you didn't show any viewport code. You also said that it happens when you resize the window, but you didn't show any resize handling code either. And the blue square must appear from some drawing code, which isn't shown either. How you create your rendering context and load your extensions are not important here.

Share this post


Link to post
Share on other sites
Added some message handling code to my OP post.
On my laptop it starts like that on the screenshot, so that would be intializing code.

Share this post


Link to post
Share on other sites
The window sized passed with the GL_SIZE message is the size of the client are. Don't make a window size to client area size adjustment again.

Share this post


Link to post
Share on other sites
Hidden
Here is what I do if I want to make full screen viewport:

Style of my window has only WS_POPUP flag.

Ex-Style of my window has only WS_EX_APPWINDOW flag.

Window dimensions determined by this way:



ShowWindow((HWND),SW_MAXIMIZE);

RECT rect;

GetClientRect(&rect);

WindowWidth = rect.right;

WindowHeight = rect.bottom;

 

Or also possible this way:



WindowWidth = GetSystemMetrics(SM_CXSCREEN);

WindowHeight = GetSystemMetrics(SM_CYSCREEN);

SetWindowPos((HWND),HWND_TOP,0,0,WindowWidth,WindowHeight, SWP_DRAWFRAME|SWP_SHOWWINDOW);





-me

Share this post


Link to post
It seemed that I forgot to pass the this pointer when creating the window.
The window never reached my own message processor.

I also managed to call the DefWindowProc twice. solved it now

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!