我很高兴使用LibGDX Framework的SpriteBatch类.我的目标是通过着色器修改精灵的表示.
batch = new SpriteBatch(2, shaderProgram);
Run Code Online (Sandbox Code Playgroud)
我从SpriteBatch类中复制了默认着色器,并添加了另一个统一的Sampler 2d
+ "uniform sampler2D u_Texture2;\n"//
Run Code Online (Sandbox Code Playgroud)
是否有一种工作方式将纹理赋予着色器.这样做,总是在ClearColor屏幕中结束.
batch.begin();
texture2.bind(1);
shaderProgram.setUniformi("u_Texture2", 1);
batch.draw(spriteTexture,positions[0].x,positions[0].y);
batch.draw(spriteTexture,positions[1].x,positions[1].y);
batch.end();
Run Code Online (Sandbox Code Playgroud)
每个纹理都在工作.在Mesh类的帮助下手动绘制按预期工作.那么我该怎么做才能使用SpriteBatch的便利呢?
THX寻求帮助
我有点沮丧。我即将使用 mac(OS X 小牛)进行编码。
我的着色器在 windows 7 和 android 下运行良好。当我在 OS X 下运行我的应用程序时,我在运行时遇到以下编译器错误。
Exception in thread "LWJGL Application" java.lang.IllegalStateException: ERROR: 0:6: Initializer not allowed
ERROR: 0:6: Use of undeclared identifier 'light'
ERROR: 0:6: Use of undeclared identifier 'spec'
ERROR: 0:6: Use of undeclared identifier 'spec'
ERROR: 0:6: Use of undeclared identifier 'spec'
Run Code Online (Sandbox Code Playgroud)
片段着色器片段:
String fragmentShader =
"#ifdef GL_ES\n" +
"precision mediump float;\n" +
"#endif\n" +
"uniform sampler2D cubeMap;\n"+
"uniform sampler2D normalMap;"+
"varying vec2 v_TexCoords;"+
"void main() {\n"+
" const vec4 …Run Code Online (Sandbox Code Playgroud)