aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanelTest1.java
blob: 66889e9ed384e66f7e251d7e0c143050ce0d3920 (plain)
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
package com.jogamp.opengl.test.bugs;

import javax.swing.*;
import java.awt.*;
import javax.media.opengl.*;
import javax.media.opengl.awt.*;

public class Bug427GLJPanelTest1 extends JFrame implements GLEventListener {

    public Bug427GLJPanelTest1() {
        super("Bug427GLJPanelTest1");

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new BorderLayout());

        try {
            javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    setSize(600, 600);
                    setLocation(40, 40);
                    setVisible(true);
                } } );
        } catch(Exception ex) {
            throw new RuntimeException(ex);
        }

        GLProfile glp = GLProfile.get(GLProfile.GL2);
        GLCapabilities caps = new GLCapabilities(glp);
        caps.setDoubleBuffered(true);
        caps.setHardwareAccelerated(true);

        GLJPanel panel = new GLJPanel(caps);
        panel.addGLEventListener(this);

        add(panel, BorderLayout.CENTER);
    }

    public static void main(String[] args) {
        final Bug427GLJPanelTest1 demo = new Bug427GLJPanelTest1();
        try {
            javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    demo.setVisible(true);
                } } );
        } catch(Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    public void display(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();

        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
        gl.glBegin(GL.GL_TRIANGLES);

        gl.glColor3f(1, 0, 0);
        gl.glVertex3f(0.25f, 0.25f, 0);

        gl.glColor3f(0, 1, 0);
        gl.glVertex3f(0.5f, 0.25f, 0);

        gl.glColor3f(0, 0, 1);
        gl.glVertex3f(0.25f, 0.5f, 0);

        gl.glEnd();
        gl.glFlush();
    }

    public void init(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();

        gl.glClearColor(0, 0, 0, 0);
        gl.glMatrixMode(GL2.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrtho(0, 1, 0, 1, -1, 1);
    }

    public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {
    }

    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
    }
    
    public void dispose(GLAutoDrawable drawable) {
    }
}