Binary texture mapping

Hello JOGL users!

I have problems with monochrome (1-bit) textures.
My question is: how to load it fast into GPU memory and use it without reformatting it to grayscale (or RGB) with CPU?
I need it because I’m developing earth map viewer and a lot of maps in large scales are monochome (1-bit, black & white) images.
I’ve looked into JOGL TextureData source code and I saw that BufferedImage with image type of TYPE_BYTE_BINARY is reformatted to TYPE_CUSTOM with RGB color palette. This is very slow operation. Loading 4096x4096 monochrome image takes 8 seconds. The same image in grayscale loads in 1,5 sec.
I’ve experimented with GL_COLOR_INDEX pixel format and GL_BITMAP pixel type operators with glTexImage2D, but all tests have failed.
I’ve started to add some code to Texture.java and it also gave me nothig. This is a piece of the code:


int[] map = new int[256];
IntBuffer palette = IntBuffer.allocate(256);
 for(int i=0; i<map.length; i++) {
  if(i<128)
     map[i] = 0;
  else 
     map[i] = 255;
 }
palette.put(map);
palette.rewind();

gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, GL.GL_TRUE);
gl.glPixelStorei(GL.GL_UNPACK_ROW_LENGTH, data.getWidth());
gl.glPixelTransferi(GL.GL_MAP_COLOR, GL.GL_TRUE); 
gl.glPixelMapuiv(GL.GL_PIXEL_MAP_I_TO_R, 256, palette);
gl.glTexImage2D(newTarget, 0, GL.GL_LUMINANCE,
                texWidth, texHeight, 0,
                data.getPixelFormat(), data.getPixelType(), null);
updateSubImageImpl(data, newTarget, 0, 0, 0);
gl.glPixelTransferi(GL.GL_MAP_COLOR, GL.GL_FALSE); 
System.out.println(gl.glGetError());

The result is a completly black texture in OpenGL window. ???

As I mentioned above, my BufferedImage type is TYPE_BYTE_BINARY. data.getPixelFormat() returns GL.GL_COLOR_INDEX and data.getPixelType() returns GL.GL_BITMAP. Pixel alignment is set to 1. gl.glGetError() returns 0.

I didn’t found any useful things in Google. OpenGL docs also don’t explain this issue.
I’ve been sitting with this for days, so please help me!!!

Greetings
Latek

I would suggest you look into trying to add a GL_BITMAP code path to the TextureIO classes. If you can do this and would be willing to contribute your code we’ll be glad to incorporate it into the standard distribution. If you don’t have time then you can feel free to file an RFE (including a test image you want to be able to render) though I have to warn you that it is not likely we are going to have time to add this in the near future. If someone else from the community could pitch in here as well that would be great.

FYI, I am loosely affiliated with another project in the same domain and they have never indicated that they needed this support. All of the imagery they display is either full color (DXTn compressed) or, I believe, grayscale.

Thanks for reply Ken.

I would be glad if I could add this functionality to Texture classes and I have time to do it.
I’m interested in JOGL for about a year and everything I’ve needed I’ve found in JOGL or OpenGL forums and documentation.
But this problem is different. I didn’t find any comprehensive tutorial nor code samples about how to manage monochrome textures in OpenGL - especially using JOGL.
I’m using JOGL to create a map tool for GIS system (as an offscreen map server that glues map tiles and shows it as a flat layer in GIS system). The problem is that the most of map data is in Intergraph CIT (binary images compressed with CCITT4 algorithm) and monochrome TIFF format.
I want to use GL_BITMAP in texture mapping of map tiles because I belive it would be the fastest way to show the map to the GIS user.

The code sample I’ve posted above reads the monochrome 4096x4096 texture in 0,8 sec, but it’s not working (black textrure appears).

Unfortunately I’m stuck with it and need some help form OpenGL/JOGL masters :wink:

Greetings
Latek

I did some searching and agree with you that it seems to be tricky to find examples of GL_BITMAP usage on the web. However the documentation of glTexImage2D with GL_BITMAP image types is pretty clear and I don’t think it should be that hard to get it working. I would recommend you start by making a very simple bitmap texture by hand (shifting in bits into one or more bytes in a ByteBuffer or similar) and trying to write the appropriate OpenGL code to get it loaded as a texture and displayed on the screen. You’ll need to pay attention to things like the GL_UNPACK_LSB_FIRST state and the GL_UNPACK_ALIGNMENT state. Once you have that we can work on adding this code path to the TextureIO classes.

It was simpler than i thought:


      	float[] map = new float[2];
        FloatBuffer palette = FloatBuffer.allocate(2);
        map[0] = 0;
        map[1] = 255;
        palette.put(map);
        palette.rewind();
        gl.glPixelTransferi(GL.GL_MAP_COLOR, GL.GL_TRUE); 
  	gl.glPixelMapfv(GL.GL_PIXEL_MAP_I_TO_R, 2, palette);

Thanks for replies!