Generating level from bitmap

Hi, I’m new and I’d like to ask about how to generate level from bitmap. I’m aiming at Wolfenstein3D-like game (i.e. no stairs, etc., only flat ground), so I feel like I could keep levels as bitmaps (kinda like Notch did for Catacomb Snatch). Unfortunately Notch’s game is 2D and even if it uses LWJGL (didn’t see sources), it’s most likely pure LWJGL so it’s not applicable for JME.

Every pixel in PNG file would be equivalent of one “3D Tile” (enemy, decoration, collectables, walls, etc.). Generation will be easiest part - I’ve already generated level from 3D array of rgb values (x,y,r/g/b 3D vector [as type]). The problem is how to actually process image into such array (getting value of specified pixels, etc.)

Any help?

@dariuszg-jagielski said:
Any help?

The question doesn't make a ton of sense.. A heightmap from an image is easy, but loading the entire level from it? Why?

Because I can then use Paint as level designer. Also since it’ll be Wolf3d clone, there won’t be any slopes and height changes between parts of same level, so it just makes sense

Explanation in pictures

Basically I’d like to process image like this (x8 for viewer’s convenience, actual image is 9x9);

so it’ll generate level like this (blender mockup):

As you can see green pixel represents cylinder and red ones are represented by cubes. In short - use different color values for representing “3d tiles” in game which when building are aligned in grid on XZ plane.

As I said, actual level generation is easiest part, problem is with getting color values from image.

This is straight Java, nothing to do with jME (unless you want to load it as a texture… which would be a waste of resources since you aren’t displaying it)…

Check out BufferedImage and Raster.

this may or may not help you, I ripped it from some terrain related code I think so you could probably find it in the source somewhere.


Thanks. And sorry for posting noobish questions - I’m still learning, both Java and JME, so you should forgive me ;).

Yay, thanks @thetoucher I was looking for something like that a couple months ago… lol, never quite got to do a bit of research/thinking about it :wink: That’ll be handy!

Hi there,

This is very simple to do.

A while back I did something similar except with my image to jME3 loading I only loaded blocks and set there material color to what ever the image pixel represented.

Here is the code:


public Node load(String mapFile, int waterHeight) {

try {

BatchNode map = new BatchNode("map");

BufferedImage image =;

System.out.println("image = " + image);

int width = image.getWidth();

int height = image.getHeight();

for (int y = 0; y < height; y++) {

for (int x = 0; x < width; x++) {

int color = image.getRGB(x, y);

int red = (color & 0x00ff0000) >> 16;

int green = (color & 0x0000ff00) >> 8;

int blue = color & 0x000000ff;

int alpha = (color >> 24) & 0xff;

//Only paint something if the alpha is not 0

if (alpha != 0) {

Spatial block = null;

block = loadBlock(red, green, blue, alpha);

//If there is a block we need to move it

if (block != null) {

float xPos = (blockSize2) * (x);

float yPos = (blockSize
2) * (height-y);

block.setLocalTranslation(xPos, yPos, 0);







return map;

} catch (IOException ex) {

Logger.getLogger(MapLoader.class.getName()).log(Level.SEVERE, null, ex);


return null;


protected Spatial loadBlock(int red, int green, int blue, int alpha) {

Box b = new Box(Vector3f.ZERO, blockSize, blockSize, blockSize);

Geometry geom = new Geometry("Box", b);

float fRed = ((float)red)/255f;

float fGreen = ((float)green)/255f;

float fBlue = ((float)blue)/255f;

float fAlpha = ((float)alpha)/255f;

Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

mat.setColor("Color", new ColorRGBA(fRed, fGreen, fBlue, fAlpha));


return geom;



1 Like