Click here to Skip to main content
16,017,502 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
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

Java
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);

//        if (durum == 0) {
//   
//            gl.glBindTexture(GL.GL_TEXTURE_2D, 13);
//            gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
//            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
//            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);
//        } else {
//          
//        }
        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?
Posted
Comments
Sergey Alexandrovich Kryukov 10-Mar-12 18:52pm    
Not clear why can't you.
--SA
TorstenH. 12-Mar-12 2:31am    
...and not clear what you are doing - that looks like a bit more than just a background image and some painting.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900