My favorites | Sign in
Project Logo
Project hosting will be READ-ONLY Wednesday at 8am PST due to brief network maintenance.
                
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
package org.lwjgltutorial.chapter2;

import static org.lwjgl.opengl.GL11.GL_LINE_LOOP;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glFlush;
import static org.lwjgl.opengl.GL11.glVertex3f;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

public class ProperSquare {

private static final int WINDOW_HEIGHT = 600;
private static final int WINDOW_WIDTH = 800;

public ProperSquare(){
init();
}

private void init() {
// find out what the current bits per pixel of the desktop is
int currentBpp = Display.getDisplayMode().getBitsPerPixel();
// find a display mode at 800x600
try {
DisplayMode mode = findDisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT,
currentBpp);
Display.setDisplayMode(mode);
Display.setFullscreen(false);
Display.setTitle("Proper Square");
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double aspectRatio = (double)WINDOW_WIDTH/WINDOW_HEIGHT;
glOrtho(aspectRatio,- aspectRatio, -1.0d, 1.0d, 1.0d, -1.0d);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

private void loop() {
render();
// update window.
Display.update();
// wait for close
while(!Display.isCloseRequested()){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Display.destroy();
}

private void render() {
// draw the square
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(0.5f, 0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, 0.5f);
glEnd();

// flush any commands that are still hanging about.
glFlush();
}


private DisplayMode findDisplayMode(int width, int height, int bpp) throws LWJGLException {
DisplayMode[] modes = Display.getAvailableDisplayModes();
DisplayMode mode = null;

for (int i=0;i<modes.length;i++) {
if ((modes[i].getBitsPerPixel() == bpp) || (mode == null)) {
if ((modes[i].getWidth() == width) && (modes[i].getHeight() == height)) {
mode = modes[i];
}
}
}

return mode;
}

public static void main(String[] args) throws InterruptedException{

ProperSquare square = new ProperSquare();
square.loop();

}




}
Show details Hide details

Change log

r4 by fireman.phil on Jun 14, 2009   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 2388 bytes, 99 lines
Hosted by Google Code