Hi there,
I came across an issue with my rendering code. As the title says, I get no render output at specific window sizes. For example at 508x525 and less the expected output is visible, but at ~ 552x552 and higher it is not.
Here is my Code:
WndProc
Code cpp:LRESULT CALLBACK Graphics::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ switch(msg){ case WM_DESTROY: PostQuitMessage(0); break; case WM_SIZE: ResetViewport(LOWORD(lParam), HIWORD(lParam)); break; case WM_KEYDOWN: int width = wndSize.iWidth; int height = wndSize.iHeight; break; default: return DefWindowProc(hWnd, msg, wParam, lParam); break; } return 0; }
Init opengl function
Code cpp:bool Graphics::InitGL(){ // Window existing? if(!hMainWnd) return false; // Pixelformat PIXELFORMATDESCRIPTOR pfd; ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR)); pfd.nVersion = 1; pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cAlphaBits = 16; pfd.cDepthBits = 8; // Get the device context if(!(hDC = GetDC(hMainWnd))) return false; // Get appropriate pixel format int iFormat = 0; if(!(iFormat = ChoosePixelFormat(hDC, &pfd))) return false; if(!SetPixelFormat(hDC, iFormat, &pfd)) return false; // Create render context if(!(hRC = wglCreateContext(hDC))) return false; // Make it the current context if(!wglMakeCurrent(hDC, hRC)) return false; // set the viewport // get the client area size RECT clientArea; GetClientRect(hMainWnd, &clientArea); ResetViewport(clientArea.right - clientArea.left, clientArea.bottom - clientArea.top); return true; }
ResetViewport function
Code cpp:void Graphics::ResetViewport(int width, int height){ if(width <= 0) width = 100; if(height <= 0) height = 100; wndSize.iWidth = width; wndSize.iHeight = height; glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, (float)(width/height), 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
Render function
Code cpp:void Graphics::Render(){ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glClearColor(1.0f, 0.15f, 0.76f, 1.0f); glLoadIdentity(); glBegin(GL_TRIANGLES); glColor3f(1.0f, 1.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(0.5f, 1.0f, 0.0f); glVertex3f(1.0f, 0.0f, 0.0f); glEnd(); SwapBuffers(hDC); }
Any suggestions?
EDIT: Does anybody know why I can't change my profile settings?