tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
2
ZUGRIFFE
995
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Polli Polli ist offline Mitglied Silber
    Registriert seit
    Dec 2007
    Beiträge
    88
    Hallo alle zusammen,

    ich habe ein kleines Problem, seit knapp zwei Tagen versuche ich mich an Jogl, bislangen mit mittelmäßigen Erfolg.
    Ich habe an zwei Stellen ein Problem, evtl. könnt ihr mir ja dabei helfen, da ich gesehen habe, dass ihr schon ein Problem bezüglich Jogl gelöst habt.

    Und zwar ist mein erstes Problem: Wenn ich auf den Button "Linien" klicke, soll eigentlich eine Linie vom Mittelpunkt zur rechten oberen Ecke führen, aber irgendwie klappt das nicht. Ich komme einfach nicht weiter, habt ihr eine Idee was ich da machen kann? Ich habe es schon mit repaint probiert, aber es lieferte nicht den gewünschten Erfolg.

    Mein Zweites Problem ist, wenn ich das Fenster größer ziehe dann wird das Panel blau, also so dass alles was drauf ist nicht mehr sichtbar ist. Beim zweiten mal ziehen ist alles wieder da... Könnt ihr mir evtl. eine Lösung oder einen Tipp geben?

    Danke für eure Hilfe

    Hier mal mein Quellcode:

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import net.java.games.jogl.*;
    import net.java.games.jogl.util.*;
     
    public class Darstellung implements GLEventListener {
        int size_x = 800;
        int size_y = 600;
        JFrame frame;
        JMenuBar menuebar;
        JPanel toolbarPanel;
        GLCanvas panel1;
        GLCanvas panel2;
        JTabbedPane tabbedpane;
        JMenu fileMenue;
        JMenu helpMenue;
        JMenuItem neuItem;
        JMenuItem openItem;
        JMenuItem saveItem;
        JMenuItem helpItem;
        JMenuItem copyrightItem;
        GridBagLayout layout;
        JButton kreisButton;
        JButton eckButton;
        JButton linienButton;
        JButton punktButton;
        JButton ellipseButton;
        JButton kugelButton;
        JButton polygoneButton;
        JButton ellipsoidButton;
        GL gl;
        GLU glu;
        GLUT glut;
     
        public Darstellung() {
            Window();
        }
     
        public void Window() {
            frame = new JFrame("Architekten-Tool");
            frame.setSize(size_x, size_y);
            javax.swing.JPopupMenu.setDefaultLightWeightPopupEnabled(false); //MenuBar in den Vordergrund
            frame.setJMenuBar(MenueHilfe());
            compLayout();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
     
        public JMenuBar MenueHilfe() {
            menuebar = new JMenuBar();
            fileMenue = new JMenu("Datei");
            menuebar.add(fileMenue);
            fileMenue.add(neuItem = new JMenuItem("Neu"));
            fileMenue.add(openItem = new JMenuItem("Öffnen"));
            fileMenue.add(saveItem = new JMenuItem("Speichern"));
            helpMenue = new JMenu("Hilfe");
            menuebar.add(helpMenue);
            helpMenue.add(helpItem = new JMenuItem("Hilfe"));
            helpMenue.add(copyrightItem = new JMenuItem("Copyright"));
     
            return menuebar;
        }
     
        public JTabbedPane Tabbed() {
            panel1 = GLDrawableFactory.getFactory().createGLCanvas(
                    new GLCapabilities());
            panel2 = GLDrawableFactory.getFactory().createGLCanvas(
                    new GLCapabilities());
            
            panel1.addGLEventListener(this);
            tabbedpane = new JTabbedPane();
            tabbedpane.addTab("New 1", panel1);
            tabbedpane.addTab("New 2", panel2);
            return tabbedpane;
        }
     
        public JPanel Toolbar() {
            JPanel toolbarPanel = new JPanel();
            kreisButton = new JButton("Kreis");
            eckButton = new JButton("n-Eck");
            linienButton = new JButton("Linien");
            linienButton.addActionListener(new LinienKlick());
            punktButton = new JButton("Punkt");
            ellipseButton = new JButton("Ellipse");
     
            kugelButton = new JButton("Kugel");
            polygoneButton = new JButton("Polygone");
            ellipsoidButton = new JButton("Ellipsoid");
     
            toolbarPanel.setLayout(new GridLayout(8, 1));
     
            // 2D
            toolbarPanel.add(kreisButton);
            toolbarPanel.add(eckButton);
            toolbarPanel.add(linienButton);
            toolbarPanel.add(punktButton);
            toolbarPanel.add(ellipseButton);
     
            // 3D
            toolbarPanel.add(kugelButton);
            toolbarPanel.add(polygoneButton);
            toolbarPanel.add(ellipsoidButton);
            return toolbarPanel;
        }
     
        public void compLayout() {
            Container c = frame.getContentPane();
     
            layout = new GridBagLayout();
            c.setLayout(layout);
     
            // x y w h wx wy
            addComponent2(c, layout, Tabbed(), 0, 0, 10, 10, 0.1, 0.1);
            addComponent1(c, layout, Toolbar(), 10, 0, 2, 10, 0, 0);
        }
     
        static void addComponent1(Container cont, GridBagLayout gbl, Component c,
                int x, int y, int width, int height, double weightx, double weighty) {
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.fill = GridBagConstraints.VERTICAL;
            gbc.gridx = x;
            gbc.gridy = y;
            gbc.gridwidth = width;
            gbc.gridheight = height;
            gbc.weightx = weightx;
            gbc.weighty = weighty;
            gbl.setConstraints(c, gbc);
            cont.add(c);
        }
     
        static void addComponent2(Container cont, GridBagLayout gbl, Component c,
                int x, int y, int width, int height, double weightx, double weighty) {
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.fill = GridBagConstraints.BOTH;
            gbc.gridx = x;
            gbc.gridy = y;
            gbc.gridwidth = width;
            gbc.gridheight = height;
            gbc.weightx = weightx;
            gbc.weighty = weighty;
            gbl.setConstraints(c, gbc);
            cont.add(c);
        }
     
        @Override
        public void init(GLDrawable arg0) {
            // TODO Auto-generated method stub
            gl = arg0.getGL();
            glu = arg0.getGLU();
            glut = new GLUT();
            gl.glClearColor(1, 1, 1, 0); 
            
            System.out.println("init");
        }
        
        @Override
        public void display(GLDrawable arg0) {
            // TODO Auto-generated method stub
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            
            gl.glColor3d(1, 0, 0);
            gl.glBegin(GL.GL_LINES);
                gl.glVertex3d(0, 0, 0);
                gl.glVertex3d(50, 0, 0);
            gl.glEnd();
            
            System.out.println("display");
        }
     
        @Override
        public void displayChanged(GLDrawable arg0, boolean arg1, boolean arg2) {
            // TODO Auto-generated method stub
        }
     
        @Override
        public void reshape(GLDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
            // TODO Auto-generated method stub
        }
        
        public class LinienKlick implements ActionListener{
     
            @Override
            public void actionPerformed(ActionEvent arg0) {
                System.out.println("g "+ gl);
                System.out.println("Ich werde aufgerufen...");
                gl.glColor3d(1, 0, 0);
                gl.glBegin(GL.GL_LINES);
                    gl.glVertex3d(0, 0, 0);
                    gl.glVertex3d(50, 50, 0);
                gl.glEnd();
                panel1.display();
            }   
        }
        
        public static void main(String[] args) {
            Darstellung gui = new Darstellung();
        }
    }

    Ganz liebe Grüße,

    Polli.
    Geändert von Polli (05.01.10 um 09:18 Uhr)
     
    Jeder Moment ist eine neue Chance, nutze sie!!

    Wer lächelt statt zu toben, ist immer der Stärkere.

  2. #2
    Polli Polli ist offline Mitglied Silber
    Registriert seit
    Dec 2007
    Beiträge
    88
    Hallo ihr lieben,
    ich wollte mal nachfragen ob mir niemand mit dem Problem helfen kann?
    Den Beitrag habe ich vor nem Monat gepostet und den Fehler habe ich bis jetzt noch nicht rausbekommen... mag mir evtl. jemand helfen?

    LG Polli
     
    Jeder Moment ist eine neue Chance, nutze sie!!

    Wer lächelt statt zu toben, ist immer der Stärkere.

  3. #3
    MrCastle MrCastle ist offline Mitglied Bronze
    Registriert seit
    Aug 2009
    Beiträge
    32
    Ich bin mir zwar nicht sicher ob das funktioniert, aber füge mal die den Aufruf "gl.glFlush();" ans Ende deiner display-Methode ein. Es erzwingt die Ausführung aller anstehenden OpenGL-Befehle in einem endlichen Zeitraum.
     

Ähnliche Themen

  1. JOGL: VBO + Texturen
    Von Lorem im Forum Java
    Antworten: 0
    Letzter Beitrag: 06.10.10, 22:02
  2. Jogl 3D-Applet
    Von Tobsen999 im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 0
    Letzter Beitrag: 01.07.10, 16:35
  3. Compilermeldungen von Cg (JOGL)
    Von TriipaxX im Forum Java
    Antworten: 1
    Letzter Beitrag: 06.11.06, 15:39
  4. Probleme mit JOGL
    Von TriipaxX im Forum Java
    Antworten: 12
    Letzter Beitrag: 23.05.06, 16:15
  5. Eclipse und JOGL
    Von oska im Forum Java
    Antworten: 1
    Letzter Beitrag: 29.11.03, 22:02