[英]I can't create two contexts in opengl using sdl2
i need a debug window, in which i could better observe the scenario the possible changes, and change in real time, using sdl2 and opengl 3.3 i created the second window, changed the event system to close the window using multiple windows, but glContext is越野車,一旦我創建了第二個上下文,並且好像第一個似乎存在,從而破壞了 windows 之一的渲染,是否可以使用 sdl2 使用多個 opengl 上下文?
this->window=SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL | (resize ? SDL_WINDOW_RESIZABLE : SDL_WINDOW_SHOWN));
SDL_GLContext windowContext=SDL_GL_CreateContext(this->window);
this->debug=SDL_CreateWindow("debug", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 600, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
SDL_GLContext debugContext=SDL_GL_CreateContext(this->debug);
下面是兩個具有不同上下文的 windows 的示例:
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <stdio.h>
int main(int argc, char **argv) {
(void)argc, (void)argv;
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL_Init error: %s\n", SDL_GetError());
return 1;
}
SDL_Window *windows[2];
SDL_GLContext contexts[2];
for(int i = 0; i != sizeof(windows)/sizeof(windows[0]); ++i) {
char title[32];
snprintf(title, sizeof(title), "window%d", i);
windows[i] = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480, SDL_WINDOW_OPENGL);
if(!windows[i]) {
fprintf(stderr, "SDL_CreateWindow error: %s\n", SDL_GetError());
return 1;
}
contexts[i] = SDL_GL_CreateContext(windows[i]);
if(!contexts[i]) {
fprintf(stderr, "SDL_GL_CreateContext error: %s\n", SDL_GetError());
return 1;
}
}
int running = 1;
while(running) {
SDL_Event ev;
while(SDL_PollEvent(&ev)) {
if(ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_q) {
running = 0;
break;
}
}
SDL_GL_MakeCurrent(windows[0], contexts[0]);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(windows[0]);
SDL_GL_MakeCurrent(windows[1], contexts[1]);
glClearColor(0, 1, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(windows[1]);
}
return 0;
}
但是每個 window 的單獨上下文不是必需的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.