Java 类com.badlogic.gdx.graphics.glutils.ShaderProgram 实例源码

项目:cocos2d-java    文件:Sprite.java   
@Override
public void onCommand(PolygonSpriteBatch batch) {
    if(_shaderProgram == null) {
        ShaderProgram p = GLProgramCache.getInstance().getSpriteBatchDefaultProgram();
        if(batch.getShader() != p) {
            batch.setShader(null);
        }
    } else {
        if(batch.getShader() != _shaderProgram) {
            batch.setShader(_shaderProgram);
        }
    }
    if(_sprite.getTexture() != null) {
        _sprite.draw(batch);
    }
}
项目:Planet-Generator    文件:Scene.java   
private void setupRendering() {
    ShaderProgram.pedantic = false;

    gameCamera = new OrthographicCamera();
    gameCamera.setToOrtho(false, BUFFER_WIDTH, BUFFER_HEIGHT);
    gameCamera.translate(EDITOR_OFFSET, 0);
    gameCamera.update();

    starCamera = new OrthographicCamera();
    starCamera.setToOrtho(false, BUFFER_WIDTH, BUFFER_HEIGHT);
    starCamera.translate(STAR_EDITOR_OFFSET, 0);
    starCamera.update();

    screenCamera = new OrthographicCamera();
    screenCamera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    screenCamera.update();

    batch = new SpriteBatch();
    pixelBuffer = new PixelBuffer();
}
项目:GDX-Engine    文件:DefaultGameAsset.java   
@Override
public ShaderProgram loadShader(String vsFilePath)
{
    if(!Game.isSupportOpenGL20)
        return null;

    String fsProcess = vsFilePath.substring(0, vsFilePath.length()-7);
    fsProcess += "fs.glsl";
    ShaderProgram shader = new ShaderProgram(Gdx.files.internal(vsFilePath),
            Gdx.files.internal(fsProcess));

    if(shader.isCompiled())
        return shader;
    else
        throw new GdxRuntimeException("Cannot compile the shader");
}
项目:GDX-Engine    文件:BaseGameScene3D.java   
/**
 * Call right before starting render stage of Scene 3D
 */
protected void preRender() {
    //Create default member for managers if the managers don't have any member. 
    if(camera.count() == 0)
    {
        camera.add("default", new FreeCamera(70, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), new Vector3(0, 5, 5), 0,135));
        camera.setActiveCamera("default");
    }
    if(light.count() == 0 && Game.isSupportOpenGL20)
    {
        light.addBaseLight("default", new DirectionLight(new Vector3(1, 1, 1), new Vector3(1, 1, -1)));
    }
    if(shader.count() == 0 && Game.isSupportOpenGL20)
    {
        String vs = loadShaderFile("effect/default-vs.glsl");
        String fs = loadShaderFile("effect/default-fs.glsl");
        ShaderProgram s = new ShaderProgram(vs , fs);
        if(!s.isCompiled())
        {
            throw new GdxRuntimeException("Cannot compile default shader");
        }
        shader.add("default", s);
        shader.setActiveShader("default");
    }
}
项目:Cubes_2    文件:WorldShaderProvider.java   
private void getShaderIf(int shader, Renderable renderable, boolean fogFlag, boolean aoFlag) {
    if (shaders[shader] == null) {
        if (shader == 0) {
            shaders[shader] = new CubesShader(renderable);
        } else {
            ArrayList<Feature> f = new ArrayList<Feature>();
            if (fogFlag)
                f.add(new FogFeature());
            if (aoFlag)
                f.add(new AmbientOcclusionFeature());
            shaders[shader] = new FeatureShader(renderable, f);
        }

        ShaderProgram program = shaders[shader].program;
        if (!program.isCompiled()) {
            Log.error("Failed to compile shader");
            Log.error("Shader log: \n" + program.getLog());
            Log.error("Fragment shader source: \n" + program.getFragmentShaderSource());
            Log.error("Vertex shader source: \n" + program.getVertexShaderSource());
            throw new CubesException("Failed to compile shader");
        }

        shaders[shader].init();
    }
}
项目:gdx-cclibs    文件:CompliantBatch.java   
/** Constructs a CompliantQuadBatch with a specified capacity and optional default shader.
 * @param maxVertices The number of vertices this FlexBatch can batch at once. Maximum of 32767.
 * @param generateDefaultShader Whether a default shader should be created. The default shader is owned by the
 *           CompliantQuadBatch, so it is disposed when the CompliantQuadBatch is disposed. If an alternate shader has been
 *           applied with {@link #setShader(ShaderProgram)}, the default can be used again by setting the shader to null.
 * @param supportPolygons Whether Poly2Ds are supported for drawing. The FlexBatch will not be optimized for
 *           FixedSizeBatchables. */
