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.