I am trying to use SDL2 for OpenGL interop. I find something very strange during StartRasterGL()
that I still don’t know why.
First I make and compile the gvdb library according to Readme, selected BUILD_OPENGL
and set build mode as Release.
Then I build g3print sample in Release mode. The sample works find in Release but throwing access violation when
gvdb1.getScene()->AddModel ( "lucy.obj", 1.0, 0, 0, 0 ); // Access violation here gvdb1.CommitGeometry( 0 ); // Send the polygons to GPU as OpenGL VBO
is called. But StartRasterGL() works fine in both mode.
Then I set up my own project using SDL2 and glew 2.1.0.
VolumeGVDB gvdb; float voxel_size = 0.1f; SDL_Init(SDL_INIT_EVERYTHING); // Initilize everything using SDL std::string title = "test"; unsigned int width = 1920; unsigned int height = 1080; 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_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // Set attributes for SDL window SDL_Window* window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL); // Create OpenGL window using SDL SDL_GLContext gl_context = SDL_GL_CreateContext(window); // Create OpenGL context glewInit();
gvdb.SetDebug(true); gvdb.SetVerbose(true); // enable/disable console output from gvdb gvdb.SetProfile(true, true); gvdb.SetCudaDevice(GVDB_DEV_FIRST); gvdb.Initialize(); gvdb.StartRasterGL(); // Access violation
are called. I got access violation when calling StartRasterGL() in debug mode but everything is ok in Release;
I manage to pin down the error line which is line 261 in gvdb_scene.cpp, function AddShader()
// Read shader source GLuint program = glCreateProgram();
This glCreateProgram() is linked to glew.h from gvdb source folder, I am not sure about the cmake process of this but I assume glew is baked into libgvdb.lib and libgvdb.dll. While my project link glew to its official binaries glew32.lib, glew32s.lib and glew32.dll.
I succeed creating a screen quad shader program so I can confirm the gl context exists, also gvdb can find glsl shader files. My initial guess is somehow gvdb_scene cannot find the gl context in debug mode. But calling
does not give me any error in debug. so I think GVDB can find the gl context. Then I think maybe it is the glew version issue so I replaced glew files in gvdb src with newly downloaded version. The same error still happens. Then I changed the cmake mode of gvdb library from Release to Debug but same error still occurs.
As an inexperienced OpenGL user, I am running out of ideas about what is going wrong here. Apparently the glCreateProgram() in AddShader() is linked to libgvdb.lib and my explicit glCreateProgram() is linked to glew32.lib or glew32s.lib. But how come StartRasterGL() works fine in Release but not in Debug?