/** * @param simulation * @param gl */ private void renderHud(GL10 gl) { gl.glDisable(GL10.GL_CULL_FACE); gl.glDisable(GL10.GL_DEPTH_TEST); int width = Gdx.app.getGraphics().getWidth(); int height = Gdx.app.getGraphics().getHeight(); // spriteBatch.setProjectionMatrix(viewMatrix); // spriteBatch.setTransformMatrix(transformMatrix); spriteBatch.begin(); spriteBatch.enableBlending(); spriteBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); /*A minimum of dataset B maximum of dataset a is from where you would like normalised data set to start b is where you would like normalised data set to end x is the value you are trying to normalise a + (x-A)*(b-a)/(B-A) */ float length = 0 + (progress - 0) * ((Gdx.graphics.getWidth() / 10) * 8 - 0) / (1 - 0); spriteBatch.setColor(0, 0, 1, 1); spriteBatch.draw( progressBarTexture, Gdx.graphics.getWidth() / 10, 110, (Gdx.graphics.getWidth() / 10) * 8, 30); spriteBatch.setColor(0, 1, 1, 1); spriteBatch.draw(progressBarTexture, (Gdx.graphics.getWidth() / 10) + 2, 112, length, 26); spriteBatch.setColor(1, 1, 1, 1); font.draw(spriteBatch, "Version:" + BattleBeasties3d.version, 10, 10); font.draw(spriteBatch, "Loading " + String.format("%.0f", progress * 100) + "%", 100, 100); if (Splash.fadeIn) { spriteBatch.setColor(0, 0, 0, Splash.fadeTimer); spriteBatch.draw(xfadeTexture, 0, 0, width, height); } if (Splash.fadeOut) { spriteBatch.setColor(1, 1, 1, Splash.fadeTimer); spriteBatch.draw(xfadeTexture, 0, 0, width, height); } spriteBatch.setColor(1, 1, 1, 1); if (BattleBeasties3d.Error == BattleBeasties3d.NETWORK_DOWN && netErrorShown == false) { stage.addActor( Actors.bottomToast( "Connection to internet failed, Please check your network is working.", 5, skin)); netErrorShown = true; } spriteBatch.end(); }
private void renderSun(GL10 gl, float radius, float x, float y, float z, Application app) { gl.glDisable(GL10.GL_LIGHTING); radius = radius * worldscale; sunTexture.bind(); gl.glPushMatrix(); // move away from origin gl.glTranslatef(x, y, z); // scale to size of earth gl.glScalef(radius, radius, radius); gl.glDisable(GL10.GL_CULL_FACE); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE); gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); // gl.glRotatef((Splash.planetmove/10), .25f, .75f, .5f); sunMesh.render(GL10.GL_TRIANGLES); gl.glPopMatrix(); gl.glEnable(GL10.GL_LIGHTING); gl.glEnable(GL10.GL_CULL_FACE); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); }
private void renderSky(GL10 gl) { gl.glDisable(GL10.GL_LIGHTING); skyTexture.bind(); gl.glColor4f(1, 1, 1, 1); gl.glPushMatrix(); gl.glTranslatef(0, 0, 0); gl.glScalef(100f, 100f, 100f); skyMesh.render(GL10.GL_TRIANGLES); gl.glPopMatrix(); gl.glEnable(GL10.GL_LIGHTING); }
private void renderInsideStation(Application app) { GL10 gl = app.getGraphics().getGL10(); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glViewport(0, 0, app.getGraphics().getWidth(), app.getGraphics().getHeight()); gl.glEnable(GL10.GL_BLEND); gl.glDisable(GL10.GL_DITHER); gl.glEnable(GL10.GL_DEPTH_TEST); gl.glEnable(GL10.GL_CULL_FACE); setStaticProjectionAndCamera(app.getGraphics(), app, gl); setLighting(gl); gl.glEnable(GL10.GL_TEXTURE_2D); renderSky(gl); renderPlanet(gl, "sun", true, 1737f, Splash.planetmove - 150, 0, -2500, app); renderSky(gl); gl.glDisable(GL10.GL_DITHER); gl.glDisable(GL10.GL_CULL_FACE); // do alpha models after this renderStaticShip(gl, app); renderSun(gl, 70000f, -1600, 0, -4500, app); gl.glDisable(GL10.GL_TEXTURE_2D); renderHud(gl); }
/** * render ship jets * * @param basescale :- scale factor for jet size before applying thrust * @param length :- scale factor for jet length, typically thrust value + random noise * @param x The jet's x-coordinate. * @param y The jet's y-coordinate. * @param z The jet's z-coordinate. * @return The product, in a vector <#, #, #, 1>, representing the rotated point. */ private void renderJet( GL10 gl, float baseScale, float length, float x, float y, float z, Application app) { jetTexture.bind(); gl.glPushMatrix(); // move away from origin gl.glTranslatef(x, y, z); // scale to size of earth gl.glScalef(baseScale, baseScale, baseScale * length); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE); gl.glDisable(GL10.GL_LIGHTING); // gl.glRotatef((Splash.planetmove/10), .25f, .75f, .5f); jetMesh.render(GL10.GL_TRIANGLES); gl.glPopMatrix(); gl.glEnable(GL10.GL_LIGHTING); // gl.glEnable(GL10.GL_DEPTH_TEST); }
/** * This method is responsible for OpenGL rendering mechanism. Adds lighting to the world. Checks * rigidBody map for proper collisionshapes (like SphereShape or BoxShape). */ public void render(float delta) { float[] light_ambient = new float[] {1.5f, 1.5f, 1.5f, 1.5f}; float[] light_diffuse = new float[] {1.0f, 1.0f, 1.0f, 1.0f}; float[] light_specular = new float[] {1.0f, 1.0f, 1.0f, 1.0f}; float[] light_position0 = new float[] {1.0f, 10.0f, 1.0f, 0.0f}; light_position0[0] = position.x + 10; light_position0[1] = position.y; light_position0[2] = position.z; float x = 0.0f, z = 0.0f; GL10 gl = Gdx.graphics.getGL10(); deltaTime = Gdx.graphics.getDeltaTime(); Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, light_ambient, 0); Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, light_diffuse, 0); Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, light_specular, 0); Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, light_position0, 0); Gdx.graphics.getGL11().glEnable(GL10.GL_LIGHTING); Gdx.graphics.getGL11().glEnable(GL10.GL_LIGHT0); Gdx.gl.glEnable(GL10.GL_DEPTH_TEST); Gdx.gl.glEnable(GL10.GL_CULL_FACE); Gdx.gl.glEnable(GL10.GL_TEXTURE_2D); startTime = System.nanoTime(); rigidBody = physics.doSimulation(deltaTime, 1); endTime = (System.nanoTime() - startTime) / 1000000000.0f; for (RigidBody body : rigidBody.values()) { if (body.geometry.shape.getType() == ShapeType.BOX_SHAPE_PROXYTYPE) { gl.glPushMatrix(); body.motionState.resultSimulation.getOpenGLMatrix(glMat); gl.glMultMatrixf(glMat, 0); wallShapeZ = (BoxShape) body.geometry.shape; wood.bind(); gl.glRotatef(270, 1, 0, 0); gl.glScalef(7, 7, 7); wall.render(GL10.GL_TRIANGLES); gl.glPopMatrix(); } if (body.geometry.shape.getType() == ShapeType.STATIC_PLANE_PROXYTYPE) { gl.glPushMatrix(); body.motionState.resultSimulation.getOpenGLMatrix(glMat); gl.glMultMatrixf(glMat, 0); groundShape = (StaticPlaneShape) body.geometry.shape; stone.bind(); gl.glRotatef(270, 1, 0, 0); gl.glScalef(6f, 6f, 6f); plane.render(GL10.GL_TRIANGLES); gl.glPopMatrix(); } if (body.geometry.shape.getType() == ShapeType.SPHERE_SHAPE_PROXYTYPE) { gl.glPushMatrix(); sphereMovement(body); body.motionState.resultSimulation.getOpenGLMatrix(glMat); gl.glMultMatrixf(glMat, 0); x = body.motionState.resultSimulation.originPoint.x; z = body.motionState.resultSimulation.originPoint.z; if ((x >= 19.0 && x <= 26.5) && (z >= 8.4 && z <= 8.6)) { Gdx.app.log("Zwyciestwo", "lolol"); } if (indexior == 0) black.bind(); else if (indexior == 1) green.bind(); else if (indexior == 2) pink.bind(); else if (indexior == 3) steel.bind(); else if (indexior == 4) maja.bind(); sphere.render(GL10.GL_TRIANGLES); gl.glPopMatrix(); cameraSetup(body); } } if (Gdx.input.justTouched()) { FileHandle fh = Gdx.files.local("ala.txt"); fh.writeString( String.valueOf(x) + " " + String.valueOf(z) + " " + String.valueOf(indexior), false); game.setScreen(new MenuScreen(game)); } gl.glPushMatrix(); gl.glTranslatef(22.0f, -10.0f, 8.5f); gl.glScalef(1.0f, 1.0f, 1.0f); gl.glRotatef(270, 1, 0, 0); aim.bind(); target.render(GL10.GL_TRIANGLES); gl.glPopMatrix(); gl.glDisable(GL10.GL_CULL_FACE); gl.glDisable(GL10.GL_DEPTH_TEST); }