пишу свою прогу на с++ с использованием sdl + opengl 4.5. нужно создать несколько окон. проблема в том что при закрытии одного окна крашится вся прога.
[VGL] ERROR: in getGLXDrawable--
[VGL] 184: Window has been deleted by window manager
main.cpp
#include "src/GL/gl.h"
#include "src/GL/glwindow.h"
#include <iostream>
#include <SDL2/SDL.h>
int main()
{
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
std::cerr << "Couldn't initialize SDL " << SDL_GetError() << std::endl;
return 0;
}
SDL_GL_LoadLibrary(NULL); // Default OpenGL is fine.
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, 5);
// Also request a depth buffer
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
glinit();
glwindow tmp1("Window1",0,640,480), tmp2("Window2",0,640,480), tmp3("Window3",0,640,480);
tmp1.sert(1,0,0);
tmp2.sert(0,1,0);
tmp3.sert(0,0,1);
while(tmp1.run() || tmp2.run() || tmp3.run())
{
tmp1.draw();
tmp2.draw();
tmp3.draw();
}
std::cout << tmp1.run() << std::endl;
std::cout << tmp2.run() << std::endl;
std::cout << tmp3.run() << std::endl;
SDL_Quit();
return 0;
}
glwindow.h
#ifndef GLWINDOW_H
#define GLWINDOW_H
#include <string>
#include <SDL2/SDL.h>
class glwindow
{
public:
glwindow(std::string caption, int SCREEN_FULLSCREEN, int SCREEN_WIDTH = 960, int SCREEN_HEIGHT = 800);
bool run();
void draw();
std::string geterr();
void sert(float f1,float f2,float f3);
~glwindow();
private:
SDL_Window *window;
SDL_GLContext context;
std::string err;
int qw;
float f1, f2, f3;
};
#endif // GLWINDOW_H
glwindow.cpp
#include "glwindow.h"
#include "src/GL/gl.h"
glwindow::glwindow(std::__cxx11::string caption, int SCREEN_FULLSCREEN, int SCREEN_WIDTH, int SCREEN_HEIGHT)
{
if (SCREEN_FULLSCREEN)
{
window = SDL_CreateWindow(
caption.c_str(),
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_OPENGL
);
}
else
{
window = SDL_CreateWindow(
caption.c_str(),
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL
);
}
if (window == NULL)
{
err = "Couldn't set video mode ";
err += SDL_GetError();
return;
}
context = SDL_GL_CreateContext(window);
if (context == NULL)
{
err = "Failed to create OpenGL context ";
err += SDL_GetError();
return;
}
qw = 1;
}
bool glwindow::run()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT || event.window.event == SDL_WINDOWEVENT_CLOSE)
{
qw = 0;
}
}
return qw;
}
void glwindow::draw()
{
SDL_GL_MakeCurrent(window,context);
GLfloat red[] = { f1, f2, f3, 1.0f };
glClearBufferfv(GL_COLOR, 0, red);
SDL_GL_SwapWindow(window);
}
void glwindow::sert(float f1, float f2, float f3)
{
this->f1 = f1;
this->f2 = f2;
this->f3 = f3;
}
glwindow::~glwindow()
{
}