{"action":"closed","issue":{"url":"https://api.github.com/repos/libgdx/libgdx/issues/2432","labels_url":"https://api.github.com/repos/libgdx/libgdx/issues/2432/labels{/name}","comments_url":"https://api.github.com/repos/libgdx/libgdx/issues/2432/comments","events_url":"https://api.github.com/repos/libgdx/libgdx/issues/2432/events","html_url":"https://github.com/libgdx/libgdx/issues/2432","id":45183889,"number":2432,"title":"Spritebatch and Shaders disordering.","user":{"login":"Oyatsumi","id":8701389,"avatar_url":"https://avatars.githubusercontent.com/u/8701389?v=3","gravatar_id":"","url":"https://api.github.com/users/Oyatsumi","html_url":"https://github.com/Oyatsumi","followers_url":"https://api.github.com/users/Oyatsumi/followers","following_url":"https://api.github.com/users/Oyatsumi/following{/other_user}","gists_url":"https://api.github.com/users/Oyatsumi/gists{/gist_id}","starred_url":"https://api.github.com/users/Oyatsumi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Oyatsumi/subscriptions","organizations_url":"https://api.github.com/users/Oyatsumi/orgs","repos_url":"https://api.github.com/users/Oyatsumi/repos","events_url":"https://api.github.com/users/Oyatsumi/events{/privacy}","received_events_url":"https://api.github.com/users/Oyatsumi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/libgdx/libgdx/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2014-10-07T23:12:53Z","updated_at":"2015-02-02T18:01:12Z","closed_at":"2015-02-02T18:01:12Z","body":"Hello, I've opened the following issue: https://github.com/libgdx/libgdx/issues/2367\r\nIt was then closed and I reposted and got no response from it.\r\nI don't know exactly if I was supposed to create a new issue or not, sorry if wasn't. So, could someone clarify these points?\r\nI would be very glad.\r\nThank you.\r\n\r\nThe actual comment I posted on the previous issue ->\r\n\r\n\r\nI think there is something pretty strange with the behavior of the framebuffer. I tried to boil it down for testing and I apparently found a new issue.\r\n\r\nThe blending functions here are the same I used on my game (http://www.mediafire.com/download/x7qqa3z5h4ilbsu/jogo37_frameskip=10-shadow=true.jar), which is running fine on windows.\r\n\r\nThe code went like that:\r\n\t\r\n\t\r\n\tfinal static String VERT =  \r\n\t\t\t\"attribute vec4 \"+ShaderProgram.POSITION_ATTRIBUTE+\";\\n\" +\r\n\t\t\t\"attribute vec4 \"+ShaderProgram.COLOR_ATTRIBUTE+\";\\n\" +\r\n\t\t\t\"attribute vec2 \"+ShaderProgram.TEXCOORD_ATTRIBUTE+\"0;\\n\" +\r\n\t\t\t\r\n\t\t\t\"uniform mat4 u_projTrans;\\n\" + \r\n\t\t\t\" \\n\" + \r\n\t\t\t\"varying vec4 vColor;\\n\" +\r\n\t\t\t\"varying vec2 vTexCoord;\\n\" +\r\n\t\t\t\r\n\t\t\t\"void main() {\\n\" +  \r\n\t\t\t\"\tvColor = \"+ShaderProgram.COLOR_ATTRIBUTE+\";\\n\" +\r\n\t\t\t\"\tvTexCoord = \"+ShaderProgram.TEXCOORD_ATTRIBUTE+\"0;\\n\" +\r\n\t\t\t\"\tgl_Position =  u_projTrans * \" + ShaderProgram.POSITION_ATTRIBUTE + \";\\n\" +\r\n\t\t\t\"}\";\r\n\t\r\n\tfinal static String FRAG = \r\n\t\t\t//GL ES specific stuff\r\n\t\t\t  \"#ifdef GL_ES\\n\" //\r\n\t\t\t+ \"#define LOWP lowp\\n\" //\r\n\t\t\t+ \"precision mediump float;\\n\" //\r\n\t\t\t+ \"#else\\n\" //\r\n\t\t\t+ \"#define LOWP \\n\" //\r\n\t\t\t+ \"#endif\\n\" + //\r\n\t\t\t\"//texture 0\\n\" + \r\n\t\t\t\"uniform sampler2D u_texture;\\n\" + \r\n\t\t\t\"\\n\" + \r\n\t\t\t\"//our screen resolution, set from Java whenever the display is resized\\n\" + \r\n\t\t\t\"uniform vec2 resolution;\\n\" + \r\n\t\t\t\"\\n\" + \r\n\t\t\t\"//screen color RGB(Intensity)\\n\" + \r\n\t\t\t\"uniform LOWP vec4 ambient; \\n\" + \r\n\t\t\t\"\\n\" + \r\n\t\t\t\"//\\\"in\\\" attributes from our vertex shader\\n\" + \r\n\t\t\t\"varying LOWP vec4 vColor;\\n\" +\r\n\t\t\t\"varying vec2 vTexCoord;\\n\" + \r\n\t\t\t\"\\n\" + \r\n\t\t\t\"//RADIUS of our vignette, where 0.5 results in a circle fitting the screen\\n\" + \r\n\t\t\t\"const float RADIUS = 0.75;\\n\" + \r\n\t\t\t\"\\n\" + \r\n\t\t\t\"//softness of our vignette, between 0.0 and 1.0\\n\" + \r\n\t\t\t\"const float SOFTNESS = 0.75;\\n\" + \r\n\t\t\t\"\\n\" + \r\n\t\t\t\"void main() {\\n\" + \r\n\t\t\t\"\t//sample our texture\\n\" + \r\n\t\t\t\"\tvec4 texColor = texture2D(u_texture, vTexCoord);\\n\" + \r\n\t\t\t\"\t\t\\n\" + \r\n\t\t\t\"\t//1. VIGNETTE\\n\" + \r\n\t\t\t\"\t\\n\" + \r\n\t\t\t\"\t//determine center position\\n\" + \r\n\t\t\t\"\tvec2 position = (gl_FragCoord.xy / resolution.xy) - vec2(0.5);\\n\" + \r\n\t\t\t\"\t\\n\" + \r\n\t\t\t\"\t//determine the vector length of the center position\\n\" + \r\n\t\t\t\"\tfloat len = length(position);\\n\" + \r\n\t\t\t\"\t\\n\" + \r\n\t\t\t\"\t//use smoothstep to create a smooth vignette\\n\" + \r\n\t\t\t\"\tfloat vignette = smoothstep(RADIUS, RADIUS-SOFTNESS, len);\\n\" + \r\n\t\t\t\"\t\\n\" + \r\n\t\t\t\"\t//apply the vignette with 60% opacity\\n\" + \r\n\t\t\t\"\ttexColor.rgb = mix(texColor.rgb, texColor.rgb * vignette, 0.6);\\n\" + \r\n\t\t\t\"\t\t\\n\" + \r\n\t\t\t\"\t//2. GRAYSCALE\\n\" + \r\n\t\t\t\"\t\\n\" +\r\n\t\t\t\"\t//convert to grayscale using NTSC conversion weights\\n\" + \r\n\t\t\t\"\tfloat gray = dot(texColor.rgb, vec3(0.299, 0.587, 0.114));\\n\" + \r\n\t\t\t\"\t\\n\" + \r\n\t\t\t\"\t//create our sepia tone from some constant value\\n\" + \r\n\t\t\t\"\tvec3 sepiaColor = vec3(gray) * ambient.rgb;\\n\" + \r\n\t\t\t\"\t\t\\n\" + \r\n\t\t\t\"\t//again we'll use mix so that the sepia effect is at somewhere\\n\" + \r\n\t\t\t\"\ttexColor.rgb = mix(texColor.rgb, sepiaColor, ambient.a);\\n\" + \r\n\t\t\t\"\t\t\\n\" + \r\n\t\t\t\"\t//final colour, multiplied by vertex colour\\n\" + \r\n\t\t\t\"\tgl_FragColor = texColor * vColor;\\n\" + \r\n\t\t\t\"}\";\r\n\t\r\n\t@Override\r\n\tpublic void resize(int width, int height) {\r\n\t\toc.setToOrtho(false, width, height);\r\n\t\tbatch.setProjectionMatrix(oc.combined);\r\n\t}\r\n\t@Override\r\n\tpublic void create(){\r\n\t\tshader = new ShaderProgram(VERT, FRAG);\r\n\t\tbatch = new SpriteBatch();\r\n\t\tframeBuffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);\r\n\t\toc = new OrthographicCamera();  \r\n\t\toc.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r\n\t}\r\n\tpublic ShaderProgram shader = null;\r\n\tpublic SpriteBatch batch = null;\r\n\tpublic FrameBuffer frameBuffer = null;\r\n\tOrthographicCamera oc = null;\r\n\t@Override\r\n\tpublic void render() {\r\n\t\tGdx.gl.glClearColor(0f, 0f, 0f, 0f);\r\n\t    Gdx.gl.glClear(Gdx.gl.GL_COLOR_BUFFER_BIT);\r\n\t    \r\n\t    Texture mario1 = new Texture(Gdx.files.internal(\"data/mario.png\")),\r\n\t    \t\tmario2 = new Texture(Gdx.files.internal(\"data/mario.png\")),\r\n\t    \t\tmario3 = new Texture(Gdx.files.internal(\"data/mario.png\")),\r\n\t    \t\tmario4 = new Texture(Gdx.files.internal(\"data/mario.png\")),\r\n\t    \t\tmario5 = new Texture(Gdx.files.internal(\"data/mario.png\")),\r\n\t    \t\tmario6 = new Texture(Gdx.files.internal(\"data/mario.png\"));\r\n\t    \r\n\t    shader.begin();\r\n\t\tshader.setUniformf(\"ambient\", 1.2f, 1.0f, 0.8f, 1.0f);\r\n\t\t\r\n\t\r\n\t\t\r\n\t\tbatch.setBlendFunction(GL20.GL_SRC_ALPHA,\r\n                GL20.GL_ONE_MINUS_SRC_ALPHA);\r\n\t\tGdx.gl20.glBlendFuncSeparate(GL20.GL_SRC_ALPHA,\r\n                GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);\r\n\t\t\r\n\t\t\r\n\t\tbatch.setProjectionMatrix(oc.combined);\r\n\t\t\r\n\t\t\r\n\t\tbatch.begin();\r\n\r\n\r\n\t\t//1\r\n\t    batch.draw(mario1, 0, 0);\r\n\t    \r\n\t    frameBuffer.begin();\r\n\t    \r\n\t    \r\n\t    //2\r\n\t    batch.draw(mario2, mario1.getWidth(), 0);\r\n\t    \r\n\t    batch.setShader(shader);\r\n\t    \r\n\t    //3\r\n\t    batch.draw(mario3, mario1.getWidth()*2, 0);\r\n\t    \r\n        batch.setBlendFunction(GL20.GL_SRC_ALPHA,\r\n                GL20.GL_ONE); //ignore the batch blend function\r\n        Gdx.gl20.glBlendFuncSeparate(GL20.GL_SRC_ALPHA,\r\n                GL20.GL_ONE, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);\r\n        \r\n        //4\r\n        batch.draw(mario4, 0, mario1.getHeight());\r\n        \r\n        batch.setBlendFunction(GL20.GL_SRC_ALPHA,\r\n                GL20.GL_ONE_MINUS_SRC_ALPHA); //ignore the batch blend function\r\n        Gdx.gl20.glBlendFuncSeparate(GL20.GL_SRC_ALPHA,\r\n                GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);\r\n\r\n        Sprite fB = new Sprite(frameBuffer.getColorBufferTexture());\r\n        fB.flip(false, true);\r\n        batch.draw(fB, 0, 0, frameBuffer.getColorBufferTexture().getWidth(), frameBuffer.getColorBufferTexture().getHeight());\r\n        frameBuffer.end();\r\n       \r\n        \r\n        //5\r\n        batch.draw(mario5, mario3.getWidth(), mario1.getHeight());\r\n        \r\n        batch.setShader(null);\r\n        \r\n        //6\r\n        batch.draw(mario5, mario3.getWidth()*2, mario1.getHeight());\r\n\r\n        batch.end();\r\n\t\t\r\n\t\tmario1.dispose(); mario2.dispose(); mario3.dispose(); mario4.dispose(); mario5.dispose(); mario6.dispose();\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void pause() {\r\n\t\t\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void resume() {\r\n\t\t// TODO Auto-generated method stub\r\n\t\t\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void dispose() {\r\n\t\t// TODO Auto-generated method stub\r\n\t\t\r\n\t}\r\n\r\n\r\n\r\n\r\n\r\nAnd I get this (look, only the mario 5 and 6 are being \"rendered\").\r\nhttp://s15.postimg.org/qifzzor23/mario1.png\r\n\r\n\r\nwhen I take the frameBuffer.begin() and frameBuffer.end() lines and remove them, I get this:\r\nhttp://s28.postimg.org/6dtbws1yl/mario1.png\r\nWhere all marios appear on the screen.\r\n\r\nBy removing the blendfunctions, all of them, and also keeping the frameBuffer.begin() and frameBuffer.end(). I get this:\r\nhttp://s21.postimg.org/q71ziamsn/mario1.png\r\nMario 1, 2 and 3 do not appear.\r\nIs this supposed to happen?\r\n\r\nIf I shift the frameBuffer.being() priorly to the batch.being(), I also get the same previous screen.\r\n\r\nIf I keep the blendfunctions deleted and the lines frameBuffer.begin() and frameBuffer.end() intact and I dont use the shader, then I get the following result:\r\nhttp://s29.postimg.org/nb5aaub5z/mario1.png\r\n\r\nMy question is: Is that supposed to happen? Mario 1, 2, 3 and also 4 not being rendered? If so, why that?\r\n\r\nThank you in advance.\r\nPS.: I was running on a windows 8 for now.\r\nHeres the mario png if necessary: http://s30.postimg.org/qvhwvvt35/novo.png\r\nPS2.: Libgdx 1.3.1"}}