您正在使用哪個版本的SDL?我以爲這是SDL-1.2.14,並試圖與該版本如下:
#include "SDL.h"
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface *screen;
#if 1
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
SDL_Delay(2000);
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL | SDL_FULLSCREEN);
SDL_Delay(5000);
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
SDL_Delay(5000);
#else
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL | SDL_FULLSCREEN);
SDL_Delay(2000);
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
SDL_Delay(5000);
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL | SDL_FULLSCREEN);
SDL_Delay(5000);
#endif
SDL_Quit();
return 0;
}
的代碼都從windowd到全屏和背部或周圍取決於預處理標誌設置相反的方向。
我沒有得到一個全屏模式的窗口框架,而有一個時忽略SDL_FULLSCREEN
。我還將SDL_SetVideoMode
的返回值分配給一個變量,因爲這可能會改變。切換到全屏窗口時,可能仍會顯示在窗口模式下顯示的屏幕內容。在全屏模式下,導致我看到位於屏幕左上角的SDL_app窗口。您必須清除屏幕以確保只顯示自己的內容。
還有一個SDL_WM_ToggleFullscreen
函數。它在Windows上不起作用,但指向文檔的鏈接包含有關如何以便攜方式處理切換窗口/全屏的示例。 從SDL文件的代碼示例如下:
/* Anyone may copy and alter this fragment of pseudo-code and use it however they wish */
#include "SDL.h" /* The only library needed to do this */
Uint32 flags = SDL_SWSURFACE; /* Start with whatever flags you prefer */
SDL_Surface *screen = SDL_SetVideoMode(640, 480, 32, flags); /* Start with whatever settings you prefer */
/* -- Portable Fullscreen Toggling --
As of SDL 1.2.10, if width and height are both 0, SDL_SetVideoMode will use the
width and height of the current video mode (or the desktop mode, if no mode has been set).
Use 0 for Height, Width, and Color Depth to keep the current values. */
flags = screen->flags; /* Save the current flags in case toggling fails */
screen = SDL_SetVideoMode(0, 0, 0, screen->flags^SDL_FULLSCREEN); /*Toggles FullScreen Mode */
if(screen == NULL) screen = SDL_SetVideoMode(0, 0, 0, flags); /* If toggle FullScreen failed, then switch back */
if(screen == NULL) exit(1); /* If you can't switch back for some reason, then epic fail */
的例子並沒有提及何時而切換窗口模式下使用SDL_OPENGL
標誌會發生什麼。我擔心OpenGL上下文可能會被破壞並重新創建,這意味着在切換窗口模式時,您將不得不重新初始化OpenGL並重新加載所有紋理和幾何圖形。
編輯:
我能確認的是,OpenGL上下文被切換顯示模式後銷燬:
創建顯示列表
GLuint list = glGenLists(1);
glNewList(list, GL_COMPILE);
glBegin(GL_LINES);
glVertex2f(0.0f, 0.0f);
glVertex2f(1.0f, 1.0f);
glEnd();
glEndList();
與
調用它
glClear(GL_COLOR_BUFFER_BIT);
glCallList(list);
工作。調用相同列表的SDL_SetVideoMode
之後導致無法繪製任何內容。
您好Trenki,感謝您的答覆。我確實使用了SDL 1.2.14,並且在調整大小後重新初始化OpenGL上下文,並重新加載所有紋理/幾何。我也清除glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);每一幀,所以只有我的東西應該顯示! – aCuria
好吧,這有點奇怪,但是當我改變我的電話setvideomode,使前3個參數爲空,它似乎工作! – aCuria