Skip to content

Instantly share code, notes, and snippets.

@Quby
Created December 6, 2011 16:31
Show Gist options
  • Save Quby/1438840 to your computer and use it in GitHub Desktop.
Save Quby/1438840 to your computer and use it in GitHub Desktop.
import org.lwjgl.opengl.*;
import org.lwjgl.*;
import org.lwjgl.util.glu.*;
import org.lwjgl.input.*;
public class Main {
public static void main(String[] args) {
int w = 800, h = 600;
try {
Display.setDisplayMode(new DisplayMode(w,h));
PixelFormat pf = new PixelFormat()
.withBitsPerPixel(16)
.withDepthBits(24)
.withSamples(4);
Display.create(pf);
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
GL11.glViewport(0, 0, w, h);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(45.0f, w/h, 0.1f, 100.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glClearColor(0.0f, 255.0f, 255.0f, 255.0f);
float z1 = 0.0f;
float z2 = 0.0f;
while(!Display.isCloseRequested()) {
if (Keyboard.isKeyDown(Keyboard.KEY_LEFT))
z1 -= 0.01f;
if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
z1 += 0.01f;
if (Keyboard.isKeyDown(Keyboard.KEY_DOWN))
z2 -= 0.01f;
if (Keyboard.isKeyDown(Keyboard.KEY_UP))
z2 += 0.01f;
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
Display.destroy();
break;
}
//GL11.glEnable(ARBMultisample.GL_MULTISAMPLE_BIT_ARB);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glLoadIdentity();
GL11.glColor3f(0, 0, 0);
GL11.glTranslatef(0, 0, -5.0f);
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3f (1.0f, 1.0f, z1-z2);
GL11.glVertex3f (1.0f, -1.0f, z1+z2);
GL11.glVertex3f (-1.0f, -1.0f, -z1+z2);
GL11.glVertex3f (-1.0f, 1.0f, -z1-z2);
GL11.glEnd();
//GL11.glDisable(ARBMultisample.GL_SAMPLE_COVERAGE_INVERT_ARB );
Display.update();
}
Display.destroy();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment