函数1调用函数2,它调用函数3
现有问题是函数1中两行注释的代码没有按预期运行。我有一个显示器,因为这些线条只是黑色。
//std::thread *thread1 = new std::thread(&Screen::DisplayRows, this, pbr );
//thread1->join();
但是,这两行DisplayRows(pbr);
下方的行似乎工作得很好,并且显示正确显示。本质上,我正在寻找在函数1的for循环中创建的多个线程,以及那些线程通过函数3中的glfwSwapBuffers(_window);
更新显示。
现在,两行注释的代码确实调用了函数3,但显示没有更新。注释行和DisplayRows(pbr);
应该做同样的事情,但是当涉及到注释行时,显示不会反映出来。
功能1
void Screen::Display(Container* PBC, SimpleSorter *Solution)
{
while (!glfwWindowShouldClose(window))
{
// Scale to window size
GLint windowWidth, windowHeight;
glfwGetWindowSize(window, &windowWidth, &windowHeight);
glViewport(0, 0, windowWidth, windowHeight);
// Draw stuff
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Set the background color
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WIDTH, HEIGHT, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
PBC->DrawContainer();// 0, 0);
std::vector<PixelBlockRow> row = PBC->getRows();
for ( int i =0; i <PBC->getRows().size(); i ++)
{
PixelBlockRow *pbr = &row[i];
//std::thread *thread1 = new std::thread(&Screen::DisplayRows, this, pbr );
//thread1->join();
DisplayRows(pbr);
}
getchar();
}
}
功能2
void Screen::DisplayRows(PixelBlockRow *PBR)
{
_Solution->Sort(PBR);
}
功能3
void SimpleSorter::Sort( PixelBlockRow * p)
{
auto block = p->GetRow();
for (int i = 0; i < block.size(); i++)
{
for (int j = 0; j < i; j++)
{
if (block[i].GetColor().GetR() < block[j].GetColor().GetR())
{
Color c = block[i].GetColor();
block[i].SetColor(block[j].GetColor());
block[j].SetColor(c);
p->DrawPixelBlockRow();
Sleep(5);
glfwSwapBuffers(_window);
std::cout << ij++ << std::endl;
}
}
}
for (int i = 0; i < block.size(); i++) {
Color c = block[i].GetColor();
std::cout << "(" << c.GetR() << "," << c.GetG() << "," << c.GetB() << "),";
}
}