New to JOGL - Texture not displaying on Linux and Mac OSes?

I’m new to JOGL and Java (at least, deployment of Java applications), so it’s possible I’m missing something really obvious here, but this is the problem I’m having:

I took the code from some of the early NeHe tutorials and modified a few things so it simply loads a texture and displays it within an orthogonal display. Having never done anything multiplatform before (I used to program in C# with DirectX), before I did anything else, especially because the NeHe code should definitely work for everyone, I wanted to make sure other people could run it. Several friends using Windows, Linux, and Mac OSes tried it for me; it works perfectly on Windows, and on the computer of one of the people using a Mac. For the other people, which included one Mac user and several Linux users, it apparently loaded properly, except that the texture didn’t display. Instead, the only thing rendered was a white box of the same size as the quad (i.e., it’s like I hadn’t used a textured quad at all, but had just rendered a white quad with the same position coordinates for the vertices).

I’m not really even sure if this is a problem with JOGL displaying the texture or Java loading the image in the first place. If it’s a problem with loading the image, I can say that the image is at least being found, because when I first asked someone using Linux to test it, I hadn’t taken the case-sensitive file system into account, causing runtime errors because the file wasn’t found. Beyond that, I’m not sure. Normally I would try to debug this myself, but I don’t have access to a computer with a Mac or Linux OS, so I’m hoping someone has some idea of what might be going on.

I’m not sure how much of this is relevant, but there’s more information below:

-The image being loaded is a .PNG with transparency. There is no partial transparency (although I think my code allows for it); the pixels are either completely opaque or transparent. The dimensions are 30 x 34, so it’s not a power of 2, but I believe that doesn’t matter in JOGL. Again, it displays perfectly on Windows and apparently (some) Macs, so I’m not sure why it doesn’t work on Linux and other Macs.

-This is using code from the NeHe tutorials, meaning that all of the image loading is handled with the included TextureReader class (the first time it appears, if there was more than one version).

-The following line of code is used to tell OpenGL that “img” is a texture with an alpha channel:

gl.glTexImage2D(target, 0, GL.GL_RGBA, img.getWidth(), img.getHeight(), 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, img.getPixels());

It’s exactly the same as the code in the early NeHe tutorial except for the Alpha part. To be honest, I’m not sure why I’m supposed to put in GL.GL_* twice, so me changing them both to RGBA might be the problem (although it still works on Windows).

-The following code is the relevant portions from when OpenGL is being initialized:

gl.glShadeModel(GL.GL_SMOOTH);
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL.GL_BLEND);
texture = genTexture(gl); // texture is just an integer, and the method genTexture simply calls
                          // glGenTextures for one new texture and returns the texture name.
gl.glBindTexture(GL.GL_TEXTURE_2D, texture);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);

If anyone wants to see the full body of the code, just tell me. It’s messy because I’ve been commenting a lot of lines of code out, and adding a lot of lines from other NeHe lessons and online tutorials to test how different things work, but I’ve still only modified one or two classes from the tutorial. This is all the code that I thought was relevant, but I don’t really know about OpenGL yet to be sure.

jogl might not require there to be npot textures since the current opengl spec doesn’t require it, but that doesn’t mean that your friends’ cards are capable of doing npot textures. If they have older computers then it’s more likely that they only support opengl up to 1.4 or 1.5, which I believe doesn’t have standardized npot texturing.

For npot support, you have to check for GL_ARB_texture_non_power_of_two or OpenGL version 2.0 or greater.

Thanks for the help. It’s now working for Macs, but still doesn’t work for Linux.

On Linux, it’s apparently stopped displaying the quad altogether, even the “white box” thing it was doing before. I take this to mean that the power of 2 issue was a problem for Linux too, although I’m not sure why nothing’s rendering now.

Because the greater dimensions (64 x 64) mean that most of the image itself is now empty transparent space, I assumed the image might, for example, have been loading upside down or something, so I tried changing the texture coordinates from the top to the bottom of the image, but that apparently didn’t change anything. Any ideas on what still might be going wrong?

Have you considered using the com.sun.opengl.util.texture classes? They were intended to save people from continually reinventing the wheel in texture loading, and to abstract away details like what non-power-of-two extension is in use. There are demos illustrating use in the demos.texture package in the jogl-demos workspace.

I actually wasn’t even aware the NeHe tutorials didn’t use the built-in Texture class. But I switched over and it seems to be working now. Actually, if it’s supposed to be making non-power-of-two textures work on computers that can’t use them by making a new texture with the correct dimensions, that doesn’t seem to be work properly - I still need the actual image file to have power-of-two dimensions to work. That’s not really big a deal, though.

I just have one more question. The program still doesn’t work for at least one person using Linux, and I think I can better explain the problem now: every value for the texture appears to be set to 0. I can’t say that for sure, but when loading any .PNG with an alpha channel, no texture is displayed (so I’d assume the alpha channel is set to 0), and when loading any .PNG without an alpha channel, a completely black texture is displayed (so the RGB channels must be set to 0). I don’t think this is really a JOGL issue at this point, but just so I can figure out how to help fix it, does anyone know what might be causing that? I’d assume this is a driver issue, or something about the version of OpenGL they’re using? It’s strange behavior because the other aspects of OpenGL (rotation, scaling, etc.) seem to be working just fine. The texture just won’t display for some reason (or at least, gets all of its values set to 0 upon being loaded into OpenGL).

Either way, thanks for all the help. I can pretty much stop worrying about compatibility now and get back to just learning how to use JOGL and Swing. :slight_smile:

This should be working though I haven’t tested it recently. If you can prove that it isn’t with a test case then please file a bug with the Issue Tracker on the JOGL home page. Note that you need to use Texture.getImageTexCoords(), etc.

I can’t think of what would be causing this. Once the TextureIO classes get the bits from the ImageIO subsystem (which is used to load PNG images) then everything should work identically well for all file formats. If you can provide a test case then again please file a bug.

Small note, as far I can tell, on the MacOS X front, OpenGL 2.0 is only supported by MacOS X 10.4.3 and above. This is from checking some forum posts, but I couldn’t seem to find any official information to confirm this.