samedi 28 février 2015

SDL2 + OpenGL crashing?


I followed a tutorial to set up SDL 2 with OpenGL, but when I ran the application, it immediately closed. I messed around with some values and found out that if I set the depth bits to 32, it works and stays open. Why would it support higher values but not lower values (like 16 and 24)? This is a problem, because I want my application to be able to run on other windows machines, but some only support 16 bit depth (I think?).



if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
return false;
}

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Useless?
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

mainWindow = SDL_CreateWindow("OpenGL with SDL", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, resolution.SCREEN_WIDTH, resolution.SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);

if (!mainWindow) {
return false;
}

mainContext = SDL_GL_CreateContext(mainWindow);

SDL_GL_SetSwapInterval(1);


Can I at least automatically set it to something that is supported at runtime?


Edit


It also appears to work with 25-31.




Aucun commentaire:

Enregistrer un commentaire