This is my C++ file:
#include <iostream>
#include "window.h"
#include <SDL2/SDL.h>
int main(int argc, char* argv[]) {
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
std::cout << "Something went wrong" << std::endl;
}
else {
SDL_CreateWindow("Neptune's Limit", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1024, 768, SDL_WINDOW_OPENGL);
}
return 0;
}
When I run it, it flashes up for a half a second and then immediately closes. I have looked at the other posts about this, but the answer to them was about SDL_EVENT. I do not have that anywhere in my program.
What could be wrong?
After create SDL window, use while loop for maintain SDL window.
I learn basic SDL functions with this tutorial
SIMPLE EXAMPLE
#include <iostream>
#include <SDL2/SDL.h>
int main(int argc, char* argv[]) {
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
std::cout << "Something went wrong" << std::endl;
} else {
SDL_CreateWindow("Neptune's Limit", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1024, 768, SDL_WINDOW_OPENGL);
while( true ) {
// SDL RUNNING
// Poll Event Code Maybe here!
}
}
return 0;
}
Maybe this code doesn't exit because there's no exit-SDL code.
For exit program, add SDL_Event:
SDL POLL EVENT EX)
SDL_Event e;
while(true) { // SDL loop
while( SDL_PollEvent( &e ) != 0 ) {
if( e.type == SDL_QUIT ) {
// Ctrl + C in console !
}
} // end of handling event.
}
Hope this helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With