Window not displaying SDL2
I just needed an event loop. I added this code and it worked:
SDL_bool quit = SDL_FALSE;
while(!quit)
{
SDL_RenderPresent(renderer);
SDL_WaitEvent(&event);
if(event.type == SDL_QUIT)
quit = SDL_TRUE;
}
Thank you to HolyBlackCat for your comment!
SDL Window does not show even with Event Loop
You need to include SDL_MainReady
as you are not using SDL_main
.
See here
So you code would be adjusted like
int main() {
SDL_Window* window;
SDL_SetMainReady();
SDL_Init(SDL_INIT_EVERYTHING);
...
return 0;
}
SDL window not showing?
Like the others state, your program terminates immediately so the window should "flash" momentarily. You can have the window appear for a few seconds by using SDL_Delay
:
SDL_Window *win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
if (win == nullptr){
std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
SDL_Quit();
return 1;
}
SDL_Delay(2000);
SDL_DestroyWindow(win);
SDL_Quit();
And remember to call SDL_DestroyWindow
.
A while(true) {}
loop will just cause your program to freeze. You probably want something like the following so that it listens for events, and you can close the window at your leisure.
SDL_Event e;
bool quit = false;
while (!quit){
while (SDL_PollEvent(&e)){
if (e.type == SDL_QUIT){
quit = true;
}
if (e.type == SDL_KEYDOWN){
quit = true;
}
if (e.type == SDL_MOUSEBUTTONDOWN){
quit = true;
}
}
}
Make an sdl window not show up on the menubar
Take a look to SDL_WindowFlags, SDL_WINDOW_SKIP_TASKBAR
is what you are looking for.
Uint32 flags = SDL_WINDOW_SKIP_TASKBAR;
SDL_Window * window = SDL_CreateWindow(
/* ... */
flags
);
Related Topics
Advice on Mocking System Calls
Understanding Boost::Disjoint_Sets
How to Use a Lambda Expression as a Template Parameter
How to Catch Out of Memory Exception in C++
C++ Frontend Only Compiler (Convert C++ to C)
How to Read Jpeg and Png Pixels in C++ on Linux
Is Using a Vector of Boolean Values Slower Than a Dynamic Bitset
Brute-Force, Single-Threaded Prime Factorization
Implementing Component System from Unity in C++
How to Make the for Each Loop Function in C++ Work with a Custom Class
How to Choose Heap Allocation VS. Stack Allocation in C++
How to Iterate Through a List of Objects in C++