public CompliantBatch (Class<T> batchableType, int maxVertices, boolean generateDefaultShader, boolean supportPolygons) {
    super(batchableType, maxVertices, supportPolygons ? maxVertices * 2 : 0);
    try {
        tmp = batchableType.newInstance();
    } catch (Exception e) {
        throw new IllegalArgumentException("Batchable classes must be public and have an empty constructor.", e);
    }
    if (generateDefaultShader) {
        defaultShader = new ShaderProgram(BatchablePreparation.generateGenericVertexShader(1),
            BatchablePreparation.generateGenericFragmentShader(1));
        if (defaultShader.isCompiled() == false)
            throw new IllegalArgumentException("Error compiling shader: " + defaultShader.getLog());
        setShader(defaultShader);
    } else {
        defaultShader = null;
    }
}
项目:gdx-cclibs    文件:FullScreenFader.java   
public void createShader(){
    String vertexShaderSrc =  "attribute vec4 a_position;    \n" +
            "void main()                  \n" +
            "{                            \n" +
            "   gl_Position = a_position;  \n" +
            "}                            \n";
    String fragmentShaderSrc = "#ifdef GL_ES\n" +
            "precision mediump float;\n" +
            "#endif\n" +
            "uniform vec4 u_color;    \n" +
            "void main()                                  \n" +
            "{                                            \n" +
            "  gl_FragColor =  u_color;\n" +
            "}                                            \n";

    shader=new ShaderProgram(vertexShaderSrc,fragmentShaderSrc);

    u_color = shader.getUniformLocation("u_color");
}
项目:arcadelegends-gg    文件:RenderSystem.java   
public RenderSystem(DecalBatch decalBatch, AssetManager assetManager, float worldDegree, Assets.LevelAssets assets) {
    super(Aspect.all(RenderComponent.class, PositionComponent.class));
    this.levelAssets = assets;
    decalMap = new ObjectMap<>();
    uiMap = new ObjectMap<>();
    this.decalBatch = decalBatch;
    this.assetManager = assetManager;
    buffers = new ObjectMap<>();

    this.spriteBatch = new SpriteBatch();
    this.font = assets.uifont;
    font.setColor(Color.BLACK);
    this.uiCamera = new OrthographicCamera();

    Viewport viewportUi = new FitViewport(levelAssets.health_bar_gradient.getWidth(), levelAssets.health_bar_gradient.getHeight(), uiCamera);
    viewportUi.update(viewportUi.getScreenWidth(), viewportUi.getScreenHeight(), true);

    stateTime = 0;
    this.worldDegree = worldDegree;

    gradientShader = new ShaderProgram(Shaders.GradientShader.vertexShader, Shaders.GradientShader.fragmentShader);
    if (gradientShader.isCompiled() == false)
        throw new IllegalArgumentException("couldn't compile shader: " + gradientShader.getLog());
    shaderBatch = new SpriteBatch(10, gradientShader);
}
项目:KyperBox    文件:GameState.java   
public GameState(String name, String tmx, StateManager manager) {
    this.tmx = tmx;
    setManager(manager);
    if(name!=null)
    this.name = name;
    else
        this.name = "";
    sprites = new ObjectMap<String, Sprite>();
    animations = new ObjectMap<String, Animation<String>>();
    fonts = new ObjectMap<String, BitmapFont>(); //TODO: test load to avoid repeats
    particle_effects = new ObjectMap<String, ParticleEffectPool>();
    pvalues = new Array<String>();
    time_scale = 1f;
    shaders = new ObjectMap<String, ShaderProgram>();
    svalues = new Array<String>();
}
项目:KyperBox    文件:GameState.java   
private void loadShaders(TiledMap data) {
    MapObjects objects = data.getLayers().get("preload").getObjects();
    String scheck = "Shader";
    for (MapObject o : objects) {
        String name = o.getName();
        MapProperties properties = o.getProperties();
        String type = properties.get("type", String.class);
        if (type != null && type.equals(scheck)) {
            String file = properties.get("shader_name", String.class);
            if (file != null) {
                game.loadShader(file);
                game.getAssetManager().finishLoading();
                if (!shaders.containsKey(name)) {
                    ShaderProgram sp = game.getShader(file);
                    shaders.put(name, sp);
                    svalues.add(KyperBoxGame.SHADER_FOLDER + KyperBoxGame.FILE_SEPARATOR + file);
                }
            }
        }
    }
}
项目:RavTech    文件:ShaderManager.java   
/** Adds GLES specifics (if needed) and compiles shaders.
 * 
 * @param key - shader identifier
 * @param vert - vertex shader source
 * @param frag - fragment shader source
 * @return whether the shaders compiled correctly */
