⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shadertestglsl.java

📁 java 3d编程的一些例子源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        initComponents();                // Create the scene and add the Canvas3D to the drawing panel        Canvas3D c = initScene();        drawingPanel.add(c, java.awt.BorderLayout.CENTER);    }            // ----------------------------------------------------------------        /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents    private void initComponents() {        java.awt.GridBagConstraints gridBagConstraints;        densityButtonGroup = new javax.swing.ButtonGroup();        colorButtonGroup = new javax.swing.ButtonGroup();        sceneGraphButtonGroup = new javax.swing.ButtonGroup();        mainPanel = new javax.swing.JPanel();        guiPanel = new javax.swing.JPanel();        densityPanel = new javax.swing.JPanel();        zeroButton = new javax.swing.JRadioButton();        halfButton = new javax.swing.JRadioButton();        fullButton = new javax.swing.JRadioButton();        colorPanel = new javax.swing.JPanel();        goldButton = new javax.swing.JRadioButton();        silverButton = new javax.swing.JRadioButton();        sceneGraphPanel = new javax.swing.JPanel();        DetachButton = new javax.swing.JToggleButton();        AttachButton = new javax.swing.JToggleButton();        replaceSPButton = new javax.swing.JButton();        drawingPanel = new javax.swing.JPanel();        jMenuBar1 = new javax.swing.JMenuBar();        fileMenu = new javax.swing.JMenu();        exitMenuItem = new javax.swing.JMenuItem();        setTitle("Window Title");        addWindowListener(new java.awt.event.WindowAdapter() {            public void windowClosing(java.awt.event.WindowEvent evt) {                exitForm(evt);            }        });        mainPanel.setLayout(new java.awt.BorderLayout());        guiPanel.setLayout(new javax.swing.BoxLayout(guiPanel, javax.swing.BoxLayout.X_AXIS));        guiPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));        densityPanel.setLayout(new java.awt.GridBagLayout());        densityPanel.setBorder(new javax.swing.border.TitledBorder("Density"));        densityButtonGroup.add(zeroButton);        zeroButton.setText("Zero");        zeroButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                zeroButtonActionPerformed(evt);            }        });        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        densityPanel.add(zeroButton, gridBagConstraints);        densityButtonGroup.add(halfButton);        halfButton.setText("Half");        halfButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                halfButtonActionPerformed(evt);            }        });        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 1;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        densityPanel.add(halfButton, gridBagConstraints);        densityButtonGroup.add(fullButton);        fullButton.setSelected(true);        fullButton.setText("Full");        fullButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                fullButtonActionPerformed(evt);            }        });        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 2;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        densityPanel.add(fullButton, gridBagConstraints);        guiPanel.add(densityPanel);        densityPanel.getAccessibleContext().setAccessibleName("ShaderAttributeValue \n");        colorPanel.setLayout(new java.awt.GridBagLayout());        colorPanel.setBorder(new javax.swing.border.TitledBorder("Color"));        colorButtonGroup.add(goldButton);        goldButton.setSelected(true);        goldButton.setText("Gold");        goldButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                goldButtonActionPerformed(evt);            }        });        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        colorPanel.add(goldButton, gridBagConstraints);        colorButtonGroup.add(silverButton);        silverButton.setText("Silver");        silverButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                silverButtonActionPerformed(evt);            }        });        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 1;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        colorPanel.add(silverButton, gridBagConstraints);        guiPanel.add(colorPanel);        sceneGraphPanel.setLayout(new java.awt.GridBagLayout());        sceneGraphPanel.setBorder(new javax.swing.border.TitledBorder("Scene Graph"));        sceneGraphButtonGroup.add(DetachButton);        DetachButton.setSelected(true);        DetachButton.setText("Detach");        DetachButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                DetachButtonActionPerformed(evt);            }        });        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        sceneGraphPanel.add(DetachButton, gridBagConstraints);        sceneGraphButtonGroup.add(AttachButton);        AttachButton.setText("Create");        AttachButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                AttachButtonActionPerformed(evt);            }        });        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 1;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        sceneGraphPanel.add(AttachButton, gridBagConstraints);        replaceSPButton.setText("Replace Shader");        replaceSPButton.setEnabled(false);        replaceSPButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                replaceSPButtonActionPerformed(evt);            }        });        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 2;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        sceneGraphPanel.add(replaceSPButton, gridBagConstraints);        guiPanel.add(sceneGraphPanel);        mainPanel.add(guiPanel, java.awt.BorderLayout.NORTH);        drawingPanel.setLayout(new java.awt.BorderLayout());        drawingPanel.setPreferredSize(new java.awt.Dimension(500, 500));        mainPanel.add(drawingPanel, java.awt.BorderLayout.CENTER);        getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);        fileMenu.setText("File");        exitMenuItem.setText("Exit");        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                exitMenuItemActionPerformed(evt);            }        });        fileMenu.add(exitMenuItem);        jMenuBar1.add(fileMenu);        setJMenuBar(jMenuBar1);        pack();    }    // </editor-fold>//GEN-END:initComponents    private void silverButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_silverButtonActionPerformed        color = SILVER;        if(scene != null) {            sao2.setValue(silver);        }    }//GEN-LAST:event_silverButtonActionPerformed    private void goldButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goldButtonActionPerformed        color = GOLD;        if(scene != null) {            sao2.setValue(gold);        }    }//GEN-LAST:event_goldButtonActionPerformed    private void replaceSPButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replaceSPButtonActionPerformed      if (shaderSelected != DIMPLE_SHADER) {          goldButton.setEnabled(false);          silverButton.setEnabled(false);          zeroButton.setEnabled(false);          halfButton.setEnabled(false);          fullButton.setEnabled(false);      }            switch(shaderSelected) {          case DIMPLE_SHADER:             s3d.setAppearance(sApp1);             goldButton.setEnabled(true);             silverButton.setEnabled(true);             zeroButton.setEnabled(true);             halfButton.setEnabled(true);             fullButton.setEnabled(true);              shaderSelected = BRICK_SHADER;             break;          case BRICK_SHADER:             s3d.setAppearance(sApp2);             shaderSelected = WOOD_SHADER;             break;          case WOOD_SHADER:              s3d.setAppearance(sApp3);              shaderSelected = POLKADOT3D_SHADER;              break;          case POLKADOT3D_SHADER:              s3d.setAppearance(sApp4);              shaderSelected = DIMPLE_SHADER;              break;          default:              assert false;      }          }//GEN-LAST:event_replaceSPButtonActionPerformed    private void fullButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fullButtonActionPerformed        density = 16.0f;        if (scene != null) {            sao1.setValue(new Float(density));        }    }//GEN-LAST:event_fullButtonActionPerformed    private void DetachButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DetachButtonActionPerformed        if (scene != null) {            scene.detach();            scene = null;            replaceSPButton.setEnabled(false);            goldButton.setEnabled(true);            silverButton.setEnabled(true);            zeroButton.setEnabled(true);            halfButton.setEnabled(true);            fullButton.setEnabled(true);            shaderSelected = DIMPLE_SHADER;                   }    }//GEN-LAST:event_DetachButtonActionPerformed    private void AttachButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AttachButtonActionPerformed       if (scene == null) {            scene = createSceneGraph(1);            univ.addBranchGraph(scene);            replaceSPButton.setEnabled(true);            shaderSelected = BRICK_SHADER;       }      }//GEN-LAST:event_AttachButtonActionPerformed    private void halfButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_halfButtonActionPerformed        density = 8.0f;        if(scene != null) {            sao1.setValue(new Float(density));        }    }//GEN-LAST:event_halfButtonActionPerformed    private void zeroButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zeroButtonActionPerformed        density = 0.0f;        if(scene != null) {            sao1.setValue(new Float(density));        }      }//GEN-LAST:event_zeroButtonActionPerformed    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed        System.exit(0);    }//GEN-LAST:event_exitMenuItemActionPerformed    /** Exit the Application */    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm        System.exit(0);    }//GEN-LAST:event_exitForm    /**     * @param args the command line arguments     */    public static void main(String args[]) {        new ShaderTestGLSL().setVisible(true);    }    // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JToggleButton AttachButton;    private javax.swing.JToggleButton DetachButton;    private javax.swing.ButtonGroup colorButtonGroup;    private javax.swing.JPanel colorPanel;    private javax.swing.ButtonGroup densityButtonGroup;    private javax.swing.JPanel densityPanel;    private javax.swing.JPanel drawingPanel;    private javax.swing.JMenuItem exitMenuItem;    private javax.swing.JMenu fileMenu;    private javax.swing.JRadioButton fullButton;    private javax.swing.JRadioButton goldButton;    private javax.swing.JPanel guiPanel;    private javax.swing.JRadioButton halfButton;    private javax.swing.JMenuBar jMenuBar1;    private javax.swing.JPanel mainPanel;    private javax.swing.JButton replaceSPButton;    private javax.swing.ButtonGroup sceneGraphButtonGroup;    private javax.swing.JPanel sceneGraphPanel;    private javax.swing.JRadioButton silverButton;    private javax.swing.JRadioButton zeroButton;    // End of variables declaration//GEN-END:variables}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -