My question about jogl. I put image on canvas. But i can't change polygons color when i drawing polygon also while there was no background image, set the color of the polygon.
Image code
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL.GL_BLEND);
BufferedImage bufferedImage = null;
int w = 0;
int h = 0;
try {
bufferedImage = ImageIO.read(OpenGLFuncition.class.getResource("kibris.png"));
w = bufferedImage.getWidth();
h = bufferedImage.getHeight();
} catch (IOException ex) {
}
WritableRaster raster =
Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
w,
h,
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 dukeImg =
new BufferedImage(colorModel,
raster,
false,
null);
Graphics2D g = dukeImg.createGraphics();
g.drawImage(bufferedImage, null, null);
DataBufferByte dukeBuf =
(DataBufferByte) raster.getDataBuffer();
byte[] dukeRGBA = dukeBuf.getData();
ByteBuffer bb = ByteBuffer.wrap(dukeRGBA);
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.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, w, h, 0, GL.GL_RGBA,
GL.GL_UNSIGNED_BYTE, bb);
int left = 0;
int top = 0;
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glBindTexture(GL.GL_TEXTURE_2D, 13);
gl.glBegin(GL.GL_POLYGON);
gl.glTexCoord2d(0, 0);
gl.glVertex2d(left, top);
gl.glTexCoord2d(1, 0);
gl.glVertex2d(left + w, top);
gl.glTexCoord2d(1, 1);
gl.glVertex2d(left + w, top + h);
gl.glTexCoord2d(0, 1);
gl.glVertex2d(left, top + h);
gl.glEnd();
Is there another way to put pictures to canvas?