protected boolean init (String key, String vert, String frag) {
    if (frag == null || vert == null)
        return false;
    frag = appendGLESPrecisions(frag);
    vert = appendGLESPrecisions(vert);
    sourcesVert.put(key, vert);
    sourcesFrag.put(key, frag);
    ShaderProgram sp = new ShaderProgram(vert, frag);
    if (!sp.isCompiled()) {
        Gdx.app.log("ShaderManager", "Error while loading shader '" + key + "':\n" + sp.getLog());
        Gdx.app.log("ShaderManager", "--------------------------------");
        Gdx.app.log("ShaderManager", "Vertex shader source: \n" + vert);
        Gdx.app.log("ShaderManager", "--------------------------------");
        Gdx.app.log("ShaderManager", "Fragment shader source: \n" + frag);
        Gdx.app.log("ShaderManager", "--------------------------------");
        return false;
    }
    shaders.put(key, sp);
    Gdx.app.log("ShaderManager", "Shader '" + key + "' loaded");
    return true;
}
项目:Escapy    文件:EscapyVolumeRenderer.java   
private ShaderProgram initShader(Texture colorMapTex, Texture maskMapTex, Texture normalMapTex, TransVec dim,
        float amIntensity, float dirIntensity, float shadIntensity, float sprtSize, float lum, float thresh, ShaderProgram shader) {
    shader.begin();
    {
        maskMapTex.bind(2);
        normalMapTex.bind(1);
        colorMapTex.bind(0);
        super.batcher.setShader(shader);

        shader.setUniformi(maskMap, 2);
        shader.setUniformi(normalMap, 1);
        shader.setUniformi(colorMap, 0);

        shader.setUniformf(fieldSize, dim.x, dim.y);
        shader.setUniformf(ambientIntensity, amIntensity);
        shader.setUniformf(directIntensity, dirIntensity);
        shader.setUniformf(shadowIntensity, shadIntensity);
        shader.setUniformf(spriteSize, sprtSize);
        shader.setUniformf(height, lum);
        shader.setUniformf(threshold, thresh);
    }
    shader.end();
    return shader;
}
项目:nhglib    文件:LightProbe.java   
private Texture renderBRDF() {
    ShaderProgram brdfShader = new ShaderProgram(
            Gdx.files.internal("shaders/brdf_shader.vert"),
            Gdx.files.internal("shaders/brdf_shader.frag"));

    FrameBuffer frameBuffer = FrameBuffer.createFrameBuffer(Pixmap.Format.RGB888, (int) brdfWidth, (int) brdfHeight, true);

    brdfShader.begin();
    frameBuffer.begin();
    Gdx.gl.glViewport(0, 0, (int) brdfWidth, (int) brdfHeight);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    quadMesh.render(brdfShader, GL20.GL_TRIANGLES);
    frameBuffer.end();
    brdfShader.end();
    brdfShader.dispose();

    return frameBuffer.getColorBufferTexture();
}
项目:nhglib    文件:MainDef.java   
@Override
public void create() {
    super.create();

    geometryPass = new ShaderProgram(
            Gdx.files.internal("shaders/g_buffer.vert"),
            Gdx.files.internal("shaders/g_buffer.frag"));

    lightingPass = new ShaderProgram(
            Gdx.files.internal("shaders/deferred_shader.vert"),
            Gdx.files.internal("shaders/deferred_shader.frag"));

    ModelBuilder mb = new ModelBuilder();
    Model cube = mb.createBox(1, 1, 1, new Material(),
            VertexAttributes.Usage.Position |
                    VertexAttributes.Usage.Normal |
                    VertexAttributes.Usage.TextureCoordinates);
    cubeMesh = cube.meshes.first();
}
项目:LibGDX-PBR    文件:PBRShader.java   
@Override
public void init() {
    loadReflection("rnl_phong_m00");

    String vert = Gdx.files.internal("Shaders/VS_ShaderPlain.vsh").readString();
    String frag = Gdx.files.internal("Shaders/ShaderPlain.fsh").readString();
    program = new ShaderProgram(vert, frag);
    if (!program.isCompiled()){
        throw new GdxRuntimeException(program.getLog());
    }
    u_worldTrans = program.getUniformLocation("u_worldTrans");
    u_projTrans = program.getUniformLocation("u_projTrans");
    vLight0 = program.getUniformLocation("vLight0");
    albedo = program.getUniformLocation("albedo");
    metallic = program.getUniformLocation("metallic");
    sCubemapTexture = program.getUniformLocation("sCubemapTexture");
    vRoughness = program.getUniformLocation("vRoughness");
    ambientOcclusion = program.getUniformLocation("ambientOcclusion");
}
项目:LibGDX-PBR    文件:PBRSadherTexture.java   
@Override
public void init() {
    loadReflection("rnl_phong_m00");

    String vert = Gdx.files.internal("Shaders/VS_PBR_ShaderTexture.vsh").readString();
    String frag = Gdx.files.internal("Shaders/PBR_ShaderTexture.fsh").readString();
    program = new ShaderProgram(vert, frag);
    if (!program.isCompiled()){
        throw new GdxRuntimeException(program.getLog());
    }
    u_worldTrans = program.getUniformLocation("u_worldTrans");
    u_projTrans = program.getUniformLocation("u_projTrans");
    vLight0 = program.getUniformLocation("vLight0");
    albedoTexture = program.getUniformLocation("albedoTexture");
    metallicTexture = program.getUniformLocation("metallicTexture");
    sCubemapTexture = program.getUniformLocation("sCubemapTexture");
    roughnessTexture = program.getUniformLocation("roughnessTexture");
    ambientOcclusionTexture = program.getUniformLocation("ambientOcclusionTexture");
    normalTexture = program.getUniformLocation("normalTexture");
    heightTexture = program.getUniformLocation("heightTexture");
}
项目:exterminate    文件:UniVertexBufferObject.java   
@Override
public void unbind (final ShaderProgram shader, final int[] locations) {
    final GL20 gl = Gdx.gl20;
    final int numAttributes = attributes.size();
    if (locations == null) {
        for (int i = 0; i < numAttributes; i++) {
            shader.disableVertexAttribute(attributes.get(i).alias);
        }
    } else {
        for (int i = 0; i < numAttributes; i++) {
            final int location = locations[i];
            if (location >= 0) shader.disableVertexAttribute(location);
        }
    }
    gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
    isBound = false;
}
项目:RavTech    文件:ShaderManager.java   
public ShaderManager (String shaderDir, AssetManager am, boolean addProcessors) {
    shaders = new ObjectMap<String, ShaderProgram>();
    shaderPaths = new ObjectMap<String, String>();
    sourcesVert = new ObjectMap<String, String>();
    sourcesFrag = new ObjectMap<String, String>();
    frameBuffers = new ObjectMap<String, FrameBuffer>();
    openedFrameBuffers = new Array<String>(true, MAX_FRAMEBUFFERS);
    screenCamera = new OrthographicCamera(Gdx.graphics.getWidth() + 2, Gdx.graphics.getHeight() + 2);
    createScreenQuad();
    screenCamera.translate(0, -1);
    screenCamera.update();
    setShaderDir(shaderDir);
    setAssetManager(am);
    // add("empty", "empty.vert", "empty.frag");
    // add("default", "default.vert", "default.frag");
    if (addProcessors && (Gdx.app.getType() == ApplicationType.Desktop || Gdx.app.getType() == ApplicationType.Applet
        || Gdx.app.getType() == ApplicationType.WebGL)) {
        /*
         * add("processor", "processor.vert", "processor.frag"); add("processor_blur", "processor.vert", "processor_blur.frag");
         * add("copy", "processor.vert", "copy.frag"); add("processor_draw", "processor.vert", "processor_draw.frag");
         * add("processor_fill", "processor.vert", "processor_fill.frag");
         */
    }
}
项目:cocos2d-java    文件:GLProgramCache.java   
/** adds a GLProgram to the cache for a given name */
public void addGLProgram(ShaderProgram program, String key) {
    ShaderProgram ret = _programs.put(key, program);
    if(ret != null) {
        ret.dispose();
        CCLog.engine(TAG, "reset key program : " + key);
    }
}
项目:cocos2d-java    文件:GLProgramCache.java   
public void removeGLProgram(String key) {
    ShaderProgram ret = _programs.remove(key);
    if(ret != null) {
        ret.dispose();
    } else {
        CCLog.error(TAG, "program not found.  key : " + key);
    }
}
项目:cocos2d-java    文件:GLProgramCache.java   
public ShaderProgram loadGLProgramFromFile(String vertexShaderPath, String fragmentShaderPath, String key) {
    ShaderProgram ret = _programs.get(key);
    if(ret != null) {
        CCLog.engine(TAG, "program exists. call removeGLProgram() first");
        return ret;
    }
    ShaderProgram program = new ShaderProgram(
            FileUtils.getInstance().getFileHandle(vertexShaderPath), 
            FileUtils.getInstance().getFileHandle(fragmentShaderPath));
    addGLProgram(program, key);
    return program;
}
项目:cocos2d-java    文件:GLProgramCache.java   
public ShaderProgram loadGLProgramFromString(String vertexShader, String fragmentShader, String key) {
    ShaderProgram ret = _programs.get(key);
    if(ret != null) {
        CCLog.engine(TAG, "program exists. call removeGLProgram() first");
        return ret;
    }
    ShaderProgram program = new ShaderProgram(vertexShader, fragmentShader);
    addGLProgram(program, key);
    return program;
}
项目:cocos2d-java    文件:ShaderTests.java   
public void onEnter() {
            super.onEnter();

//          for(int i = 0; i < 2000; ++i) {
//              spriteNormal = Sprite.create("powered.png");
//              spriteNormal.setContentSize(20, 20);
//              spriteNormal.setPosition(MathUtils.randomFloat(0, 1200), MathUtils.randomFloat(0, 650));
//              addChild(spriteNormal);
//          }

            spriteShader = Sprite.create("powered.png");
            spriteShader.setPosition(300, 320);
            addChild(spriteShader);

            spriteNormal = Sprite.create("powered.png");
            spriteNormal.setPosition(800, 320);
            addChild(spriteNormal);

            ShaderProgram shader = GLProgramCache.getInstance().loadGLProgramFromStringAndFile(
                    GLProgramCache.getInstance().getSpriteBatchDefaultProgram().getVertexShaderSource(), 
                    "shader/flip.fragment.glsl");
//          shader.setUniformi("", 1);
//          spriteShader.setShaderProgram(shader);

//          spriteShader.getGLProgramShader().set;


            scheduleUpdate();
        }
