Hi again,
last time you helped me. So i need solve this problem if it is possible. When i you load texture and use blending with GLCanvas everything work correctly, but when i use GLJPanel blending dont work. Thank you for trying help. Here is source code : import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; import com.jogamp.opengl.*; import com.jogamp.opengl.awt.*; import com.jogamp.opengl.glu.*; import com.jogamp.opengl.util.FPSAnimator; import com.jogamp.opengl.util.texture.*; import com.jogamp.opengl.util.texture.awt.AWTTextureIO; import static com.jogamp.opengl.GL.*; import static com.jogamp.opengl.GL2.*; class GrafSceneX03 implements GLEventListener { private GLU globalGlu; private float obrazekVrch, obrazekSpodek, obrazekVlevo, obrazekVpravo; private Texture obrazek; private boolean blending; private float uhelKrychleX = 0.0f; private float uhelKrychleY = 0.0f; private float rychostKrychleX = 0.1f; private float rychostKrychleY = 0.1f; private float rychostKrychleXZmena = 0.4f; private float rychostKrychleYZmena = 0.4f; private void ctverecVpredu(GL2 mistniGL) { mistniGL.glBegin(GL_QUADS); mistniGL.glNormal3f(0.0f, 0.0f, 1.0f); mistniGL.glTexCoord2f(obrazekVlevo, obrazekVrch); mistniGL.glVertex3f(-1.0f, 1.0f, -1.0f); mistniGL.glTexCoord2f(obrazekVpravo, obrazekVrch); mistniGL.glVertex3f(1.0f, 1.0f, -1.0f); mistniGL.glTexCoord2f(obrazekVpravo, obrazekSpodek); mistniGL.glVertex3f(1.0f, -1.0f, -1.0f); mistniGL.glTexCoord2f(obrazekVlevo, obrazekSpodek); mistniGL.glVertex3f(-1.0f, -1.0f, -1.0f); mistniGL.glEnd(); } private void ctverecVzadu(GL2 mistniGL) { mistniGL.glBegin(GL_QUADS); mistniGL.glNormal3f(0.0f, 0.0f, 1.0f); mistniGL.glTexCoord2f(obrazekVlevo, obrazekVrch); mistniGL.glVertex3f(-1.0f, 1.0f, 1.0f); mistniGL.glTexCoord2f(obrazekVpravo, obrazekVrch); mistniGL.glVertex3f(1.0f, 1.0f, 1.0f); mistniGL.glTexCoord2f(obrazekVpravo, obrazekSpodek); mistniGL.glVertex3f(1.0f, -1.0f, 1.0f); mistniGL.glTexCoord2f(obrazekVlevo, obrazekSpodek); mistniGL.glVertex3f(-1.0f, -1.0f, 1.0f); mistniGL.glEnd(); } public void display(GLAutoDrawable drawable) { GL2 mistniGL = drawable.getGL().getGL2(); mistniGL.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mistniGL.glLoadIdentity(); mistniGL.glTranslatef(0.0F, 0.0F, -5.5F); obrazek.enable(mistniGL); obrazek.bind(mistniGL); mistniGL.glRotatef(uhelKrychleX, 1.0f, 0.0f, 0.0f); mistniGL.glRotatef(uhelKrychleY, 0.0f, 1.0f, 0.0f); // DISPLAY PART OF BLENDING if (blending) { mistniGL.glEnable(GL_BLEND); mistniGL.glDisable(GL_DEPTH_TEST); } else { mistniGL.glDisable(GL_BLEND); mistniGL.glEnable(GL_DEPTH_TEST); } ctverecVpredu(mistniGL); ctverecVzadu(mistniGL); mistniGL.glFlush(); uhelKrychleX = uhelKrychleX + rychostKrychleX; uhelKrychleY = uhelKrychleY + rychostKrychleY; } public void init(GLAutoDrawable drawable) { GL2 mistniGL = drawable.getGL().getGL2(); globalGlu = new GLU(); mistniGL.glClearColor(0.0F, 0.0F, 0.0F, 0.0F); mistniGL.glClearDepthf(1.0f); mistniGL.glEnable(GL_DEPTH_TEST); mistniGL.glDepthFunc(GL_LEQUAL); mistniGL.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); mistniGL.glShadeModel(GL_SMOOTH); ((Component) drawable).addKeyListener(new StiskKlavesy()); try { BufferedImage obr = ImageIO.read(new File("images/crate.png")); obrazek = AWTTextureIO.newTexture(GLProfile.getDefault(), obr, false); mistniGL.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); mistniGL.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); TextureCoords textureCoords = obrazek.getImageTexCoords(); obrazekVrch = textureCoords.top(); obrazekSpodek = textureCoords.bottom(); obrazekVlevo = textureCoords.left(); obrazekVpravo = textureCoords.right(); } catch (GLException e) { System.out.println("Pri nacitani se nepodarilo zobrazit OpenGL"); e.printStackTrace(); } catch (IOException e) { System.out.println("Nepodarilo se nacist soubor"); e.printStackTrace(); } // BLENDING SETTINGS mistniGL.glColor4f(1.0f, 1.0f, 1.0f, 0.5f); mistniGL.glBlendFunc(GL_SRC_ALPHA,GL_ONE); mistniGL.glBlendEquation(GL_FUNC_ADD); mistniGL.glEnable(GL_BLEND); mistniGL.glDisable(GL_DEPTH_TEST); blending = false; } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2 mistniGL = drawable.getGL().getGL2(); if (height <= 0) height = 1; float f = (float) width / height; mistniGL.glViewport(0, 0, width, height); mistniGL.glMatrixMode(GL_PROJECTION); mistniGL.glLoadIdentity(); globalGlu.gluPerspective(45.0D, f, 1.0D, 20.0D); mistniGL.glMatrixMode(GL_MODELVIEW); mistniGL.glLoadIdentity(); } public void dispose(GLAutoDrawable drawable) {} class StiskKlavesy extends KeyAdapter { public void keyPressed(KeyEvent paramKeyEvent) { if (paramKeyEvent.getKeyCode() == 27) System.exit(0); // ESC = 27 --> EXIT int stisk = paramKeyEvent.getKeyCode(); switch (stisk) { case KeyEvent.VK_B: blending = !blending; break; case KeyEvent.VK_UP: rychostKrychleX -= rychostKrychleXZmena; break; case KeyEvent.VK_DOWN: rychostKrychleX += rychostKrychleXZmena; break; case KeyEvent.VK_LEFT: rychostKrychleY -= rychostKrychleYZmena; break; case KeyEvent.VK_RIGHT: rychostKrychleY += rychostKrychleYZmena; break; } } } } public class X03_BlendingGLCanvas extends JFrame { private static final long serialVersionUID = -3710917792113122957L; private void nastaveniKonstruktoruOkna() { super.setTitle("Texture rotate with arrows, press B set blending, ESC Exit"); this.setSize(800, 600); this.setLocation(200,200); this.getContentPane().setLayout(new BorderLayout()); JFrame.setDefaultLookAndFeelDecorated(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } X03_BlendingGLCanvas() { nastaveniKonstruktoruOkna(); /* // OPTION 1 - GLCANVAS EVERYTHING WORK final GLProfile profile = GLProfile.get(GLProfile.GL2); GLCapabilities capabilities = new GLCapabilities(profile); GLCanvas scena = new GLCanvas(capabilities); final FPSAnimator animace = new FPSAnimator(scena,60, true); animace.start(); this.getContentPane().add(scena); GrafSceneX03 grafika = new GrafSceneX03(); scena.addGLEventListener(grafika); scena.setFocusable(true); */ // OPTION 2 - GLJPANEL - BLENDING NOT WORKING GLJPanel scena = new GLJPanel(); final FPSAnimator animace = new FPSAnimator(scena,60,true); animace.start(); this.getContentPane().add(scena); GrafSceneX03 grafika = new GrafSceneX03(); scena.addGLEventListener(grafika); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new X03_BlendingGLCanvas().setVisible(true); } }); } } GLCanvas screen : GLJPnanel screen : |
Administrator
|
Hello
I suspect that it's a known limitation, I'll look at that tomorrow. Some states are lost when using the GLJPanel.
Julien Gouesse | Personal blog | Website
|
Free forum by Nabble | Edit this page |