简体   繁体   中英

Am i deleting sdl2 and opengl right c++

I was wondering if i am deleting sdl and opengl the right way.

Here is the code of my deconstructor:

Mix_CloseAudio();

// Close and destroy the window
SDL_DestroyWindow(window);
SDL_GL_DeleteContext(gContext);

// Clean up
SDL_Quit();

glDeleteProgram(programID);
glDeleteTextures(1, &textureID);

Nope, that's almost exactly backwards.

The SDL window owns the GL context, and the GL context owns the GL objects.

You want something like this:

Mix_CloseAudio();

glDeleteProgram(programID);
glDeleteTextures(1, &textureID);

SDL_GL_DeleteContext(gContext);

// Close and destroy the window
SDL_DestroyWindow(window);

// Clean up
SDL_Quit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM