问题
I've been trying to figure out how to use OpenGL ES 2.0 for 2D. So far I think I have a handle on most things. But the one thing that I haven't figured out is what to do for the shaders?
I understand that you set up the camera/view and the lights in the shader, but I don't want shadows or any kind of sign of lighting. Basically I just want to move sprites around the screen and have the sprites look exactly like they did when I drew them in photoshop.
Anyone have an example of a shader that would do this? Or maybe an article that talks about this?
I already find that there's a lot of 3d overhead in OpenGL when trying to make a purely 2D program, but apparently it's the only viable option on Android.
回答1:
I made a 2D videogame and these are the shaders I used. Two very simple shaders. Is this what you asking for?
**VERTEX_SHADER_2D =**
attribute vec4 position;
attribute vec2 textureCoordIn;
varying vec2 vTextureCoordOut;
uniform mediump mat4 modelViewMatrix;
void main()
{
gl_Position = modelViewMatrix * position;
vTextureCoordOut = textureCoordIn;
}
**FRAGMENT_SHADER_2D =**
varying mediump vec2 vTextureCoordOut;
uniform sampler2D sampler;
void main()
{
gl_FragColor = texture2D(sampler, vTextureCoordOut);
}
来源:https://stackoverflow.com/questions/9714443/what-kind-of-shader-for-2d-games-ie-super-mario