Need help rendering pixels in java using JOGL Library

Viewed 11

Hello all i'm trying to render pixels to the screen using this method and i get a null pointer exception. Any help would be greatly appreciated! thanks! The screen size is 1920 x 1080 and i'm trying to render chunks of 64.


    Exception in thread "main" java.lang.NullPointerException
        at Screen.render(Screen.java:49)
        at Game.render(Game.java:169)
        at Game.run1(Game.java:147)
        at Game.<init>(Game.java:110)
        at Main.main(Main.java:18)
this is the line of code with the problem
int color = tileIndex * 4 + sheet.pixels[sheetPixel++];

    public void render(int[] pixels, int offset, int row){
        for(int yTile = yOffset>> 64 ;yTile <= (yOffset+height) >>64; yTile++){
            int yMin = yTile * 256 - yOffset;
            int yMax = yMin + 256;
            if(yMin <0) yMin = 0;
            if(yMax > height) yMax = height;
            
            for(int xTile = xOffset >>64; xTile <= (xOffset + width ) >> 64 ; xTile ++){
                int xMin = xTile * 256 - xOffset;
                int xMax = xMin + 256;
                if(xMin <0) xMin = 0;
                if(xMax > width) xMax = width;
                
                int tileIndex = (xTile & (MAP_WIDTH_MASK)) + (yTile & (MAP_WIDTH_MASK) )*MAP_WIDTH;
                for(int y = yMin; y<yMax; y++){
                    int sheetPixel = ((y+yOffset) &63)* sheet.height + ((xMin+xOffset)&63) * sheet.width;
                    int tilePixel = offset + xMin + y *row;
                    
                    for(int x = xMin; x<xMax; x++){
                        int color = tileIndex * 4 + sheet.pixels[sheetPixel++];
                        pixels[tilePixel++] = colors[color];
                    }
                }
            }
        

}

I think the problem is that sheetpixel isn't iterating in the right scope.

0 Answers
Related