我正在遵循SDL上的Lazy Foo tutorial。
使用SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
SDL_CreateWindow("SDL Tutorial", 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
创建一个窗口并运行二进制文件时,菜单栏出现,但窗口没有。我需要一些指导以进一步调试它。
我也尝试过手动设置窗口位置,但是没有运气。
SDL_GetError()
一切都编译成功,#include <SDL2/SDL.h>
#include <stdio.h>
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main(int argc, const char * argv[]) {
FILE *log_file;
log_file = fopen("log.log", "a+");
//The window we'll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Surface* screenSurface = NULL;
//Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(log_file, "SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
}
else
{
//Create window
window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (window == NULL)
{
fprintf(log_file, "Window could not be created! SDL_Error: %s\n", SDL_GetError());
}
else
{
//Get window surface
screenSurface = SDL_GetWindowSurface(window);
//Fill the surface white
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
//Update the surface
SDL_UpdateWindowSurface(window);
fprintf(log_file, "SDL_Error: %s\n", SDL_GetError());
//Wait two seconds
SDL_Delay(2000);
}
}
//Destroy window
SDL_DestroyWindow(window);
//Quit SDL subsystems
SDL_Quit();
return 0;
}
不会产生任何错误。我登录到文件进行确认。
boolean flag = True
for(int i = 1; i < 20 && flag; i *= 2) {
//Code in here
}
答案 0 :(得分:0)
它不起作用的原因是因为我没有设置事件循环。
我是documentation on how to draw a line,在那里有一个例子。
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = SDL_TRUE;
}
}