dilix
dilix

Reputation: 3893

AndEngine - how to use standalone shaders

I've found andengine sample with blur effect and it works fine, i found that i can use ShaderProgram class and in PreDraw of the Sprite use some shaders (setShaders).

Can i use the same class ShaderProgramm and use shader without attach to sprite ?

For example in onDraw use Shader that only draw a grenn triangle on scene (like in android opengl example). Is there simple way to use ShaderProgram in this way (how can i attach shaders out of PreDraw of Sprite) ?

I've tried smth like this:

BrushShaderProgram bs = BrushShaderProgram.getInstance();
bs.link(pGLState);
GLES20.glUseProgram(bs.getId());
GLES20.glVertexAttribPointer(bs.maPositionHandle, 3, GLES20.GL_FLOAT, false, 12, triangleVB);
GLES20.glEnableVertexAttribArray(bs.maPositionHandle);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3);

shader is simple:

public static final String VERTEXSHADER =  
                "attribute vec4 vPosition; \n" +
                "void main(){              \n" +
                " gl_Position = vPosition; \n" +
                "}                         \n";

public static final String FRAGMENTSHADER = "precision mediump float;  \n" +
                "void main(){              \n" +
                " gl_FragColor = vec4 (0.63671875, 0.76953125, 0.22265625, 1.0); \n" +
                "}                         \n";

Upvotes: 0

Views: 1638

Answers (1)

Nicolas Gramlich
Nicolas Gramlich

Reputation: 2790

Why not create a Triangle class, just like the Rectangle class?

Upvotes: 2

Related Questions