Hey, i've been working on a very simple opengl template, based on nehe's oop code, for my applications.
the problem i am having is when i try to render stuff in fullscreen opengl window, every thing is very wonky.
Where as in windowed mode it works perfectly. i have looked over and over the code, not being able to find out what i did worng.
If some of you may enlighten me. I have managed to narrow it down to OpenGL Initialization routine, at least thats where i think the problem is.
few things to note in the code below, gfxWindow, and pTrace are 2 global variable/classes, gfxWindow contains all the window info, like resolution, bits per pixel, etc, where are pTrace is just a loging class that i use.
And sorry if anyone thinks this is messy way of doing things, neat ness is not top of my priorities list
bool COpenGL::InitGL()
{
pTrace->toFile("\nInitializing OpenGL States");
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
if (gfxWindow.winInit.bFullscreen)
{
pTrace->toFile("\n\tWindow is set to FullScreen mode");
}
else
pTrace->toFile("\n\tWindow is set to Windowed mode");
return true;
}
bool COpenGL::CreateGfxWindow()
{
int extGLError;
GLuint PixelFormat;
WNDCLASSEX wndClass;
DWORD dwExStyle;
DWORD dwStyle;
wndClass.cbSize = sizeof(wndClass);
wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndClass.lpfnWndProc = procWin;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = gfxWindow.winInit.hInstance;
wndClass.hIcon = LoadIcon(gfxWindow.winInit.hInstance, IDI_APPLICATION);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = NULL;
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = "Main Window";
wndClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
if (!RegisterClassEx(&wndClass))
{
pTrace->toFile("\n* Failed to Register the Window Class.");
return false;
}
if (gfxWindow.winInit.bFullscreen)
{
pTrace->toFile("\n\tSetting dmScreenSettings values");
DEVMODE dmScreenSettings;
ZeroMemory(&dmScreenSettings, sizeof(DEVMODE));
dmScreenSettings.dmSize = sizeof(DEVMODE);
dmScreenSettings.dmPelsHeight = gfxWindow.winInit.iHeight;
dmScreenSettings.dmPelsWidth = gfxWindow.winInit.iWidth;
dmScreenSettings.dmBitsPerPel = gfxWindow.winInit.iBitDepth;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
pTrace->toFile("\n* Resolution of %d x %d is not supported.",gfxWindow.winInit.iWidth, gfxWindow.winInit.iWidth);
return false;
}
}
if (gfxWindow.winInit.bFullscreen)
{
pTrace->toFile("\n\tSetting dwExStyle values");
dwExStyle = WS_EX_TOPMOST;
dwStyle = WS_POPUP;
}
else
{
dwExStyle = WS_EX_APPWINDOW |WS_EX_WINDOWEDGE;
dwStyle = WS_CAPTION;
}
static PIXELFORMATDESCRIPTOR pfd = {
sizeof (PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
gfxWindow.winInit.iBitDepth,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if (!(gfxWindow.hWnd = CreateWindowEx(dwExStyle, "Main Window",
gfxWindow.winInit.cTitle,
dwStyle | WS_CLIPSIBLINGS |WS_CLIPCHILDREN,
0, 0, gfxWindow.winInit.iWidth, gfxWindow.winInit.iHeight,
NULL, NULL, gfxWindow.winInit.hInstance, NULL)))
{
pTrace->toFile("\n* Window Creation ERROR.");
KillWindow();
return false;
}
if (!(gfxWindow.hDC = GetDC(gfxWindow.hWnd)))
{
pTrace->toFile("\n* Failed to create a GL Device Context");
KillWindow();
return false;
}
if (!(PixelFormat = ChoosePixelFormat(gfxWindow.hDC, &pfd)))
{
pTrace->toFile("\n* Can't find a suitable pixel format");
KillWindow();
return false;
}
if (!SetPixelFormat(gfxWindow.hDC, PixelFormat, &pfd))
{
pTrace->toFile("\n* Failed to Set Pixel Format");
KillWindow();
return false;
}
if (!(gfxWindow.hRC = wglCreateContext(gfxWindow.hDC)))
{
pTrace->toFile("\n* Can not create a GL Rendering Context");
KillWindow();
return false;
}
if (!wglMakeCurrent(gfxWindow.hDC, gfxWindow.hRC))
{
pTrace->toFile("\n* Cannot Activate the GL Rendering Context");
KillWindow();
return false;
}
extGLError = extgl_Initialize();
if (extGLError != 0)
{
pTrace->toFile("\nExtGL exited with code %d", extGLError);
}
else
{
pTrace->toFile("\nCheck Supported GL Versions");
if (extgl_Extensions.OpenGL12)
pTrace->toFile("\n\tOpenGL 1.2 is Supported");
if (extgl_Extensions.OpenGL13)
pTrace->toFile("\n\tOpenGL 1.3 is Supported");
if (extgl_Extensions.OpenGL14)
pTrace->toFile("\n\tOpenGL 1.4 is Supported");
}
ShowWindow(gfxWindow.hWnd, SW_SHOW);
SetForegroundWindow(gfxWindow.hWnd);
SetFocus(gfxWindow.hWnd);
ShowCursor(false);
if(!InitGL())
{
pTrace->toFile("\nFailed to Initialize OpenGL Functions");
KillWindow();
return false;
}
pTrace->toFile("\nOpenGL Window Created");
return true;
}
and in the window Proc i have
this
case WM_SIZE:
if (height ==0)
height =1;
pTrace->toFile("\n+++Entered WM_SIZE");
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 500.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return 0;
[edited by - Roy Fokker on March 24, 2003 10:05:51 PM]