项目:Planet-Generator    文件:Planet.java   
public Planet(Sprite sprite, Pixmap pixmap, int direction) {
    super(sprite);
    this.pixmap = pixmap;
    this.direction = direction;

    rotationSpeed = 1/50f;
    radius = sprite.getWidth()/2;

    planetShader = new ShaderProgram(Gdx.files.internal("shaders/planet.vsh"), Gdx.files.internal("shaders/planet.fsh"));
    if(!planetShader.isCompiled()) {
        Gdx.app.error("Planet Shader Error", "\n" + planetShader.getLog());
    }
}
项目:GDX-Engine    文件:DefaultGameAsset.java   
@Override
public ShaderProgram loadShader(String vsProcess,String fsProcess)
{
    if(!Game.isSupportOpenGL20)
        return null;

    ShaderProgram shader = new ShaderProgram(Gdx.files.internal(vsProcess),
            Gdx.files.internal(fsProcess));

    if(shader.isCompiled())
        return shader;
    else
        throw new GdxRuntimeException("Cannot compile the shader");
}
项目:GDX-Engine    文件:TileRenderer.java   
public TileRenderer(int[][][] map, TileAtlas atlas, int tileWidth,
        int tileHeight, float unitsPerTileX, float unitsPerTileY,
        IntArray blendedTiles, int tilesPerBlockX, int tilesPerBlockY,
        ShaderProgram shader) {
    super(map, atlas, tileWidth, tileHeight, unitsPerTileX, unitsPerTileY,
            blendedTiles, tilesPerBlockX, tilesPerBlockY, shader);
    // TODO Auto-generated constructor stub
}
项目:GDX-Engine    文件:TileRenderer.java   
public TileRenderer(TiledMap map, TileAtlas atlas, int tilesPerBlockX,
        int tilesPerBlockY, float unitsPerTileX, float unitsPerTileY,
        ShaderProgram shader) {
    super(map, atlas, tilesPerBlockX, tilesPerBlockY, unitsPerTileX, unitsPerTileY,
            shader);
    // TODO Auto-generated constructor stub
}
项目:GDX-Engine    文件:ShaderManager.java   
/**
 * Get the specified Shader by providing shader 's key
 * @param key
 * @return
 */
public ShaderProgram getShader(String key)
{
    if(!collection.containsKey(key))
        throw new GdxRuntimeException("Shader is not existing in ShaderManager!");

    return collection.get(key);
}
项目:GDX-Engine    文件:ShaderManager.java   
/**
 * Add new shader, also provide its key
 * @param shader
 * @param key
 */
public void addShader(ShaderProgram shader, String key)
{
    if(collection.containsKey(key))
        throw new GdxRuntimeException("Shader key is existing in ShaderManager!");

    collection.put(key, shader);
}
项目:GDX-Engine    文件:ShaderManager.java   
/**
 * set current active shader by reference to the shader
 * @param shader
 */
public void setActiveShader(ShaderProgram shader)
{
    if(!collection.containsValue(shader))
        throw new GdxRuntimeException("Shader is not existing in ShaderManager!");

    activeObject = shader;
}
项目:Cubes_2    文件:WorldShaderProvider.java   
@Override
public void init(ShaderProgram program) {
    u_cameraposition = program.fetchUniformLocation("u_cameraposition", true);
    u_skycolor = program.fetchUniformLocation("u_skycolor", true);
    u_fogdistance = program.fetchUniformLocation("u_fogdistance", true);
    u_minfogdistance = program.fetchUniformLocation("u_minfogdistance", true);
}
项目:Cubes_2    文件:WorldShaderProvider.java   
@Override
public void begin(ShaderProgram program, Camera camera, RenderContext context) {
    WorldClient worldClient = ((WorldClient) Cubes.getClient().world);
    float distance = Settings.getIntegerSettingValue(Settings.GRAPHICS_VIEW_DISTANCE) * Area.SIZE_BLOCKS;
    float fogDistance = MathUtils.clamp(distance * 0.1f, 8f, 16f);

    program.setUniformf(u_cameraposition, Cubes.getClient().player.position);
    program.setUniformf(u_skycolor, worldClient.getSkyColour());
    program.setUniformf(u_fogdistance, fogDistance);
    program.setUniformf(u_minfogdistance, distance - fogDistance);
}
项目:Cubes_2    文件:WorldShaderProvider.java   
@Override
public void begin(ShaderProgram program, Camera camera, RenderContext context) {
    TextureAttribute textureAttribute = AmbientOcclusion.getTextureAttribute();

    ao_unit = context.textureBinder.bind(textureAttribute.textureDescription);
    program.setUniformi(u_aoTexture, ao_unit);

    program.setUniformf(u_aoUVTransform, textureAttribute.offsetU, textureAttribute.offsetV,
            textureAttribute.scaleU, textureAttribute.scaleV);
}
项目:Cubes_2    文件:FrametimeGraph.java   
private static ShaderProgram createShaderProgram() {
    String vertex = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n";
    vertex += "uniform mat4 u_projModelView;\n";
    vertex += "void main() {\n" + "   gl_Position = u_projModelView * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n";
    vertex += "   gl_PointSize = 1.0;\n";
    vertex += "}\n";
    String fragment = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n";
    fragment += "void main() {\n" + "   gl_FragColor = vec4(0, 1, 0, 1)"; // #00ff00ff
    fragment += ";\n}";
    return new ShaderProgram(vertex, fragment);
}
项目:gdx-cclibs    文件:FlexBatch.java   
public void setShader (ShaderProgram shader) {
    if (drawing) {
        flush();
        shader.end();
    }
    this.shader = shader;
    if (drawing) {
        shader.begin();
        applyMatrices();
    }
}
项目:gdx-cclibs    文件:BatchablePreparation.java   
/** Generate vertex attributes suitable for multi-texturing and vertex color. 32 bit floats are used for each position
 * component and texture coordinate. The four color components are packed into a single 32 bit float.
 * @param textureCount The number of textures to support.
 * @param position3D Whether the position attribute should include a Z component.
 * @param textureCoordinates3D Whether the texture coordinate attribute(s) should include a third component.
 * @param attributes The array to add the vertex attributes to. They are added with position and color in the first two
 *           available positions, followed by texture coordinates. */
public static void addBaseAttributes (Array<VertexAttribute> attributes, int textureCount, boolean position3D,
    boolean textureCoordinates3D) {
    attributes.add(new VertexAttribute(Usage.Position, position3D ? 3 : 2, ShaderProgram.POSITION_ATTRIBUTE));
    attributes.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
    for (int i = 0; i < textureCount; i++) {
        attributes.add(
            new VertexAttribute(Usage.TextureCoordinates, textureCoordinates3D ? 3 : 2, ShaderProgram.TEXCOORD_ATTRIBUTE + i, i));
    }
}
项目:gdx-cclibs    文件:BatchablePreparation.java   
public static String generateGenericVertexShader (int textureCount) {
    boolean v3 = Gdx.gl30 != null;
    String attribute = v3 ? "in" : "attribute";
    String varying = v3 ? "out" : "varying";

    StringBuilder sb = new StringBuilder();

    if (v3) sb.append("#version 300 es\n");
    sb.append(attribute).append(" vec4 ").append(ShaderProgram.POSITION_ATTRIBUTE).append(";\n");
    sb.append(attribute).append(" vec4 ").append(ShaderProgram.COLOR_ATTRIBUTE).append(";\n");
    for (int i = 0; i < textureCount; i++)
        sb.append(attribute).append(" vec2 ").append(ShaderProgram.TEXCOORD_ATTRIBUTE).append(i).append(";\n");
    sb.append("uniform mat4 u_projTrans;\n");
    sb.append(varying).append(" vec4 v_color;\n");
    for (int i = 0; i < textureCount; i++)
        sb.append(varying).append(" vec2 v_texCoords").append(i).append(";\n\n");

    sb.append("void main()\n");
    sb.append("{\n");
    sb.append("   v_color = ").append(ShaderProgram.COLOR_ATTRIBUTE).append(";\n");
    sb.append("   v_color.a = v_color.a * (255.0/254.0);\n");
    for (int i = 0; i < textureCount; i++)
        sb.append("   v_texCoords").append(i).append(" = ").append(ShaderProgram.TEXCOORD_ATTRIBUTE).append(i).append(";\n");
    sb.append("   gl_Position =  u_projTrans * ").append(ShaderProgram.POSITION_ATTRIBUTE).append(";\n");
    sb.append("}\n");

    return sb.toString();
}
项目:MMORPG_Prototype    文件:ShaderBatch.java   
public ShaderBatch(float brightness, float contrast)
{
    ShaderProgram.pedantic = false;
    ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
    setShader(shader);
    shader.begin();
    int brightnessLoc = shader.getUniformLocation("brightness");
    int contrastLoc = shader.getUniformLocation("contrast");
    shader.setUniformf(brightnessLoc, brightness);
    shader.setUniformf(contrastLoc, contrast);
    shader.end();
}
项目:arcadelegends-gg    文件:CharacterRenderer.java   
/**
 * Draws the given gradient {@link Texture} to the given {@link FrameBuffer}, using the given {@link Color} with the given percent.
 * <p>
 * This is achieved via a gradient shader.
 *
 * @param buffer      the {@link FrameBuffer} to be drawn to
 * @param color       the {@link Color} which should be drawn
 * @param gradient    the gradient texture which should be drawn
 * @param perc        the percent the gradient texture should be drawn
 * @param shaderBatch the {@link SpriteBatch} to use
 * @param shader      the {@link ShaderProgram} to use
 * @param projection  projection matrix for pixel perfect rendering
 */
private static void drawToBuffer(FrameBuffer buffer, Color color, Texture gradient, float perc, SpriteBatch shaderBatch, ShaderProgram shader, Matrix4 projection) {
    buffer.begin();
    AL.graphics.getGL20().glClearColor(0, 0, 0, 0);
    AL.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);

    shaderBatch.setProjectionMatrix(projection);
    shaderBatch.begin();
    shaderBatch.setColor(color);
    shader.setUniformf("u_gradient", perc);
    shaderBatch.draw(gradient, -buffer.getWidth() / 2, -buffer.getHeight() / 2);
    shaderBatch.end();
    buffer.end();
}
项目:KyperBox    文件:KyperBoxGame.java   
@Override
public void create() {
    game_prefs = Gdx.app.getPreferences(prefs_name);

    game_stage = new Stage(view);
    game_states = new ObjectMap<String, GameState>();
    game_stage.setDebugAll(false);

    current_gamestates = new Array<GameState>();
    transition_state = new GameState(null);
    transition_state.setGame(this);

    assets = new AssetManager();
    assets.setLoader(TiledMap.class, new KyperMapLoader(assets.getFileHandleResolver()));
    assets.setLoader(ParticleEffect.class, new ParticleEffectLoader(assets.getFileHandleResolver()));
    assets.setLoader(ShaderProgram.class,
            new ShaderProgramLoader(assets.getFileHandleResolver(), VERTEX_SUFFIX, FRAGMENT_SUFFIX));
    sound = new SoundManager(this);

    packages = new Array<String>();
    packages.add("com.kyperbox.objects");

    global_data = new UserData(GAME_DATA_NAME);
    input = new GameInput();

    Gdx.input.setInputProcessor(game_stage);

    initiate();
}