Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Opengl Multithreading (wglMakeCurrent() & wglShareLists() ) issue

Opengl Multithreading (wglMakeCurrent() & wglShareLists() ) issue

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsgame-devhelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    James_722
    wrote on last edited by
    #1

    I am trying to multi-thread my OpenGL code but I have been having trouble. At first, I thought that using opengl inside an alternate thread was impossible, so I just did loading operations and passed the data to opengl in the main thread (I knew once I started passing too much data the main thread would lockup, and noticeably freeze the execution of the program while the data was being moved). I found some forum threads discussing opengl and multi-threading but they don't discuss the details that I'm looking for. namely, how and where do I use wglMakeCurrent() and wglShareLists(). I have been trying to create a display list in the alternate thread with the instructions outlined in the aforementioned forum posts but it crashes every time. I can load the model data, I can even load shaders, but loading a model (of any size) crashes the program. I will show some code snippets but there is really too much to put in one post:

    //This is the code initializing the 2 Render Contexts
    if (!(app.hDC=GetDC(app.hWnd)) || // Get A Device Context?
    !(PixelFormat=ChoosePixelFormat(app.hDC,&pfd)) || // Did Windows Find A Matching Pixel Format?
    !SetPixelFormat(app.hDC,PixelFormat,&pfd) || // Able To Set The Pixel Format?
    !(app.hRC=wglCreateContext(app.hDC)) || // Able To Get A Rendering Context?
    !(app.hRC_thd=wglCreateContext(app.hDC)) || // Get the second context (for loading in parallel thread)
    !(wglShareLists(app.hRC, app.hRC_thd)) ||
    !wglMakeCurrent(app.hDC,app.hRC)) // Try To Activate The Rendering Context
    {
    KillGLWindow();
    return false;
    }

    This next bit is all the initialization and render using opengl

    GLuint o; // display list handle
    vector<v3> v,n; // verts, norms
    vector<v2> u; // texcoords (UVs)
    vector<face> f; // polygons (faces)
    bool done = false;
    void load_thread(void* null) // alternate thread entry point
    {
    wglMakeCurrent(app.hDC, app.hRC_thd); // works fine (seemingly)
    load_rs_shdr(); // works fine
    load_obj("cell.obj", v,n,u,f); // works fine
    gen_display_list(o, v, n, u, f); // crashes my program
    done = true;
    return;
    }

    bool init()
    {
    init_med(v3(0,0,0)); //function to initialize opengl (enable depth, lighting, etc...)

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups