Skip to content

Commit

Permalink
changes to handle resizable screens.
Browse files Browse the repository at this point in the history
GridBagLayout is used to resize the GL canvas together with the frame
  • Loading branch information
cwei committed Mar 2, 2008
1 parent 78d0a1f commit e6da1e1
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/jake2/render/opengl/Jsr231Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public int setMode(Dimension dim, int mode, boolean fullscreen) {
VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":");

/*
* fullscreen handling
* full screen handling
*/
if (device == null) {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
Expand All @@ -160,12 +160,18 @@ public int setMode(Dimension dim, int mode, boolean fullscreen) {
window = new Frame("Jake2 (jsr231)");
ImageIcon icon = new ImageIcon(getClass().getResource("/icon-small.png"));
window.setIconImage(icon.getImage());
window.setLayout(new GridBagLayout());

Display canvas = new Display(new GLCapabilities());
// we want keypressed events for TAB key
canvas.setFocusTraversalKeysEnabled(false);

window.add(canvas);
// the OpenGL canvas grows and shrinks with the window
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = gbc.weighty = 1;
window.add(canvas, gbc);

canvas.setSize(newDim.width, newDim.height);

// register event listener
Expand Down Expand Up @@ -209,7 +215,7 @@ public void windowClosing(WindowEvent e) {
public void run() {
//f2.setLocation(window_xpos, window_ypos);
f2.pack();
f2.setResizable(false);
f2.setResizable(true);
f2.setVisible(true);
}
});
Expand All @@ -227,10 +233,6 @@ public void run() {

this.display = canvas;

Base.setVid(newDim.width, newDim.height);

// let the sound and input subsystems know about the new window
VID.NewWindow(newDim.width, newDim.height);
setGL(display.getGL());
init(0, 0);

Expand Down Expand Up @@ -284,13 +286,13 @@ public boolean init(int xpos, int ypos) {
// clear the screen
// first buffer
beginFrame(0.0f);
glViewport(0, 0, window.getWidth(), window.getHeight());
glViewport(0, 0, display.getWidth(), display.getHeight());
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
endFrame();
// second buffer
beginFrame(0.0f);
glViewport(0, 0, window.getWidth(), window.getHeight());
glViewport(0, 0, display.getWidth(), display.getHeight());
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
endFrame();
Expand Down Expand Up @@ -347,7 +349,26 @@ GL getGL() {
activate();
return context.getGL();
}
/** <B>Overrides:</B>


/**
* @see java.awt.Component#setBounds(int, int, int, int)
*/
public void setBounds(int x, int y, int width, int height) {
final int mask = ~0x03;
if ((width & 0x03) != 0) {
width &= mask;
width += 4;
}

// System.out.println("display bounds: " + x + ", " + y + ", " + width + ", " + height);
super.setBounds(x, y, width, height);
Base.setVid(width, height);
// let the sound and input subsystems know about the new window
VID.NewWindow(width, height);
}

/** <B>Overrides:</B>
<DL><DD><CODE>paint</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */
// Overridden from Canvas to prevent the AWT's clearing of the
// canvas from interfering with the OpenGL rendering.
Expand Down

0 comments on commit e6da1e1

Please sign in to comment.