Texture Borders in JOGL

Forewarning: I’m pretty new to OpenGL and JOGL

I’m trying to institute Texture Borders using JOGL to allow me to display large images as a set of subtiles without artifacts at the seams of the textures. Before trying to do Texture Borders, I tried to use GL_CLAMP_TO_EDGE, which certainly improved the appearance of the borders, but they are still quite noticable when zoomed enough.

I do not want to use mipmapping because we have our own set of progressively smaller tiles.

I tried to implement texture borders as follows:
I increased each individual tiled image from 256x256 to 258x258 by including a 1 pixel border from the adjacent tile. The tiled image was loaded using TextureIO as follows:

First the images were prepared as a buffered image, then loaded into texturedata:
theData = TextureIO.newTextureData(bufImg, false);
theData.setBorder(1); // 1 pixel border

Then later loaded in as a texture when needed:
Texture tex = TextureIO.newTexture(theData);

However, as long as setBorder(1) is called, the textures show up blank. No error is thrown, the texture is not displayed. Thinking that it might be because the texture is no longer a power of two (even though my card supports this)… I tried a 256x256 image with the same result–nothing drawn.

I then tried to bypass TextureIO’s last step and try to load the texture myself:

gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, theData.getInternalFormat(),
258, 258, 0,
theData.getPixelFormat(), theData.getPixelType(), theData.getBuffer());

In this case, I get a much different problem: It throws this error:

Caused by: java.lang.IndexOutOfBoundsException: Required 266256 remaining bytes in buffer, only had 265224
at com.sun.gluegen.runtime.BufferFactory.rangeCheckBytes(BufferFactory.java:274)
at com.sun.opengl.impl.GLImpl.glTexImage2D(GLImpl.java:19579)

However, when I again remove the setBorder(1), it displays again–without a border.

Do I not understand how texture borders are supposed to work?

(FYI I am using an Nvidia 6800 under Windows using the latest JOGL release)

In general, it’s probably best to stay away from using texture border functionality in OpenGL. On lots of modern boards you will end up going through a slow path in drivers, and on some ATI boards I’ve found that textures with non-zero borders are completely broken (render as black or pathologically slow). I assume that the visible seams you are seeing are due to the fact that you’re using GL_LINEAR filtering when tiling the scaled images. I’m not so sure that using texture borders would even help in this case, but perhaps you could achieve the same effect by using a 256x256 texture (no border) and using the middle 254x254, then replicating the adjacent pixels at the edge of the texture and modifying your texture coordinates accordingly? We’ve used similar techniques in Java2D and the results are usually reasonable.

Chris

Thanks for the reply.

Yes, you’re correct, I am using GL_LINEAR. It does appear fine using GL_NEAREST, but this is an imaging application where image quality is important and GL_NEAREST looks terrible.

As far as your suggestion, I have considered this technique, however it has a real problem in our application. Namely, that the surfaces where the textures are mapped (and the textures themselves) sometimes are partially transparent. Therefore, the overlapping portions will appear to be less transparent than the rest of the tiles. This might end up looking worse than having the noticable seams.