I have a problem with texturing on using JOGL on Linux. Each time I call gl.glTexImage2D, I get the following exception.
Exception in thread "main" java.lang.NullPointerException
at com.sun.opengl.impl.x11.X11GLContext.getPlatformExtensionsString(X11GLContext.java:202)
at com.sun.opengl.impl.FunctionAvailabilityCache.initAvailableExtensions(FunctionAvailabilityCache.java:116)
at com.sun.opengl.impl.FunctionAvailabilityCache.isExtensionAvailable(FunctionAvailabilityCache.java:104)
at com.sun.opengl.impl.GLContextImpl.isExtensionAvailable(GLContextImpl.java:244)
at com.sun.opengl.impl.x11.X11GLContext.isExtensionAvailable(X11GLContext.java:247)
at com.sun.opengl.impl.GLImpl.isExtensionAvailable(GLImpl.java:27703)
at com.sun.opengl.impl.GLImpl.checkBufferObject(GLImpl.java:27834)
at com.sun.opengl.impl.GLImpl.checkUnpackPBODisabled(GLImpl.java:27854)
at com.sun.opengl.impl.GLImpl.glTexImage2D(GLImpl.java:19435)
at swt.views.hmiPrimitives.HMIText.drawPrimitive(HMIText.java:107)
Here is the code that creates the texture:
WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, myTextureWidth, myTextureHeight, 4, null);
ComponentColorModel colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8, 8, 8 }, true, false,
ComponentColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);
BufferedImage image = new BufferedImage(colorModel, raster, false, null);
Graphics2D g2d = image.createGraphics();
g2d.setPaint(Color.WHITE);
g2d.setBackground(new Color(0f, 0f, 1f, 0.5f));
g2d.clearRect(0, 0, image.getWidth(), image.getHeight());
g2d.setFont(myFont);
g2d.drawString(myText, 0, g2d.getFontMetrics().getAscent());
DataBufferByte buffer = (DataBufferByte) image.getData().getDataBuffer();
myImageData = ByteBuffer.allocateDirect(buffer.getData().length);
myImageData.order(ByteOrder.nativeOrder());
myImageData.put(buffer.getData());
When executing this code, the exception is thrown:
gl.glEnable(GL.GL_TEXTURE_2D);
if (myTexId == 0) {
int[] tmpTexId = new int[1];
gl.glGenTextures(1, tmpTexId, 0);
myTexId = tmpTexId[0];
}
myImageData.rewind();
gl.glBindTexture(GL.GL_TEXTURE_2D, myTexId);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, myTextureWidth, myTextureHeight, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, myImageData);
The code works fine on Windows.
Thanks for your help!