Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带有意外行的GLPOLYGONONFSET_Java_Opengl_Lwjgl - Fatal编程技术网

Java 带有意外行的GLPOLYGONONFSET

Java 带有意外行的GLPOLYGONONFSET,java,opengl,lwjgl,Java,Opengl,Lwjgl,我正在用glpolygonMode(GL_前、后、GL_线)渲染三角形条带。 然后我将线偏移启用为该设置glPolygonOffset(-0.8f,-1.0f) 不管我用什么设置偏移,我最终得到的是闪烁的随机线 四处走动时进进出出。这是一张gif。它看起来像什么。如果有人能帮忙的话 给出他们认为错误的想法,这会很好 这是我的方法,如果有人需要看的话,我会渲染线条 public void lines() { GL11.glColor3f(0.0f, 0.0f, 0.0f); GL

我正在用glpolygonMode(GL_前、后、GL_线)渲染三角形条带。 然后我将线偏移启用为该设置glPolygonOffset(-0.8f,-1.0f)

不管我用什么设置偏移,我最终得到的是闪烁的随机线 四处走动时进进出出。这是一张gif。它看起来像什么。如果有人能帮忙的话 给出他们认为错误的想法,这会很好

这是我的方法,如果有人需要看的话,我会渲染线条

public void lines() {
    GL11.glColor3f(0.0f, 0.0f, 0.0f);
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);       

    Triangle currentTri = new Triangle();
    List<Triangle> triList = new ArrayList<Triangle>();                               
    boolean xSwitch = false;

    for (int z=0; z<=100; z+=2) {
        GL11.glEnable(GL11.GL_POLYGON_OFFSET_LINE);
        GL11.glPolygonOffset (-0.8f, -1.0f);

        GL11.glBegin(GL11.GL_TRIANGLE_STRIP);

        int triPointIndex = 0;
        boolean zSwitch = true;
        xSwitch = !xSwitch;
        float zVal;
        float xVal;

        for (int x=0; x<100; x+=1) {
            xVal = x;
            float randY;
            zSwitch = !zSwitch;    

            // this is what determines the xSwitch and zSwitch outcomes.
            // changes the zVal and randY to match what must alternate.
            if (xSwitch) {
                if (zSwitch) {
                    zVal = z;
                    randY = randYList[z][x];
                } else {
                    zVal = z + 2.0f;
                    randY = randYList[z+2][x];
                }
            } else {                        
                if (zSwitch) {
                    zVal = z + 2.0f;
                    randY = randYList[z+2][x];
                } else {
                    zVal = z;
                    randY = randYList[z][x];
                }
            }   

            // set up the currentVert within the currentTri so that we can use it for computing normals.
            Vert currentVert = currentTri.triVerts[triPointIndex];
            currentVert.x = xVal;
            currentVert.y = randY;
            currentVert.z = zVal;
            triPointIndex++;

            if (triPointIndex == 3) {
                triList.add(currentTri);
                Triangle nextTri = new Triangle();

                Vector3f normal = new Vector3f();
                float Ux; float Uy; float Uz;
                float Vx; float Vy; float Vz;

                if (xSwitch) {
                    if (triList.indexOf(currentTri) % 2 == 0) {
                        Vx = currentTri.triVerts[1].x - currentTri.triVerts[0].x;
                        Vy = currentTri.triVerts[1].y - currentTri.triVerts[0].y;
                        Vz = currentTri.triVerts[1].z - currentTri.triVerts[0].z;

                        Ux = currentTri.triVerts[2].x - currentTri.triVerts[0].x;
                        Uy = currentTri.triVerts[2].y - currentTri.triVerts[0].y;
                        Uz = currentTri.triVerts[2].z - currentTri.triVerts[0].z;               
                    } else {
                        Ux = currentTri.triVerts[1].x - currentTri.triVerts[0].x;
                        Uy = currentTri.triVerts[1].y - currentTri.triVerts[0].y;
                        Uz = currentTri.triVerts[1].z - currentTri.triVerts[0].z;

                        Vx = currentTri.triVerts[2].x - currentTri.triVerts[0].x;
                        Vy = currentTri.triVerts[2].y - currentTri.triVerts[0].y;
                        Vz = currentTri.triVerts[2].z - currentTri.triVerts[0].z;   
                    }
                } else {
                    if (triList.indexOf(currentTri) % 2 == 0) {
                        Ux = currentTri.triVerts[1].x - currentTri.triVerts[0].x;
                        Uy = currentTri.triVerts[1].y - currentTri.triVerts[0].y;
                        Uz = currentTri.triVerts[1].z - currentTri.triVerts[0].z;

                        Vx = currentTri.triVerts[2].x - currentTri.triVerts[0].x;
                        Vy = currentTri.triVerts[2].y - currentTri.triVerts[0].y;
                        Vz = currentTri.triVerts[2].z - currentTri.triVerts[0].z;   
                    } else {
                        Vx = currentTri.triVerts[1].x - currentTri.triVerts[0].x;
                        Vy = currentTri.triVerts[1].y - currentTri.triVerts[0].y;
                        Vz = currentTri.triVerts[1].z - currentTri.triVerts[0].z;

                        Ux = currentTri.triVerts[2].x - currentTri.triVerts[0].x;
                        Uy = currentTri.triVerts[2].y - currentTri.triVerts[0].y;
                        Uz = currentTri.triVerts[2].z - currentTri.triVerts[0].z;
                    }
                }

                normal.x = (Uy * Vz) - (Uz * Vy);
                normal.y = (Uz * Vx) - (Ux * Vz);
                normal.z = (Ux * Vy) - (Uy * Vx);

                GL11.glNormal3f(normal.x, normal.y, normal.z);

                nextTri.triVerts[0] = currentTri.triVerts[1];
                nextTri.triVerts[1] = currentTri.triVerts[2];
                currentTri = nextTri;

                triPointIndex = 2;
            } // close triPointIndex == 3 
            GL11.glVertex3f(xVal, randY, zVal);
        } // close x loop
        GL11.glEnd();
    } // close z loop
    GL11.glDisable(GL11.GL_POLYGON_OFFSET_LINE);

} 
公共无效行(){
GL11.GL3F(0.0f,0.0f,0.0f);
GL11.glPolygonMode(GL11.GL\u前和后,GL11.GL\u线);
三角形currentTri=新三角形();
List triList=new ArrayList();
布尔值xSwitch=false;

对于(int z=0;zAre您是否意识到在执行此操作时正在泄漏多边形模式?当函数启动时,您将其更改为
GL_LINE
,并且在返回之前从未将其设置为任何其他值。这些错误的线条可能是调用此函数后绘制的结果。也可能是由于考虑到你的原始类型的退化三角形是<代码> GLY-TangangLeLange……你可以考虑使用<代码> GLYPosio绘制你的多边形,以查看模式到底是怎么回事。谢谢你,我用GLPoPoT像你建议的那样尝试,并且同样的外观发生了,但是点随机弹出。ean by“退化三角形导致条带重置”?嗯,
GL\u TRIANGLE\u strip
是一个连接的基本体。也就是说,它共享顶点。通常,如果使用此基本体模式绘制一组顶点,它们都会连接。但是,如果您创建一个三角形面积为零的情况(退化),其效果是,您指定的下一个顶点将不会连接到条带。有意这样做时,称为“原始重新启动”。无意这样做时,通常称为随机噪声;)如果您使用的是顶点数组,一个常见的原因是绘制的元素比数组存储的元素多。但是,您没有使用顶点数组。因此,如果这就是问题所在,您的循环将受到谴责。该循环有太多分支,我不想在不运行代码的情况下进行调试。但我怀疑您可能已经处理了一个案例ectly和/或可能插入了一个或多个超出您需要的点。您是否尝试过使用普通的旧三角形列表(
GL\u TRIANGLES
)绘制此列表,以排除条带计算中的任何错误?