没有调用GLEventListener JOGL实现的函数

时间:2016-04-13 23:48:55

标签: java swing opengl jogl

我正在使用Eclipse,Java和JOGL4。我正在尝试在swing画布上绘制一个简单的三角形。但是,GLEventListener函数没有被调用。

我有两个Java类,一个使用Swing设置UI的UI类,并扩展了GLEventListener。所以我在班上有init,display,dispose,functions。 我还有一个第二堂课应该叫第二堂课。但是,UI类的函数 - 初始化和显示 - 似乎从未被调用过。

因此,例如,UI类有一个函数init(),它调用第二个类init()函数。例如:

        public void display(GLAutoDrawable arg0) {
            // TODO Auto-generated method stub
            System.out.println("Display");
            renderer.display(arg0);

        }

        public void dispose(GLAutoDrawable arg0) {
            // TODO Auto-generated method stub
            System.out.println("Dispose");
        }
        @Override
        public void init(GLAutoDrawable arg0) {
            // TODO Auto-generated method stub
            System.out.println("Init");
            renderer.init(arg0);
        }
        @Override
        public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
            // TODO Auto-generated method stub
            System.out.println("Reshape");
        }

输出文本“init”,“display”,“dispose”和“Reshape”永远不会出现。即使在渲染器类中调用了display,也没有绘制任何内容。这个类太大了,不能粘贴在这里,但这是类的标题,它的末尾是监听器函数。

    package IDE;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.tree.DefaultMutableTreeNode;

import com.jogamp.newt.Display;
import com.jogamp.newt.NewtFactory;
import com.jogamp.newt.Screen;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;
import com.jogamp.newt.event.WindowUpdateEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLDrawableFactory;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.Animator;

import Central.GLRenderer;
import Listeners.BasicMenuListener;

public class UserInterface implements GLEventListener, KeyListener{
    private JTree tree;
    JPopupMenu popupmenu;
    GLRenderer renderer = new GLRenderer();
    JFrame frame = new JFrame("NecroTEK 3D Game Graphics Engine");

...

                public void display(GLAutoDrawable arg0) {
                // TODO Auto-generated method stub
                System.out.println("Display");
                renderer.display(arg0);

            }

            public void dispose(GLAutoDrawable arg0) {
                // TODO Auto-generated method stub
                System.out.println("Dispose");
            }
            @Override
            public void init(GLAutoDrawable arg0) {
                // TODO Auto-generated method stub
                System.out.println("Init");
                renderer.init(arg0);
            }
            @Override
            public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
                // TODO Auto-generated method stub
                System.out.println("Reshape");
            }


            /**************/
            // An inner class to check whether mouse events are the popup trigger
            class MousePopupListener extends MouseAdapter {
                public void mousePressed(MouseEvent e) {
                    checkPopup(e);
                }

                public void mouseClicked(MouseEvent e) {
                    checkPopup(e);
                }

                public void mouseReleased(MouseEvent e) {
                    checkPopup(e);
                }

                private void checkPopup(MouseEvent e) {
                    if (e.isPopupTrigger()) {
                        popupmenu.show(popupmenu, e.getX(), e.getY());
                    }
                }
            }


            // An inner class to show when popup events occur
            class PopupPrintListener implements PopupMenuListener {
                public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                    System.out.println("Popup menu will be visible!");
                }

                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                    System.out.println("Popup menu will be invisible!");
                }

                public void popupMenuCanceled(PopupMenuEvent e) {
                    System.out.println("Popup menu is hidden!");
                }
            }


            @Override
            public void keyPressed(KeyEvent arg0) {
                // TODO Auto-generated method stub

            }
            @Override
            public void keyReleased(KeyEvent arg0) {
                // TODO Auto-generated method stub

            }






}

好的,它现在正在调用Display,但它仍然没有绘制。这是我的render函数,由display:

调用
public void render(GLAutoDrawable drawable) {

    GL2 gl2 = drawable.getGL().getGL2();
    gl2.glClear( GL2.GL_COLOR_BUFFER_BIT );


    int width = 640;
    int height = 480;

    // draw a triangle filling the window
    gl2.glLoadIdentity();
    gl2.glBegin( GL2.GL_TRIANGLES );
    gl2.glColor3f( 1, 0, 0 );
    gl2.glVertex2f( 0, 0 );
    gl2.glColor3f( 0, 1, 0 );
    gl2.glVertex2f( width, 0 );
    gl2.glColor3f( 0, 0, 1 );
    gl2.glVertex2f( width / 2, height );
    gl2.glEnd();
  }

0 个答案:

没有答案