SDL question

Hi guys,

the problem I have here is that my window seems to become unresponsive when the program is running,not too sure why,reason I created an infinite while loop(for now) was to keep the window open but as stated the windows just becomes unresponsive

any ideas why?

thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  #include <iostream>
#include <SDL2/SDL.h>

using namespace std;

int main(int argc,char* argv[])
{

    if(SDL_Init(SDL_INIT_EVERYTHING) < 0){

        cout << "error" << endl;
    }else{

       cout << "worked" << endl;

    }

    SDL_Window *window;

    window = SDL_CreateWindow("window",400,400,400,400,SDL_WINDOW_OPENGL);


    while(true){

        // loop to keep window open but window doesn't respond 

    }


    SDL_Quit();

    return 0;
}
Last edited on
I think you don't realize that SDL2 does not actually use opengl, it uses directX if you don't choose to manually set up opengl (on windows).

The main reason why the window is not responsive is because you are not polling the events, which you must do to tell your OS that everything is a-ok.

Here is a minimal example of, the SDL_PollEvent(&e) is what makes the program work
https://wiki.libsdl.org/SDL_CreateRenderer

Look at lazyfoo tutorials to better understand SDL2 (the tutorial has flaws, like in the textinput example he forgets to free the memory when getting clipboard data, but overall it is a very nice tutorial that shows every step and explains with depth, but at least the code sticks to 1 file which makes it simple).

Also if you look at task manager and you see the program using 100% of one core, make sure you put in a SDL_Delay(1); in the main loop, or make sure vsync is on.
Last edited on
thanks poteto =)
Topic archived. No new replies allowed.