Hello everyone!
I'm trying to create a window with SDL2. This code works perfectly:
_window = SDL_CreateWindow("Hello", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0);
However, this code already doesn't:
_window = SDL_CreateWindow("Hello", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
if (!_window){
throw SDLException("Can not create window!");
}
I don't understand what's the problem: the exception is not thrown. I'm trying to get OpenGL 4.2, because glxinfo shows it's available:
Quote$ glxinfo | grep version
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
Max core profile version: 4.2
Max compat profile version: 3.0
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.0
OpenGL core profile version string: 4.2 (Core Profile) Mesa 18.0.5
OpenGL core profile shading language version string: 4.20
OpenGL version string: 3.0 Mesa 18.0.5
OpenGL shading language version string: 1.30
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 18.0.5
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.003
However the window is not shown. Here's the complete code:
if (SDL_Init(SDL_INIT_VIDEO) < 0){
throw SDLException("Can not init SDL");
}
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
_window = SDL_CreateWindow("Hello", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
if (!_window) throw SDLException("Can not create window!");
SDL_ShowWindow(_window);
_gl_context = SDL_GL_CreateContext(_window);
if (!_gl_context) throw SDLException("Can not create an OpenGL context!");
SDL_GL_SetSwapInterval(1);
However it's not crashing the app!!! I can also play some games on my laptop: MegaGlest, 0 A.D..They all work.
I also tried to add: set (OpenGL_GL_PREFERENCE GLVND) in CMakeLists.txt, but it also didn't help.
Great thanks for your attention. I tried to find the solution in the Internet first, but I've failed to find it. I hope, I'm not the only person with this problem.
p.s. Just in case, I'm also attaching the project. I'm doing it under Ubuntu 18.04, but it shouldn't make too much sense, since it uses Qt Creator and CMake. To build the project you need to have a CMake or Qt Creator installed. If you have CMake you can download just 'client(light)' file.
So, to build and run it:
1. go to the client/build directory
2. run: cmake ..&& make && ./Arena