Solved

Rendering Problem with OpenGL OR Thread OR C++ OR WIN32

Posted on 2004-09-06
3
307 Views
Last Modified: 2013-12-04
Part of a program i'm developing has an OpenGL interface. I originally wroted the program
as non-threaded, but have decieded to add a thread to repeatedly render the GUI, allowing
rendering while I block waiting on a comm port. However when I add a loop in a thread which
calls the rendering function, it won't render, but If I call the rendering function from the main
message loop it will. (I've more code as required)
[IN THE CODE BELOW wgui is a global (only 1) instance of the class WirmedGUI)]
[IN THE CODE BELOW the problem is not caused by equalizeBuffers();]

------------- MESSAGE LOOP CALL ------------------
      //Enter the message loop
      while(!done)      
      {
            //Poll for waiting messages
            while(PeekMessage( &lpMsg, NULL , 0, 0, PM_REMOVE) && !done)
            {
                  if (lpMsg.message==WM_QUIT) done=true;      //Check for the end condition                  
                  TranslateMessage( &lpMsg );
                  DispatchMessage( &lpMsg );
                  
            }
            
            //trigger an update in the GUI
            wgui.updateImage(false);              //<---------------------------------------------------THIS CALL WORKS
      }

------------- THREAD LOOP CALL ------------------
//Rendering Thread Primary Function
DWORD WINAPI WirmedGUI::ThreadFunc( LPVOID lpParam )
{
      //While were not done
      while(!wgui.done)
      {
            printf("THREAD RENDER\n");
            
            //Update the image
            wgui.updateImage(false);          //<-----------------------------------------------------THIS CALL DOESN'T WORK
      }      
      return 0;
}

------------- THREAD LOOP CALL ------------------
//Update internal scene representation, call DrawGLScene (to execute the GL commands), and revaildate the display.
void WirmedGUI::updateImage(bool justgui=false)
{      
      DrawGLScene(justgui);
      SwapBuffers(hDC);
      ValidateRgn(hWnd, NULL);
      printf("RENDER [hWnd:%i, hDC:%i] > ",hWnd,hDC);
      equalizeBuffers(); //Make sure the frame buffers are the same (prevents flickering of partially updated images      
}
0
Comment
Question by:Falcon_Zero
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 11988689
wgui.updateImage(false);          //<-----------------------------------------------------THIS CALL DOESN'T WORK

What does this mean "doesn't work"? Function is not called, ot screen is not redrawn? Do you see printf output?

However, I think it doesn't matter. Main thread should draw the screen, and COM port should be handled in the worker thread. This is standard program design, I suggest you to change your program accordingly. Drawing on the screen from worker thread creates a lot of problems.
0
 
LVL 1

Author Comment

by:Falcon_Zero
ID: 11988736
The result varies from computer to computer. On one PC i get very fast flickering 1inch bands of the OpenGL scene against the previous background (Desktop in this case) on another, I just get a black screen, which leads me to suspect a problem with OpenGL or something causing a problem which is manifest by OpenGL.
As for placing the comm functions in a worker,  I was really trying to avoid having to change the architecture of the program, which is already 10k lines long. The multithreaded side of things is in responce to a change in requirements. If I can make the above code work, thats the extent of the multithreading required. (Only ever 2 threads for this program (main & gfx).)
I agree that its better to have the gfx in the main thread, but I since I'm trying to change this with the minimum of rewriting i'll take a beating for bad style, but i'll also get
the praise for making the target date.
0
 
LVL 1

Author Comment

by:Falcon_Zero
ID: 12032050
Well, I guess I'll have to bite the bullet on this one. I'm no closer to a solution, so I'll just have to rewrite the com side of things as multi-threaded.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Rubik's Cube Code for Effective Presentation 3 77
Help Required 2 46
Hide file extensions in Notepad++ tabs 2 55
How to delete text box content on subform 1 20
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question