package agp;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.threed.jpct.*;public class OpeningScreen extends JFrame implements MouseListener { private static final long serialVersionUID = 1L; private Texture background; protected boolean hasFinished, quitPressed, introPressed; private FrameBuffer buffer; private float widthMul, heightMul; private Button3d playButton, loadButton, introButton, quitButton; public static void main(String[] args) { new OpeningScreen(); } public OpeningScreen() { FrameBuffer buffer = new FrameBuffer(1024, 768, FrameBuffer.SAMPLINGMODE_NORMAL); this.buffer = buffer; quitPressed = false; widthMul = ((float) buffer.getOutputWidth()) / 1024f; heightMul = ((float) buffer.getOutputHeight()) / 768f; background = new Texture("OpeningScreen.png", false); hasFinished = false; playButton = new Button3d(406f * widthMul, 360 * heightMul, 202f * widthMul, 80f * heightMul, new Texture("off.png", true), new Texture("on.png", true)); loadButton = new Button3d(406f * widthMul, 440 * heightMul, 202f * widthMul, 80f * heightMul, new Texture("off.png", true), new Texture("on.png", true)); introButton = new Button3d(406f * widthMul, 520 * heightMul, 202f * widthMul, 80f * heightMul, new Texture("off.png", true), new Texture("on.png", true)); quitButton = new Button3d(406f * widthMul, 600 * heightMul, 202f * widthMul, 80f * heightMul, new Texture("off.png", true), new Texture("on.png", true)); this.setSize(1024, 768); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.addMouseListener(this); } public void processClick(int x, int y) { if (playButton.contains(x, y)) hasFinished = true; else if (introButton.contains(x, y)) introPressed = true; else if (quitButton.contains(x, y)) hasFinished = quitPressed = true; this.repaint(); } public void processPress(int x, int y) { if (playButton.contains(x, y)) playButton.isPressed = true; else if (loadButton.contains(x, y)) loadButton.isPressed = true; else if (introButton.contains(x, y)) introButton.isPressed = true; else if (quitButton.contains(x, y)) quitButton.isPressed = true; this.repaint(); } public void processRelease(int x, int y) { playButton.isPressed = loadButton.isPressed = introButton.isPressed = quitButton.isPressed = false; this.repaint(); } @Override public void paint(Graphics g) { update(g); } @Override public void update(Graphics g) { buffer.clear(java.awt.Color.black); buffer.update(); buffer.blit(background, 0, 0, 0, 0, background.getWidth(), background.getHeight(), buffer.getOutputWidth(), buffer.getOutputHeight(), -1, false); buffer.clearZBufferOnly(); playButton.draw(buffer); loadButton.draw(buffer); introButton.draw(buffer); quitButton.draw(buffer); buffer.display(g); } @Override public void mouseClicked(MouseEvent arg0) { processClick(arg0.getX(), arg0.getY()); } @Override public void mouseEntered(MouseEvent arg0) { // } @Override public void mouseExited(MouseEvent arg0) { // } @Override public void mousePressed(MouseEvent arg0) { processPress(arg0.getX(), arg0.getY()); } @Override public void mouseReleased(MouseEvent arg0) { processRelease(arg0.getX(), arg0.getY()); }}class Button3d { private int x, y, width, height; private Texture unpressed, pressed; protected boolean isPressed; public Button3d(float x, float y, float width, float height, Texture unpressed, Texture pressed) { this.x = (int) (x + .5f); this.y = (int) (y + .5f); this.width = (int) (width + .5f); this.height = (int) (height + .5f); this.unpressed = unpressed; this.pressed = pressed; isPressed = false; } public boolean contains(int x, int y) { if (x > this.x && x <= this.x + this.width && y > this.y && y <= this.y + this.height) { return true; } return false; } public void draw(FrameBuffer buffer) { if (!isPressed) { buffer.blit(unpressed, 0, 0, x, y, unpressed.getWidth(), unpressed.getHeight(), width, height, 200, false); } else { buffer.blit(pressed, 0, 0, x, y, pressed.getWidth(), pressed.getHeight(), width, height, 200, false); } if (buffer.usesRenderer(IRenderer.RENDERER_SOFTWARE)) { java.awt.Graphics g2 = buffer.getGraphics(); g2.setColor(java.awt.Color.blue); g2.drawRect((int) x, (int) y, (int) width, (int) height); } }}
That's very strange. I added the clearZBufferOnly() in between the blits, but I saw no improvement.