Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.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 没有正确存储颜色数据_Java_Rendering_Bufferedimage - Fatal编程技术网

Java 没有正确存储颜色数据

Java 没有正确存储颜色数据,java,rendering,bufferedimage,Java,Rendering,Bufferedimage,我正在尝试制作一个渲染系统,其中包含一个深度贴图,其中包含用于处理alpha的常用像素。我的问题是没有正确设置颜色!我曾尝试使用System.out.println进行调试,并测试了各种组件,但没有找到解决方案 变量 处理像素的绘制、设置和清除所涉及的变量有:private int[][]node、private int[]pixels和private arraraylist changedPixels private int[][]节点处理存储像素和处理深度[depth][x+y*width]

我正在尝试制作一个渲染系统,其中包含一个深度贴图,其中包含用于处理alpha的常用像素。我的问题是没有正确设置颜色!我曾尝试使用System.out.println进行调试,并测试了各种组件,但没有找到解决方案

变量 处理像素的绘制、设置和清除所涉及的变量有:
private int[][]node
private int[]pixels
private arraraylist changedPixels

private int[][]节点
处理存储像素和处理深度[depth][x+y*width],然后再传输到缓冲区图像像素。数据设置为清晰的黑色,最低深度为完全可见的黑色

private int[]pixels
是来自缓冲区图像的数据,用于将其更改,它是每次使用的唯一图像!默认情况下,所有数据都是完全可见的黑色

private ArrayList changedPixels
处理上一帧的像素,以便在不需要时不清除整个屏幕,从而帮助提高FPS。默认情况下为空,因为没有从上一帧更改像素

方法 我有几种渲染系统的方法:
setNode(int x,int y,int z,int color,int alpha
drawScreen()
,和
clearScreen()
。我还有一个绘图矩形和sprite函数,通过调用
setNode()
方法添加颜色来处理像素的添加

private void setNode(int x, int y, int z, int color, float alpha)
{
    color = Pixel.getColor(alpha, color);

    if (translate) // Move the pixel to  the correct location
    {
        x -= transX;
        y -= transY;
    }

    if (x < 0 || x >= width || y < 0 || y >= height || alpha <= 0.0f || nodeMap[z][x + y * width] == color) // Check if we need to draw the pixel
        return;

    for (int zz = z + 1; zz < maxDepth; zz++)
        if (Pixel.getAlpha(nodeMap[zz][x + y * width]) >= 1)
            return;

    if (alpha < 1.0f) // If pixel isn't completely opaque, then set it's alpha to the given one
        if (nodeMap[z][x + y * width] != color) // If color isn't equal to the one we supply, change it up correctly
            color = Pixel.getColorBlend(color, nodeMap[z][x + y * width]);

    if (color == Pixel.WHITE) System.out.println("Pixel is white at x: " + x + ", y: " + y);
    nodeMap[z][x + y * width] = color;
}

public void drawScreen()
{
    int color = clearColor;

    for (int x = 0; x < width; x++)
        for (int y = 0; y < height; y++)
        {
            for (int z = maxDepth - 1; z > 0; z--)
            {
                if (Pixel.getAlpha(nodeMap[z][x + y * width]) > 0f)
                    color = Pixel.getColorBlend(color, nodeMap[z][x + y * width]);

                if (Pixel.getAlpha(color) >= 1f)
                    break;
            }

            if (pixels[x + y * width] != color)
            {
                pixels[x + y * width] = color;
                changedPixels.add(x + y * width);
            }
        }
}


public void clearScreen()
{
    for (Integer pixel : changedPixels)
    {
        for (int z = 0; z < maxDepth; z++)
        {
            if (z > 0)
                nodeMap[z][pixel] = clearColor;
            else
                nodeMap[z][pixel] = bgColor;
        }
    }

    changedPixels.clear();
}

public void drawRect(int offX, int offY, int z, int width, int height, int color)
{
    for (int x = 0; x < width; x++)
        for (int y = 0; y < height; y++)
            setNode(x + offX, y + offY, z, color);
}

public static int getColorBlend(int color1, int color2)
{
    float a1 = getAlpha(color1);
    float a2 = getAlpha(color2);

    float a = Math.max(a1, a2);
    float r = ((getRed(color1) * a1) + (getRed(color2) * a2 * (1 - a1))) / a;
    float g = ((getGreen(color1) * a1) + (getGreen(color2) * a2 * (1 - a1))) / a;
    float b = ((getBlue(color1) * a1) + (getBlue(color2) * a2 * (1 - a1))) / a;

    return Pixel.getColor(a, r, g, b);
}
private void集合节点(int x、int y、int z、int color、float alpha)
{
color=Pixel.getColor(alpha,color);
if(translate)//将像素移动到正确的位置
{
x-=transX;
y-=transY;
}
如果(x<0 | | x>=宽度| | y<0 | | y>=高度| |α=1)
返回;
if(alpha<1.0f)//如果像素不是完全不透明的,则将其alpha设置为给定值
if(nodeMap[z][x+y*width]!=color)//如果颜色不等于我们提供的颜色,请正确地将其更改
颜色=像素.getColorBlend(颜色,节点映射[z][x+y*宽度]);
if(color==Pixel.WHITE)System.out.println(“像素在x:+x+,y:+y处为白色”);
节点映射[z][x+y*宽度]=颜色;
}
公共屏幕()
{
int color=clearColor;
对于(int x=0;x0;z--)
{
如果(像素.getAlpha(节点映射[z][x+y*宽度])>0f)
颜色=像素.getColorBlend(颜色,节点映射[z][x+y*宽度]);
如果(像素.getAlpha(颜色)>=1f)
打破
}
如果(像素[x+y*宽度]!=颜色)
{
像素[x+y*宽度]=颜色;
更改像素。添加(x+y*宽度);
}
}
}
公共屏幕()
{
用于(整数像素:更改像素)
{
对于(int z=0;z0)
nodeMap[z][pixel]=clearColor;
其他的
nodeMap[z][pixel]=bgColor;
}
}
changedPixels.clear();
}
公共void drawRect(int-offX、int-offY、int-z、int-width、int-height、int-color)
{
对于(int x=0;x
测试 我目前所做的是初始化渲染系统,并将节点映射和像素映射设置为前面提到的设置。完成后,游戏引擎开始,然后gui按钮中的方法(您可能需要它),但它调用
drawRect(0(x)、0(y)、1(z)、100(宽)、20(高)、pixel.WHITE(颜色))
它的工作原理与我进行的测试相同,以查看它是否正在运行该方法以及它所绘制的像素

问题 总的问题是,屏幕是完全白色的,我不太明白原因!我知道它与alpha混合没有任何关系,它可以很好地工作,因为我将它用于我以前使用的渲染系统版本


感谢您的帮助,很抱歉这是一个很长的问题,我只是想确定您是否有您可能需要的一切帮助我解决这个问题。我确实意识到这不是很有效,但我仍然喜欢这个系统。再次感谢!

主要问题已经解决,但现在似乎出现了一个新问题,像素似乎被保留如果您认为该解决方案对其他人有用,请发布您自己问题的答案。并针对新问题询问新问题。如果没有,请编辑该问题以关注问题所在。:-)