Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

80
LINES

< > BotCompany Repo | #1033789 // Hardware Acceleration Test

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (4872L/27K).

1  
p-awt { new GraphicsTest; }
2  
3  
sclass GraphicsTest extends JFrame {
4  
    GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
5  
    BufferCapabilities bufferCapabilities;
6  
    BufferStrategy bufferStrategy;
7  
8  
    int y = 0;
9  
    int delta = 1;
10  
11  
    public GraphicsTest() {
12  
13  
        setTitle("Hardware Acceleration Test");
14  
        setSize(500, 300);
15  
        setLocationRelativeTo(null);
16  
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
17  
18  
        setVisible(true);
19  
20  
        createBufferStrategy(2);
21  
        bufferStrategy = getBufferStrategy();
22  
23  
        bufferCapabilities = gc.getBufferCapabilities();
24  
25  
        new AnimationThread().start();
26  
    }
27  
28  
    class AnimationThread extends Thread {
29  
        @Override
30  
        public void run() {
31  
32  
            while(true) {
33  
                Graphics2D g2 = null;
34  
                try {
35  
                    g2 = (Graphics2D) bufferStrategy.getDrawGraphics();
36  
                    draw(g2);
37  
                } finally {
38  
                    if(g2 != null) g2.dispose();
39  
                }
40  
                bufferStrategy.show();
41  
42  
                try {
43  
                    // CHANGE HERE, DONT SLEEP
44  
                    //Thread.sleep(16);
45  
                } catch(Exception err) {
46  
                    err.printStackTrace();
47  
                }
48  
            }
49  
        }
50  
    }
51  
52  
    public void draw(Graphics2D g2) {
53  
        if(!bufferCapabilities.isPageFlipping() || bufferCapabilities.isFullScreenRequired()) {
54  
            g2.setColor(Color.black);
55  
            g2.fillRect(0, 0, getWidth(), getHeight());
56  
            g2.setColor(Color.red);
57  
            g2.drawString("Hardware Acceleration is not supported...", 100, 100);
58  
            g2.setColor(Color.white);
59  
            g2.drawString("Page Flipping: " + (bufferCapabilities.isPageFlipping() ? "Available" : "Not Supported"), 100, 130);
60  
            g2.drawString("Full Screen Required: " + (bufferCapabilities.isFullScreenRequired() ? "Required" : "Not Required"), 100, 160);
61  
            g2.drawString("Multiple Buffer Capable: " + (bufferCapabilities.isMultiBufferAvailable() ? "Yes" : "No"), 100, 190);
62  
        } else {
63  
            g2.setColor(Color.black);
64  
            g2.fillRect(0, 0, getWidth(), getHeight());
65  
            g2.setColor(Color.white);
66  
            g2.drawString("Hardware Acceleration is Working...", 100, 100);
67  
            g2.drawString("Page Flipping: " + (bufferCapabilities.isPageFlipping() ? "Available" : "Not Supported"), 100, 130);
68  
            g2.drawString("Full Screen Required: " + (bufferCapabilities.isFullScreenRequired() ? "Required" : "Not Required"), 100, 160);
69  
            g2.drawString("Multiple Buffer Capable: " + (bufferCapabilities.isMultiBufferAvailable() ? "Yes" : "No"), 100, 190);
70  
        }
71  
72  
        y += delta;
73  
        if((y + 50) > getHeight() || y < 0) {
74  
            delta *= -1;
75  
        }
76  
77  
        g2.setColor(Color.blue);
78  
        g2.fillRect(getWidth()-50, y, 50, 50);
79  
    }
80  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): bhatertpkbcr, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033789
Snippet name: Hardware Acceleration Test
Eternal ID of this version: #1033789/1
Text MD5: 3a2a5dea2fea3e35c94b088cfd3f6381
Transpilation MD5: 9274614e8cbf9d1aaad7f637ba10f906
Author: stefan
Category: javax / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-04 21:59:07
Source code size: 3066 bytes / 80 lines
Pitched / IR pitched: No / No
Views / Downloads: 118 / 572
Referenced in: [show references]