multithreading - GLFW 3.0 Resource Loading With OpenGL -


i have started overwhelming scene of opengl resource loading on separate thread main thread can continue render object. when stepping in, noticed glfw released updated version month easier context management.

however, glfwmakecontextcurrent() have been unable make possible. in loading thread use function , after completion add again main thread receives context further use. not allowing me create , compile shaders or other opengl related creation.

updated:

what needs done can use glfw in situation? glfw portable, love use code includes it. not know necessary steps prepare thread keeping glfw api in mind.

as this blog post states, need create 2 threads opengl context (not same context ;d ) , share information. however, instructions shown platform specific. how can make use of glfw steps in example platform independent possible?

use share parameter on glfwcreatewindow():

#include <vector> #include <gl/glew.h> #include <glfw/glfw3.h> #include <boost/thread.hpp>  using namespace std; using namespace boost;  // reload shared vbo random data every second void mythread( glfwwindow* win, gluint vbo ) {     glfwmakecontextcurrent( win );     glewinit();     while( true )     {         float temp[ 512 ];         for( size_t = 0; < 512; i+=2 )         {             temp[ i+0 ] = rand() % 600;             temp[ i+1 ] = rand() % 600;         }          glbindbuffer( gl_array_buffer, vbo );         glbufferdata( gl_array_buffer, sizeof( float ) * 512, temp, gl_dynamic_draw );         glbindbuffer( gl_array_buffer, 0 );          // oddly important, might need glfinish()         glflush();          this_thread::sleep( posix_time::milliseconds( 1000 ) );      } }  int main( int argc, char** argv ) {     if( !glfwinit() )         return -1;      glfwwindowhint( glfw_visible, gl_false );     glfwwindow* threadwin = glfwcreatewindow( 1, 1, "thread window", null, null );      glfwwindowhint( glfw_visible, gl_true );     glfwwindow* window = glfwcreatewindow( 600, 600, "hello world", null, threadwin );     glfwmakecontextcurrent( window );     glewinit();      // load shared vbo dummy data     float temp[ 512 ];     gluint vbo;     glgenbuffers( 1, &vbo );     glbindbuffer( gl_array_buffer, vbo );     glbufferdata( gl_array_buffer, sizeof( float ) * 512, temp, gl_dynamic_draw );     glbindbuffer( gl_array_buffer, 0 );     thread athread( mythread, threadwin, vbo );      while( !glfwwindowshouldclose( window ) )     {         glclear( gl_color_buffer_bit );          glmatrixmode( gl_projection );         glloadidentity();         glortho( 0, 600, 0, 600, -1, 1 );         glmatrixmode( gl_modelview );         glloadidentity();          glenableclientstate( gl_vertex_array );            glbindbuffer( gl_array_buffer, vbo );         glvertexpointer( 2, gl_float, 0, 0 );         glcolor3ub( 255, 0, 0 );         gldrawarrays( gl_lines, 0, 256 );         glbindbuffer( gl_array_buffer, 0 );         gldisableclientstate( gl_vertex_array );             glfwswapbuffers( window );         glfwpollevents();         this_thread::sleep( posix_time::milliseconds( 16 ) );      }      athread.interrupt();     athread.join();      glfwterminate();     return 0; } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -