Hi! I’m currently trying to port a C# application to Java, and in this app is used OpenGL.
In the C# app was used OpenTK, while in the Java port I chose JOGL.
The problem comes when the program has to load textures. Java has no unsigned byte types, and the texture has to be loaded from a byte[] array.
This is the piece of code which is causing troubles:
for (int i = 0; i < model.model.mdlData[0].material.material.length; i++) {
BMD0.Model.ModelData.Material.MatDef mat = (BMD0.Model.ModelData.Material.MatDef) model.model.mdlData[0].material.material[i];
ImageData tmp_tex = Nsbtx.getTexture(tex, mat.texID, mat.palID).getImageData();
gl.glBindTexture(GL2.GL_TEXTURE_2D, texturesID.get(i));
ByteBuffer tmp_tex_data = ByteBuffer.allocate(tmp_tex.height * tmp_tex.width * 4);
PaletteData pal = tmp_tex.palette;
for (int h = 0; h < tmp_tex.height; h++) {
for (int w = 0; w < tmp_tex.width; w++) {
tmp_tex_data.put((byte) (pal.getRGB(tmp_tex.getPixel(w, h)).red & 0xff));
tmp_tex_data.put((byte) (pal.getRGB(tmp_tex.getPixel(w, h)).green & 0xff));
tmp_tex_data.put((byte) (pal.getRGB(tmp_tex.getPixel(w, h)).blue & 0xff));
tmp_tex_data.put((byte) (tmp_tex.getAlpha(w, h) & 0xff));
}
}
tmp_tex_data.flip();
gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_RGBA, tmp_tex.width, tmp_tex.height, 0, GL2.GL_RGBA, GL2.GL_UNSIGNED_BYTE, tmp_tex_data);
texturesGL.put(i, texturesID.get(i));
}
The texture is loaded from an SWT’s ImageData class, and tranformed into a RGBA array. In the C# version textures are loaded flawlessly, in the Java one some texture are loaded, some other no (or the colors are not correct). In fact, I’ve debugged the application and found that when I convert RGBA integers to byte the signs are not correct and so the number…
Here are a screenshot showing messed up values during debug and a screenshot showing difference in texture rendering respectively between Java and C#::
[ATTACH=CONFIG]1237[/ATTACH]
[ATTACH=CONFIG]1238[/ATTACH]
How can I solve this? I’m not an expert, this is one of my first program with opengl, I would like to understand how this process works…
EDIT: Here is the link showing the full image of the debugging (this one has been compressed):
h ttp://i.imgur.com/Q5Jc0Gn.png