I'm thinking about trying to create fog for my game but I'm not sure how to go about it.
It's only a 2D game that I'm experimenting with and so far I've been looking into OpenGL Fog but I haven't been able to get that working just yet.
I basically followed this tutorial:
http://www.swiftless.com/tutorials/opengl/fog.html just I'm unsure how to get that to work with 2D alongside SpriteBatches (Using LibGDX) and things.
Example of how I'm currently trying to achieve this:
1 2 3 4 5 6 7 8 9 10 11
| public void drawFog(){ float fogDensity = 0.3f; float fogColour[] = {0.5f, 0.5f, 0.5f, 1f}; gl.glEnable (gl.GL_DEPTH_TEST); gl.glEnable(gl.GL_FOG); gl.glFogf(gl.GL_FOG_MODE, gl.GL_EXP2); gl.glFogfv(gl.GL_FOG_COLOR, fogColour, 0); gl.glFogf(gl.GL_FOG_DENSITY, fogDensity); gl.glHint(gl.GL_FOG_HINT, gl.GL_NICEST); gl.glLoadIdentity(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public void render(float delta){
gl.glClear(GL10.GL_COLOR_BUFFER_BIT); gl.glClearColor(0f, 0f, 0f, 1f); gl.glViewport((int) glViewport.x, (int) glViewport.y, (int) glViewport.width, (int) glViewport.height); cam.update(); originalCamera.update(); batch.setProjectionMatrix(relProjection()); drawFog(); batch.begin(); for(int i = 0; i < entities.size(); i++){ entities.get(i).draw(batch); } batch.end(); } |