public void render2D(int dfps) { // GL.drawTexture(grass, 50, 50, 0, 11); GL.pushAttribute(GL.CURRENT_BIT); { GL.setColori(255 - brightness, 255 - brightness, 255 - brightness, 255); if (player.getActiveGun() != null) { String gunAmmo = player.getActiveGun().getClipAmmo() + "/" + player.getActiveGun().getIdleAmmo(); String dots = ""; for (int i = 1; i < 3 + 1; i++) { if (dfps > (i * 10)) { dots += "."; } else { dots += " "; } } font.render(gunAmmo, 0, 0, 0, 5f); if (player.getActiveGun().isReloading()) { font.render( "Reloading" + dots, font.getGlyphWidth() * (gunAmmo.length() + 1) * 5f, 0, 0, 5f); } } font.render("+", 0, 0, 0, 4, Font.CENTER, Font.CENTER); font.render("FPS: " + Frame.getFps(), 0, 0, 0, 2, Font.RIGHT, Font.TOP); } GL.popAttribute(); }
private void inits() { // int w = 800; // int h = 600; // try // { // Display.setDisplayMode(new DisplayMode(w, h)); // Display.setVSyncEnabled(true); // Display.setTitle("Loading Animation from Blender 2.5"); // Display.create(); // } // catch (Exception e) // { // System.out.println("Error setting up display"); // System.exit(0); // } // // GL11.glEnable(GL11.GL_TEXTURE_2D); // // GL11.glViewport(0, 0, w, h); // GL11.glMatrixMode(GL11.GL_PROJECTION); // GL11.glLoadIdentity(); // GLU.gluPerspective(45.0f, ((float) w / (float) h), 0.1f, 100.0f); // GL11.glMatrixMode(GL11.GL_MODELVIEW); // GL11.glLoadIdentity(); // // GL11.glShadeModel(GL11.GL_SMOOTH); // GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // GL11.glClearDepth(1.0f); // GL11.glEnable(GL11.GL_DEPTH_TEST); // GL11.glDepthFunc(GL11.GL_LEQUAL); // GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL.initBasicLights(); GL.setRender3D(true); }
public void render3D(int dfps) { player.lookThrough(); // camera.lookThrough(); player.render(); map.render(camera.getLocation(), dfps); GL.setLightLocation(GL.LIGHT0, player.getLocation()); // GL.setLightLocation(GL.LIGHT1, new Point(-2, 2, 4)); // GL.setLightLocation(player.getX() + player.getCenterX(), player.getY() + // player.getCenterY(), player.getZ() + player.getCenterZ()); // if (pic) // { // pic = false; // GL.endScreenCapture(); // } // if (KeyboardInput.isKeyDown(KeyboardInput.KEY_H)) // { // pic = true; // // int id = GL.beginScreenCapture(); // // texture = new Texture(id); // } }
/** * The initialization method for the Building class. Creates the visual aspects of the building, * such as the background and foreground objects (if any). * * @param spriteX The x position of the house on the sprite-sheet in pixels divided by 10. * @param spriteY The y position of the house on the sprite-sheet in pixels divided by 10. * @param width The houses width in pixels divided by 10. * @param height The houses height in pixels divided by 10. */ private void init(byte spriteX, byte spriteY, byte width, byte height) { verticesBuffer = new VerticesBuffer(OBJECT_SIZE, 3); // verticesBuffer.setBuffer(BufferUtils.createFloatBuffer(OBJECT_SIZE)); // verticesBuffer.init(); texturesBuffer = new LightBuffer(OBJECT_SIZE); // texturesBuffer.setBuffer(BufferUtils.createFloatBuffer(OBJECT_SIZE)); // texturesBuffer.init(); // float vertices[] = verticesBuffer.getElements(); // float textures[] = texturesBuffer.getElements(); verticesBuffer.addData( GL.addRectVertexArrayf(0, 0, width * tileSize, height * tileSize, 0, null)); texturesBuffer.addData( GL.addRectTextureArrayf(buildings, spriteX, spriteY, width, height, 0, null)); // map = new BuildingMap(this, idk); }
public Bullet(String location, Ship shotFrom) { super(new Texture(location)); thisBullet = this; this.shotFrom = shotFrom; this.location = location; float width = getWidth(); float height = getHeight(); setVerticesBuffer(new VerticesBuffer(4 * 2, 2)); setTexturesBuffer(new LightBuffer(4 * 2)); LightBuffer verticesBuffer = getVerticesBuffer(); LightBuffer texturesBuffer = getTexturesBuffer(); verticesBuffer.setData(0, GL.addRectVertexArrayf(0, 0, width, height, 0, null)); texturesBuffer.setData(0, GL.addRectTextureArrayf(getTexture(), 0, null)); }
/** * Method used for rendering the outside of the building. Renders at the set position of the * building. */ public void render() { float dimensions[] = Idk.getViewDimensions(); float xo = dimensions[0]; float yo = dimensions[1]; float wid = dimensions[2]; float hei = dimensions[3]; if (!Intersects.rectangles( (int) x, (int) y, (int) (width * tileSize), (int) (height * tileSize), (int) xo, (int) yo, (int) wid, (int) hei)) { return; } GL.beginManipulation(); { GL.translatef(x, y, -8); // GL.beginTextureDraw(texturesBuffer.getId(), 2); // GL.beginVertexDraw (verticesBuffer.getId(), VERTEX_SIZE); // // buildings.bind(); GL.renderQuads(verticesBuffer, texturesBuffer, buildings, 0, 1); // GL.endVertexDraw(); // GL.endTextureDraw(); } GL.endManipulation(); }
public void onCreate() { brightness = 150; released = true; GL.setRender3D(true); AL.setMasterVolume(0.1f); map = new Map(); camera = new Camera(); camera.setMaxPitch(90); camera.setMinPitch(-90); camera.setCameraMode(Camera.XZ_ONLY); player = new Player(2, 2, 2, 1, 1, 1, map); player.attachCamera(camera); Gun pistol = new Pistol(map); pistol.addAmmo(2500); pistol.reload(false); player.addGun(pistol, true); player.move(0, 9, 0); font = new Font( "res/images/font/font.png", 26, 4, new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', '-', '+', '=', '~', '`', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '?', '>', '<', ';', ':', '\'', '"', '{', '}', '[', ']', '\\', '|', ',', '.', '/', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }); grass = new Texture("res/images/grass.png"); GL.initLighting(); GL.setShadeModel(GL.SMOOTH); GL.setAmbientLighti(brightness, brightness, brightness); GL.setLightProperties(); GL.addSpecular(GL.LIGHT0, new Point(0.35f, 0.35f, 0.35f)); // GL.addSpecular(GL.LIGHT1, new Point(01.0f, 01.0f, 01.0f)); // // GL.setShadeModel(GL.SMOOTH); // // GL.addLight(new Vector(0, 0, -1), 15); // frameBufferId = GL.genFrameBuffer(); texture = new Texture(0); GL.enablePolygonAntialiasing(); // GL.initBasicLights(); }
public void loop(int dfps) { float delta = 60f / Frame.getFps(); map.update(dfps, delta); // if (dfps == 0) // { // System.out.println(Frame.getFps()); // } if (MouseInput.isGrabbed()) { float dWheel = MouseInput.getDWheel(); if (dWheel != 0) { dWheel /= 112; if (player.cameraAttached() && player.getPerspective() == Actor.THIRD) { offsetY += -1 / 5f * dWheel; offsetZ += -5 / 5f * dWheel; if (offsetY > 0 && offsetZ > 0) { camera.move(0, -1 / 5f * dWheel, -5 / 5f * dWheel); } else { offsetY -= -1 / 5f * dWheel; offsetZ -= -5 / 5f * dWheel; } } brightness += dWheel * 2; brightness = brightness < 0 ? 0 : brightness; GL.setAmbientLighti(brightness, brightness, brightness); GL.setClearColori(brightness, brightness, brightness, 255); } float dx = MouseInput.getDX(); float dy = MouseInput.getDY(); player.setSprinting(KeyboardInput.isKeyDown(KeyboardInput.KEY_LEFT_SHIFT)); if (KeyboardInput.isKeyDown(KeyboardInput.KEY_W)) { player.move(0, 0, -0.1f * delta); } if (KeyboardInput.isKeyDown(KeyboardInput.KEY_A)) { player.move(-0.1f * delta, 0, 0); } if (KeyboardInput.isKeyDown(KeyboardInput.KEY_S)) { player.move(0, 0, 0.1f * delta); } if (KeyboardInput.isKeyDown(KeyboardInput.KEY_D)) { player.move(0.1f * delta, 0, 0); } if (KeyboardInput.isKeyDown(KeyboardInput.KEY_SPACE)) { player.jump(); } player.yaw(dx * 0.10f); player.pitch(-dy * 0.10f); if (KeyboardInput.next(KeyboardInput.KEY_C)) { if (player.getPerspective() == Player.THIRD) { player.setPerspective(Player.FIRST); } else if (player.getPerspective() == Player.FIRST) { player.setPerspective(Player.THIRD); } } if (KeyboardInput.next(KeyboardInput.KEY_L)) { map.render = map.render == GL.POINTS ? GL.TRIANGLES : GL.POINTS; } if (KeyboardInput.next(KeyboardInput.KEY_O)) { GL.setWireFrameMode(!GL.isWireFrame(), GL.isWireFrame(), true); // GL.setShowColors(!GL.isShowingColors()); } if (KeyboardInput.next(KeyboardInput.KEY_R)) { if (player.getActiveGun() != null) { Gun gun = player.getActiveGun(); if (gun.getIdleAmmo() > 0) { gun.reload(); } } } if (MouseInput.isButtonDown(MouseInput.LEFT_MOUSE_BUTTON)) { if (player.getActiveGun() != null) { if (releasedDelay > player.getActiveGun().getShotDelay() && (player.getActiveGun().getShotDelay() != -1 || released)) { player.useActiveWeapon(); released = false; releasedDelay = 0; } else { releasedDelay++; } } } else { released = true; } } if (MouseInput.isButtonDown(MouseInput.LEFT_MOUSE_BUTTON)) { MouseInput.setGrabbed(true); released = false; } if (KeyboardInput.isKeyDown(KeyboardInput.KEY_ESCAPE)) { MouseInput.setGrabbed(false); } // if (KeyboardInput.isKeyDown(KeyboardInput.KEY_R)) // { // if (player.cameraAttached()) // { // player.detachCamera(); // } // else // { // player.attachCamera(camera); // } // } if (KeyboardInput.next(KeyboardInput.KEY_F11)) { Frame.setFullscreen(!Frame.isFullscreen()); } // if (KeyboardInput.isKeyDown(KeyboardInput.KEY_K)) // { // player.deta // } // System.out.println(player.getYaw() + ", " + player.getPitch() + ", " + player.getRoll()); player.update(dfps, delta); }