Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.test;
- import java.io.File;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.LWJGLUtil;
- import org.lwjgl.input.Keyboard;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.DisplayMode;
- import org.lwjgl.opengl.GL11;
- import org.lwjgl.util.glu.GLU;
- public class Main {
- // Entry point for the application
- public static void main(String[] args) {
- System.setProperty("org.lwjgl.librarypath",
- new File(new File(System.getProperty("user.dir"), "native"),
- LWJGLUtil.getPlatformName()).getAbsolutePath());
- new Main();
- }
- private final String WINDOW_TITLE = "CubeTest";
- private final int WIDTH = 640;
- private final int HEIGHT = 360;
- private Container cont;
- public static int superCount;
- public Main() {
- this.setupOpenGL();
- cont = new Container();
- cont.setVertices(new Vertex[] { new Vertex(0.0f, 0.5f, 0.0f),
- new Vertex(-0.5f, -0.5f, 0.0f), new Vertex(0.5f, -0.5f, 0.0f) });
- cont.setIndices(new byte[] { 0, 1, 2 });
- while (!Display.isCloseRequested()) {
- this.ready3D();
- this.loopCycle();
- Display.sync(60);
- Display.update();
- }
- cont.destroyResources();
- Display.destroy();
- }
- public void setupOpenGL() {
- try {
- Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
- Display.setTitle(WINDOW_TITLE);
- Display.create();
- } catch (LWJGLException e) {
- e.printStackTrace();
- System.exit(-1);
- }
- GL11.glClearColor(0.4f, 0.6f, 0.9f, 0f);
- }
- private void ready3D() {
- GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
- GL11.glViewport(0, 0, WIDTH, HEIGHT);
- GL11.glMatrixMode(GL11.GL_PROJECTION);
- GL11.glLoadIdentity();
- GLU.gluPerspective(60, (float) WIDTH / HEIGHT, 0.1f, 10.0f);
- GL11.glMatrixMode(GL11.GL_MODELVIEW);
- GL11.glLoadIdentity();
- }
- public void loopCycle() {
- superCount++;
- float sinOff = (float) Math.sin(superCount / 30f) / 2f, cosOff = (float) Math
- .cos(superCount / 30f) / 2f;
- cont.setVertices(new Vertex[] {
- new Vertex(0.0f, 0.5f, cosOff).setRGB(1, 0.6f, 0.2f),
- new Vertex(-0.5f, -0.5f, 0.0f), new Vertex(0.5f, -0.5f, 0.0f) });
- cont.setIndices(new byte[] { 0, 1, 2 });
- cont.render();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment