How to change resolution?
My openGL app has pretty much the same basic Windows structure as NeHe''s tut''s or Trent Polack''s Shining engine (go see http://nehe.gamedev.net if you''re not familliar with it, but I guess you are). Now I''ve made a game and I''m adding a menu. Via this menu I want to change the resolution and fullscreenflag. How do I destroy the old window and create a new one?
I tried using the ShutdownGL() and InitGL() functions. After that the program keeps running but everything goes white.
I also tried just destroying the window and creating a new one, but after that, nothing gets drawn at all! (although the program still keeps running).
How do I properly change resolutions? Thanx in advance.
Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][E-mail]
<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>
Anyone? Please? I cannot figure it out. I can do OpenGL but I s*ck at Win32. Thanx.
Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][E-mail]
Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][E-mail]
<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>
Look into ChangeDisplaySettings() function for changing screen res.
-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack
-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
Here''s the deal: once you create a new OpenGL window, (in case you haven''t checked the code) you bind a rendering context to it. You use this rendering context for pretty much everything you do later on - in other words it simply needs to exist before you can do "OpenGL stuff".
Now, you say you destroy the window and then re-create it. What destroying the window means is also destroying the rendering context - at least it''s a part of Nehe''s code. This effectively removes and textures you have managed to load while that RC was active among other things. Therefore, once you''ve destroyed and created the RC anew, you need to re-load the textures while that RC is active. Use wglMakeCurrent() to activate a RC (for multiple windows an individual RC exists for each window so you have to load all of the textures for each window, thus taking up n times more memory (n is the number of windows)). That''s, of course, unless you figure out a way to make several windows share a RC, or not destroy the RC and effectively bind it to another window (your case).
Hope this explains it to you,
Crispy
Now, you say you destroy the window and then re-create it. What destroying the window means is also destroying the rendering context - at least it''s a part of Nehe''s code. This effectively removes and textures you have managed to load while that RC was active among other things. Therefore, once you''ve destroyed and created the RC anew, you need to re-load the textures while that RC is active. Use wglMakeCurrent() to activate a RC (for multiple windows an individual RC exists for each window so you have to load all of the textures for each window, thus taking up n times more memory (n is the number of windows)). That''s, of course, unless you figure out a way to make several windows share a RC, or not destroy the RC and effectively bind it to another window (your case).
Hope this explains it to you,
Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
That is exactly what I tried to do in my own function. The RC and DC still exist... The problem is, how do I bind them to the new window? Here's the code I tried to use (and yield an empty window. Not even black or white or so... just transparent)
note: all variables not defined in this function are defined in the class RAID3D (like width, height, bits) or as globals (like hWnd, hInstance, etc).
All the OpenGL stuff should still be loaded (like textures etc). How do I set this stuff to the newly created window? Thanx in advance.
EDIT: Tried to find the code blocks....
Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][E-mail]
[edited by - smarechal on January 26, 2003 3:28:47 PM]
void RAID3D::ReSizeWindow(GLsizei newwidth, GLsizei newheight, GLsizei newbits, bool newfullscreen)
{
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)newwidth; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)newheight; // Set Bottom Value To Requested Height
//kill all the old stuff
if (newfullscreen) // Are We In Fullscreen Mode?
{
ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop
ShowCursor(TRUE);
R3Dlog.Output(" Restored displaysettings."); // Show Mouse Pointer
}
if (hWnd && !DestroyWindow(hWnd)) // Are We Able To Destroy The Window?
{
MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
R3Dlog.Output(" Could not destroy window.");
hWnd=NULL; // Set hWnd To NULL
}
else
{
R3Dlog.Output(" Window destroyed.");
}
//create the new stuff
if (newfullscreen) // Attempt Fullscreen Mode?
{
DEVMODE dmScreenSettings; // Device Mode
memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = newwidth; // Selected Screen Width
dmScreenSettings.dmPelsHeight = newheight; // Selected Screen Height
dmScreenSettings.dmBitsPerPel = newbits; // Selected Bits Per Pixel
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{
newfullscreen=false; // Windowed Mode Selected. Fullscreen = FALSE
}
}
if (newfullscreen) // Are We Still In Fullscreen Mode?
{
dwExnonostyle=WS_EX_APPWINDOW; // Window Extended Style
dwnonostyle=WS_POPUP; // Windows Style
ShowCursor(FALSE); // Hide Mouse Pointer
}
else
{
dwExnonostyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwnonostyle=WS_OVERLAPPEDWINDOW; // Windows Style
}
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
// Create The Window
if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
CLASSNAME, // Class Name
title, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
ShutdownGL(); // Reset The Display
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
R3Dlog.Output(" Window creation error.");
Game.ShutDown();
return; // Return FALSE
}
else
{
R3Dlog.Output(" Window created.");
}
ShowWindow(hWnd,SW_SHOW); // Show The Window
SetForegroundWindow(hWnd); // Slightly Higher Priority
SetFocus(hWnd); // Sets Keyboard Focus To The Window
ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen
bits=newbits;
width=newwidth;
height=newheight;
fullscreen=newfullscreen;
}
note: all variables not defined in this function are defined in the class RAID3D (like width, height, bits) or as globals (like hWnd, hInstance, etc).
All the OpenGL stuff should still be loaded (like textures etc). How do I set this stuff to the newly created window? Thanx in advance.
EDIT: Tried to find the code blocks....
Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][E-mail]
[edited by - smarechal on January 26, 2003 3:28:47 PM]
<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>
quote:
Original post by smarechal
That is exactly what I tried to do in my own function. The RC and DC still exist... The problem is, how do I bind them to the new window? Here''s the code I tried to use (and yield an empty window. Not even black or white or so... just transparent)
This is exactly what I was telling you - you can''t transit one rendering context from one HDC to another. And calling DestroyWindow() or anything similar also destroys the HDC which means you''re suffed. I don''t know about the transparency, but re-load your textures once you''ve created the new window (which means creating a new HDC and HRC).
Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Aha! Now I get it
Thanx a lot. I thought I could get away with it without recreating an RC and DC and reloading all the textures... I guess not! Fortunately I don''t use many textures so reloading them is not a big problem.
Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][Webdesign][E-mail]

Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][Webdesign][E-mail]
<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>
heh, I had the same problem when I was just starting.. It drove me nuts

I finally got it working! Thanx a lot guys
Now off to meet the next programming challenge. A level editor!
Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][Webdesign][E-mail]

Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][Webdesign][E-mail]
<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement