コード例 #1
0
  @Override
  protected void init() {
    initializeProgram();

    try {
      cylinderMesh = new Mesh("UnitCylinder.xml");
      planeMesh = new Mesh("LargePlane.xml");
    } catch (Exception exception) {
      exception.printStackTrace();
      System.exit(-1);
    }

    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glFrontFace(GL_CW);

    glEnable(GL_DEPTH_TEST);
    glDepthMask(true);
    glDepthFunc(GL_LEQUAL);
    glDepthRange(0.0f, 1.0f);
    glEnable(GL_DEPTH_CLAMP);

    projectionUniformBuffer = glGenBuffers();
    glBindBuffer(GL_UNIFORM_BUFFER, projectionUniformBuffer);
    glBufferData(GL_UNIFORM_BUFFER, ProjectionBlock.SIZE, GL_DYNAMIC_DRAW);

    // Bind the static buffers.
    glBindBufferRange(
        GL_UNIFORM_BUFFER, projectionBlockIndex, projectionUniformBuffer, 0, ProjectionBlock.SIZE);

    glBindBuffer(GL_UNIFORM_BUFFER, 0);
  }
コード例 #2
0
ファイル: Codenav.java プロジェクト: Haynesy/Codenav
  private void initialise() {
    DisplayMode mode = new DisplayMode(WIDTH, HEIGHT);
    Display.setTitle(TITLE);

    input = new InputHandler();
    display = new CodeDisplay(input);

    try {
      Display.setDisplayMode(mode);
      Display.setResizable(false);
      Display.create();

      if (!GLContext.getCapabilities().OpenGL33)
        System.err.printf("You must have at least OpenGL 3.3 to run this program\n");
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(-1);
    }

    // Set clear color

    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL); // Less than or equal
    glClearDepth(1.0);

    establishProjectionMatrix();

    // glEnable(GL_LIGHTING);
    // glEnable(GL_LIGHT0);
  }
コード例 #3
0
ファイル: Window.java プロジェクト: TeamField3/jTTD
 public static void setParent(Canvas canvas) {
   try {
     Display.setParent(canvas);
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
コード例 #4
0
ファイル: Window.java プロジェクト: TeamField3/jTTD
 public static void setSize(int width, int height) {
   try {
     displayMode = new DisplayMode(width, height);
     Display.setDisplayMode(displayMode);
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
コード例 #5
0
ファイル: Window.java プロジェクト: TeamField3/jTTD
 public static void create() {
   try {
     Display.create();
     Mouse.create();
     Keyboard.create();
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
コード例 #6
0
ファイル: Sprite.java プロジェクト: mewGit/alp5_game
 /**
  * Create a new sprite from a specified image.
  *
  * @param loader the texture loader to use
  * @param ref A reference to the image on which this sprite should be based
  */
 public Sprite(TextureLoader loader, String ref) {
   try {
     texture = loader.getTexture(ref);
     width = texture.getImageWidth();
     height = texture.getImageHeight();
   } catch (IOException ioe) {
     ioe.printStackTrace();
     System.exit(-1);
   }
 }
コード例 #7
0
ファイル: Sprite.java プロジェクト: mewGit/alp5_game
 public Sprite(TextureLoader loader, String ref, int x, int y, int w, int h) {
   try {
     texture = loader.getTexture(ref, GL_TEXTURE_2D, GL_RGBA, GL_LINEAR, GL_LINEAR, x, y, w, h);
     width = texture.getImageWidth();
     height = texture.getImageHeight();
   } catch (IOException ioe) {
     ioe.printStackTrace();
     System.exit(-1);
   }
 }
コード例 #8
0
  @Override
  public void handleOutput(List<Entity> collection) {
    if (getInputCloseSignal()) // read input
    System.exit(0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    for (Entity e : collection) render(e);
    Display.sync(FPS); // sync to fps
    Display.update(); // update the view/screen
  }
コード例 #9
0
  private static void killAll() {
    // Kill any waiting threads
    for (Thread t : Thread.getAllStackTraces().keySet()) {
      if (t.getState() == Thread.State.WAITING && !t.getName().contains("Disposer")) {
        t.interrupt();
      }
    }

    System.exit(0); // Exit
  }
コード例 #10
0
ファイル: OBJLoader.java プロジェクト: AlexandreRio/JGame
 /**
  * @param path Path of the .obj file
  * @param index GLUint
  */
 public static void name(String path, int index) {
   int list = glGenLists(index);
   glNewList(list, GL_COMPILE);
   {
     Model m = null;
     try {
       m = OBJLoader.loadModel(new File(path));
     } catch (FileNotFoundException e) {
       e.printStackTrace();
       Display.destroy();
       System.exit(1);
     } catch (IOException e) {
       e.printStackTrace();
       Display.destroy();
       System.exit(1);
     }
     float b;
     //			glColor3f(0.3f, 0.20f, 0.13f);
     b = (float) Math.random();
     glColor3f(b, 0, 0);
     int count = 0;
     glBegin(GL_TRIANGLES);
     for (Face face : m.faces) {
       count++;
       Vector3f n1 = m.normals.get((int) face.normal.x - 1);
       glNormal3f(n1.x, n1.y, n1.z);
       Vector3f v1 = m.vertices.get((int) face.vertex.x - 1);
       glVertex3f(v1.x, v1.y, v1.z);
       Vector3f n2 = m.normals.get((int) face.normal.y - 1);
       glNormal3f(n2.x, n2.y, n2.z);
       Vector3f v2 = m.vertices.get((int) face.vertex.y - 1);
       glVertex3f(v2.x, v2.y, v2.z);
       Vector3f n3 = m.normals.get((int) face.normal.z - 1);
       glNormal3f(n3.x, n3.y, n3.z);
       Vector3f v3 = m.vertices.get((int) face.vertex.z - 1);
       glVertex3f(v3.x, v3.y, v3.z);
     }
     glEnd();
     System.out.println(count);
   }
   glEndList();
 }
コード例 #11
0
  public static void main(String[] args) {
    try {
      Display.setDisplayMode(new DisplayMode(640, 480));
      Display.setTitle("Timer Demo");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
      Display.destroy();
      System.exit(1);
    }

    int x = 100;
    int y = 100;
    int dx = 1;
    int dy = 1;

    // Initialization code OpenGL
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 640, 480, 0, 1, -1);
    glMatrixMode(GL_MODELVIEW);

    lastFrame = getTime();

    while (!Display.isCloseRequested()) {
      // Render

      glClear(GL_COLOR_BUFFER_BIT);

      double delta = getDelta();
      x += delta * dx * 0.1;
      y += delta * dy * 0.1;

      glRecti(x, y, x + 30, y + 30);

      Display.update();
      Display.sync(60);
    }

    Display.destroy();
    System.exit(0);
  }
コード例 #12
0
ファイル: Texture.java プロジェクト: Kiwuser/3DGameEngine
  private static TextureResource loadTexture(String fileName) {
    String[] splitArray = fileName.split("\\.");
    String ext = splitArray[splitArray.length - 1];

    try {
      BufferedImage image = ImageIO.read(new File("./res/textures/" + fileName));
      int[] pixels =
          image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());

      ByteBuffer buffer = Util.createByteBuffer(image.getHeight() * image.getWidth() * 4);
      boolean hasAlpha = image.getColorModel().hasAlpha();

      for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
          int pixel = pixels[y * image.getWidth() + x];

          buffer.put((byte) ((pixel >> 16) & 0xFF));
          buffer.put((byte) ((pixel >> 8) & 0xFF));
          buffer.put((byte) ((pixel) & 0xFF));
          if (hasAlpha) buffer.put((byte) ((pixel >> 24) & 0xFF));
          else buffer.put((byte) (0xFF));
        }
      }

      buffer.flip();

      TextureResource resource = new TextureResource();
      glBindTexture(GL_TEXTURE_2D, resource.getId());

      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

      glTexImage2D(
          GL_TEXTURE_2D,
          0,
          GL_RGBA8,
          image.getWidth(),
          image.getHeight(),
          0,
          GL_RGBA,
          GL_UNSIGNED_BYTE,
          buffer);

      return resource;
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }

    return null;
  }
コード例 #13
0
  @Override
  protected void init() {
    initializePrograms();

    try {
      realHallway = new Mesh("RealHallway.xml");
      fauxHallway = new Mesh("FauxHallway.xml");
    } catch (Exception exception) {
      exception.printStackTrace();
      System.exit(-1);
    }
  }
コード例 #14
0
 private static void setUpDisplay() {
   try {
     Display.setDisplayMode(new DisplayMode(640, 480));
     Display.setVSyncEnabled(true);
     Display.setTitle("Core Lighting Demo");
     Display.create();
   } catch (LWJGLException e) {
     System.err.println("The display wasn't initialized correctly. :(");
     Display.destroy();
     System.exit(1);
   }
 }
コード例 #15
0
ファイル: ClothSim.java プロジェクト: dshen36/GATECH
 /**
  * Application init
  *
  * @param args Commandline args
  */
 public static void main(String[] args) {
   try {
     init(false);
     run();
   } catch (Exception e) {
     e.printStackTrace(System.err);
     Sys.alert(GAME_TITLE, "An error occured and the game will exit.");
   } finally {
     cleanup();
   }
   System.exit(0);
 }
コード例 #16
0
  public static void main(String[] args) {
    try {
      Display.setDisplayMode(new DisplayMode(640, 480));
      Display.setTitle("Immediate Mode Demo");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
      Display.destroy();
      System.exit(1);
    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(1, 1, 1, 1, 1, -1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    while (!Display.isCloseRequested()) {
      glClear(GL_COLOR_BUFFER_BIT);

      glBegin(GL_TRIANGLES);
      {
        glColor3f(1, 0, 0);
        glVertex2f(-0.5f, -0.5f);
        glColor3f(0, 1, 0);
        glVertex2f(0.5f, -0.5f);
        glColor3f(0, 0, 1);
        glVertex2f(0.5f, 0.5f);
      }
      glEnd();

      Display.update();
      Display.sync(60);
    }

    Display.destroy();
    System.exit(0);
  }
コード例 #17
0
ファイル: Window.java プロジェクト: TeamField3/jTTD
 public static void setFullscreen(boolean fullscreen) {
   try {
     if (fullscreen) {
       displayMode = Display.getDisplayMode();
       Display.setDisplayMode(Display.getDesktopDisplayMode());
     } else {
       Display.setDisplayMode(displayMode);
     }
     Display.setFullscreen(fullscreen);
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
コード例 #18
0
 public static void main(String[] args) {
   setUpDisplay();
   setUpDisplayLists();
   setUpCamera();
   setUpLighting();
   while (!Display.isCloseRequested()) {
     render();
     checkInput();
     Display.update();
     Display.sync(60);
   }
   cleanUp();
   System.exit(0);
 }
コード例 #19
0
ファイル: TextEditor.java プロジェクト: brainshave/OpenGLOL
  @Override
  protected void init() {
    glClearColor(0, 0, 0, 0);
    glPixelZoom(1, -1);

    try {
      for (int i = 0; i < fonts.length; ++i) {
        fonts[i] = new Font(new File(FONT_NAMES[i]), FONT_MAPS[i], width, height);
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
コード例 #20
0
 private static void setUpVBOs() {
   int[] vbos;
   try {
     model = OBJLoader.loadModel(new File(MODEL_LOCATION));
     vbos = OBJLoader.createVBO(model);
     vboVertexHandle = vbos[0];
     vboNormalHandle = vbos[1];
   } catch (FileNotFoundException e) {
     e.printStackTrace();
     cleanUp();
     System.exit(1);
   } catch (IOException e) {
     e.printStackTrace();
     cleanUp();
     System.exit(1);
   }
   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_NORMAL_ARRAY);
   glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
   glVertexPointer(3, GL_FLOAT, 0, 0L);
   glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
   glNormalPointer(GL_FLOAT, 0, 0L);
 }
コード例 #21
0
 private static void setUpVBOs() {
   int[] vbos;
   try {
     model = OBJLoader.loadModel(new File(MODEL_LOCATION));
     int vboVertexHandle = glGenBuffers();
     int vboNormalHandle = glGenBuffers();
     FloatBuffer vertices = BufferTools.reserveData(model.faces.size() * 9);
     FloatBuffer normals = BufferTools.reserveData(model.faces.size() * 9);
     for (Face face : model.faces) {
       vertices.put(BufferTools.asFloats(model.vertices.get((int) face.vertex.x - 1)));
       vertices.put(BufferTools.asFloats(model.vertices.get((int) face.vertex.y - 1)));
       vertices.put(BufferTools.asFloats(model.vertices.get((int) face.vertex.z - 1)));
       normals.put(BufferTools.asFloats(model.normals.get((int) face.normal.x - 1)));
       normals.put(BufferTools.asFloats(model.normals.get((int) face.normal.y - 1)));
       normals.put(BufferTools.asFloats(model.normals.get((int) face.normal.z - 1)));
     }
     vertices.flip();
     normals.flip();
     glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
     glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
     glEnableVertexAttribArray(attributeVertex);
     glVertexAttribPointer(attributeVertex, 3, false, 0, vertices);
     glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
     glEnableVertexAttribArray(attributeNormal);
     glBufferData(GL_ARRAY_BUFFER, normals, GL_STATIC_DRAW);
     glNormalPointer(GL_FLOAT, 0, 0L);
     // TODO: This really isn't finished yet. :-(
   } catch (FileNotFoundException e) {
     e.printStackTrace();
     cleanUp();
     System.exit(1);
   } catch (IOException e) {
     e.printStackTrace();
     cleanUp();
     System.exit(1);
   }
 }
コード例 #22
0
 private static void setUpDisplayLists() {
   bunnyDisplayList = glGenLists(1);
   glNewList(bunnyDisplayList, GL_COMPILE);
   {
     Model m = null;
     try {
       m = OBJLoader.loadModel(new File(MODEL_LOCATION));
     } catch (FileNotFoundException e) {
       e.printStackTrace();
       Display.destroy();
       System.exit(1);
     } catch (IOException e) {
       e.printStackTrace();
       Display.destroy();
       System.exit(1);
     }
     glColor3f(0.4f, 0.27f, 0.17f);
     glBegin(GL_TRIANGLES);
     for (Face face : m.faces) {
       Vector3f n1 = m.normals.get((int) face.normal.x - 1);
       glNormal3f(n1.x, n1.y, n1.z);
       Vector3f v1 = m.vertices.get((int) face.vertex.x - 1);
       glVertex3f(v1.x, v1.y, v1.z);
       Vector3f n2 = m.normals.get((int) face.normal.y - 1);
       glNormal3f(n2.x, n2.y, n2.z);
       Vector3f v2 = m.vertices.get((int) face.vertex.y - 1);
       glVertex3f(v2.x, v2.y, v2.z);
       Vector3f n3 = m.normals.get((int) face.normal.z - 1);
       glNormal3f(n3.x, n3.y, n3.z);
       Vector3f v3 = m.vertices.get((int) face.vertex.z - 1);
       glVertex3f(v3.x, v3.y, v3.z);
     }
     glEnd();
   }
   glEndList();
 }
コード例 #23
0
  private void createDisplay() {

    winWidth = 800;
    winHeight = 600;

    try {
      Display.setDisplayMode(new DisplayMode(winWidth, winHeight));
      Display.setTitle("Particle World, FPS: ");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(0);
    }
    glEnable(GL_LINE_SMOOTH);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_TEXTURE_2D);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, winWidth, winHeight, 0, 1, -1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
  }
コード例 #24
0
  @Override
  protected void onStart() {
    INSTANCE = this;

    RENDER_THREAD_ID = Thread.currentThread().getId();

    try {
      loadIcons();
      Display.setIcon(icons);
      Display.setVSyncEnabled(GameSettings.Graphics.vsync);
    } catch (IOException e) {
      e.printStackTrace();
    }

    try {
      setDisplayMode(
          GameSettings.Display.window_width,
          GameSettings.Display.window_height,
          GameSettings.Display.fullscreen);
      Display.create();
      // ROBO //todo get all this changed to proper OGL
      glClearColor(0f, 0f, 0f, 1f);
      glClearDepth(1f);
      glViewport(0, 0, GameSettings.Display.window_width, GameSettings.Display.window_height);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();

      glOrtho(
          0.0f,
          GameSettings.Display.resolution.getWidth(),
          GameSettings.Display.resolution.getHeight(),
          0.0f,
          0.1f,
          -1f);
      glMatrixMode(GL_MODELVIEW);
      glEnable(GL_TEXTURE_2D);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
      glLoadIdentity();
      curAlpha = 1f;
      capabilities = GLContext.getCapabilities();

      System.out.println("OpenGL version: " + glGetString(GL_VERSION));

      System.out.println("Building shaders..");
      long ms = getTime();
      ShaderFactory.buildAllShaders();
      System.out.println("Done! Took " + (getTime() - ms) + "ms.");

    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(0);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(0);
    } finally {
      if (looping) {
        looping = false;
        Display.destroy();
      }
    }

    started = getTime();
    next_tick = getTime();
    getDelta();
  }
コード例 #25
0
ファイル: Gears.java プロジェクト: RELO4D3D/sdk-dist
 public static void main(String[] args) {
   new Gears().execute();
   System.exit(0);
 }