Question

I have the following functions:

private void clearScreen(int color)
{
    fOffscreenImage.eraseColor(color);
}

private void fillRect(int x, int y, int width, int height, int color)
{
    for(;x<width;x++)
    {
        for(;y<height;y++)
        {
            buffer[x+y*PROJECTIONPLANEWIDTH] = color;
        }
    }
}

private void drawBuffer()
{
    fOffscreenImage.setPixels(buffer,0,PROJECTIONPLANEWIDTH,0,0,PROJECTIONPLANEWIDTH,PROJECTIONPLANEHEIGHT);
}

Both functions draw to a bitmap, first is by eraseColor, which works fine, and second is by setPixels, which always returns black. I'm writing the image to a quad displayed with OpenGL. As color input I tried default colors (Color.BLUE) and Color.argb. getPixel does return the correct output of the colors in question.

A by pixel call to setPixel would not work either, it would ignore the job.

I'm tried with Android 2.1 and 2.3.

Any suggestions on this would be great..

Was it helpful?

Solution 3

private void fillRect(int x, int y, int width, int height, int color)
{
    width += x;
    height += y;
    for(;x<width;x++)
    {
        for(;y<height;y++)
        {
            buffer[x+y*PROJECTIONPLANEWIDTH] = color;
        }
    }
}

should be

private void fillRect(int x, int y, int width, int height, int color)
{
    width += x;
    height += y;
    for(int y2 = y;y2<height;y2++)
    {
        for(int x2 = x;x2<width;x2++)
        {
            buffer[x2+y2*PROJECTIONPLANEWIDTH] = color;
        }
    }
}

OTHER TIPS

I replaced part of the raycaster with the following fillRect code, and it shows white lines on the appropriate places now! Now just to find out other colors as well :)

private void fillRect(int x, int y, int width, int height, int color)
{
    width += x;
    height += y;
    for(;x<width;x++)
    {
        for(;y<height;y++)
        {
            if (x+y*PROJECTIONPLANEWIDTH < PROJECTIONPLANEHEIGHT*PROJECTIONPLANEWIDTH)
                buffer[x+y*PROJECTIONPLANEWIDTH] = color;
        }
    }
}

I fixed this by not using a setPixel, but instead using canvas to draw to the bitmap. However it's dead slow..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top