OpenGL:立方体照明墙的问题

问题描述

我正在尝试在旧的 OpenGL 上制作一堵发光的立方体墙。当立方体不是很多(20x20)时,一切都很好,但是当它们更多(50X50)时,就会出现这样的垂直/水平线:

enter image description here

是什么导致了这些线条?

void renderWallOfCubes(double cubeSideLength,glm::vec3 cubesColor,int numBoxesInX,int numBoxesInY)
{
double biggerSide = (numBoxesInX > numBoxesInY) ? numBoxesInX : numBoxesInY;
cubeSideLength /= biggerSide;
std::vector<Vertex> cubeVertices = createCube(cubeSideLength,cubesColor);

for (int stepY = 0; stepY < numBoxesInY; stepY++)
{
    glm::mat4 translateMat = rs.getWorldMatrix();
    for (int stepX = 0; stepX < numBoxesInX; stepX++)
    {
        double cubeHalfEdge = cubeSideLength / 2.0;

        double offsetX = -cubeHalfEdge * (numBoxesInX - 1.0) + (cubeSideLength * stepX);
        double offsetY = -cubeHalfEdge * (numBoxesInY - 1.0) + (cubeSideLength * stepY);

        glm::mat4 newTranslateMat = glm::translate(translateMat,{ offsetX,offsetY,0.0 });
        rs.setWorldMatrix(newTranslateMat);
        rs.renderTriangleSoup(cubeVertices);
        rs.setWorldMatrix(glm::translate(newTranslateMat,{ -offsetX,-offsetY,0.0 }));
    }
}
}

...

void glrenderSystem::setupPointLight(uint32_t index,glm::vec3 position,glm::vec3 Ia,glm::vec3 Id,glm::vec3 Is,float Kc,float Kl,float Kq)
{
int lightIndex = GL_LIGHT0 + index;

if (lightIndex <= GL_LIGHT7)
{
    glEnable(GL_LIGHTING);

    glLightfv(lightIndex,GL_POSITION,glm::value_ptr(glm::vec4(position,1.0f)));
    glLightfv(lightIndex,GL_AMBIENT,glm::value_ptr(Ia));
    glLightfv(lightIndex,GL_DIFFUSE,glm::value_ptr(Id));
    glLightfv(lightIndex,GL_specular,glm::value_ptr(Is));

    glLightf(lightIndex,GL_CONSTANT_ATTENUATION,Kc);
    glLightf(lightIndex,GL_LINEAR_ATTENUATION,Kl);
    glLightf(lightIndex,GL_QUAdratIC_ATTENUATION,Kq);
}
}

...

void glrenderSystem::configphongMaterial(glm::vec3 Ka,glm::vec3 Kd,glm::vec3 Ks,float shininess)
{
glMaterialfv(GL_FRONT,glm::value_ptr(Ka));
glMaterialfv(GL_FRONT,glm::value_ptr(Kd));
glMaterialfv(GL_FRONT,glm::value_ptr(Ks));
glMaterialf(GL_FRONT,GL_SHINInesS,shininess);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)