java菜单栏变成白色_java-将精灵颜色更改为白色

如果要将精灵中所有形状的颜色更改为白色,则唯一的方法是使用像素着色器并将所有非黑色的片段设置为黑色(我假设黑色在您的游戏中呈现为透明) )到白色.像这样:

varying vec4 v_color;

varying vec2 v_texCoords;

uniform sampler2D u_texture;

void main() {

vec4 color=v_color * texture2D(u_texture, v_texCoords);

if(color.r!=0 && color.g!=0 && color.b!=0){

gl_FragColor=vec4(1,1,1,1);

}

else{

gl_FragColor=color;

}

}

如果您很不幸并且使用的是opengl 1.0(固定管道),我建议您现在就开始使用gles 2.0.固定管道是从90’开始的,我们现在是2013年!

编码:

初始化:

ShaderProgram.pedantic = false;

ShaderProgram defaultShader=SpriteBatch.createDefaultShader();

ShaderProgram shaderWhiteTexture=new ShaderProgram(Gdx.files.internal("vertexShader.vs").readString(),Gdx.files.internal("fragShader.fs").readString());

渲染:

//Render the textures with the normal colors

spriteBatch.begin();

spriteBatch.draw(sprite1,sprite2,sprite3...);//or whatever code u use to render them

spriteBatch.end();

//Render the textures with the shader

spriteBatch.setShader(shaderWhiteTexture);

spriteBatch.begin();

spriteBatch.draw(sprite4,sprite5,sprite6...);//or whatever code u use to render them

spriteBatch.end();

spriteBatch.setShader(defaultShader);

着色器:

//vertexShader.vs:

attribute highp vec4 a_position;

attribute highp vec4 a_color;

attribute highp vec2 a_texCoord0;

uniform mat4 u_projTrans;

varying highp vec4 v_color;

varying highp vec2 v_texCoords;

void main() {

v_color = a_color;

v_texCoords = a_texCoord0;

gl_Position = u_projTrans * a_position ;

}

//fragShader.fs:

varying highp vec4 v_color;

varying highp vec2 v_texCoords;

uniform sampler2D u_texture;

void main() {

gl_FragColor = vec4(0.0);

highp vec4 color = texture2D(u_texture, v_texCoords);

if(color.a > 0.0) {

gl_FragColor = vec4(1.0,0,0,1.0);

}

}

由问题所有者编辑:现在可以使用透明纹理

添加了什么? :

1 . the highp precision to variables

2 . the fragmentShader file Main() fonction edited

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值