Example usage for org.lwjgl.opengl GL20 glGetUniformLocation

List of usage examples for org.lwjgl.opengl GL20 glGetUniformLocation

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL20 glGetUniformLocation.

Prototype

@NativeType("GLint")
public static int glGetUniformLocation(@NativeType("GLuint") int program,
        @NativeType("GLchar const *") CharSequence name) 

Source Link

Document

Returns the location of a uniform variable.

Usage

From source file:ar.com.quark.backend.lwjgl.opengl.DesktopGLES20.java

License:Apache License

/**
 * {@inheritDoc}//from  w  w w  .  j  a  va  2 s .co m
 */
@Override
public int glGetUniformLocation(int name, String uniform) {
    return GL20.glGetUniformLocation(name, uniform);
}

From source file:cn.lambdalib.util.client.shader.ShaderMono.java

License:MIT License

private ShaderMono() {
    this.linkShader(getShader("simple.vert"), GL20.GL_VERTEX_SHADER);
    this.linkShader(getShader("mono.frag"), GL20.GL_FRAGMENT_SHADER);
    this.compile();

    this.useProgram();
    GL20.glUniform1i(GL20.glGetUniformLocation(this.getProgramID(), "sampler"), 0);
    GL20.glUseProgram(0);// w  w  w  .  j  a v  a2  s .  c o m
}

From source file:cn.lambdalib.util.client.shader.ShaderSimple.java

License:MIT License

private ShaderSimple() {
    this.linkShader(getShader("simple.vert"), GL20.GL_VERTEX_SHADER);
    this.linkShader(getShader("simple.frag"), GL20.GL_FRAGMENT_SHADER);
    this.compile();

    this.useProgram();
    GL20.glUniform1i(GL20.glGetUniformLocation(this.getProgramID(), "sampler"), 0);
    GL20.glUseProgram(0);/*  ww w . j av  a2s  .c om*/
}

From source file:com.adavr.player.globjects.Program.java

License:Open Source License

public int getUniformLocation(CharSequence name) {
    return GL20.glGetUniformLocation(id, name);
}

From source file:com.badlogic.gdx.backends.jglfw.JglfwGL20.java

License:Apache License

public int glGetUniformLocation(int program, String name) {
    return GL20.glGetUniformLocation(program, name);
}

From source file:com.flowpowered.caustic.lwjgl.gl20.GL20Program.java

License:MIT License

@Override
public void link() {
    checkCreated();//from www .  j a  v  a 2  s.  c o m
    // Add the attribute layouts to the program state
    final TObjectIntIterator<String> iterator = attributeLayouts.iterator();
    while (iterator.hasNext()) {
        iterator.advance();
        // Bind the index to the name
        GL20.glBindAttribLocation(id, iterator.value(), iterator.key());
    }
    // Link program
    GL20.glLinkProgram(id);
    // Check program link status
    if (GL20.glGetProgrami(id, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) {
        throw new IllegalStateException("Program could not be linked\n" + GL20.glGetProgramInfoLog(id, 1000));
    }
    if (CausticUtil.isDebugEnabled()) {
        // Validate program
        GL20.glValidateProgram(id);
        // Check program validation status
        if (GL20.glGetProgrami(id, GL20.GL_VALIDATE_STATUS) == GL11.GL_FALSE) {
            final Logger logger = CausticUtil.getCausticLogger();
            logger.log(Level.WARNING,
                    "Program validation failed. This doesn''t mean it won''t work, so you maybe able to ignore it\n{0}",
                    GL20.glGetProgramInfoLog(id, 1000));
        }
    }
    // Load uniforms
    uniforms.clear();
    final int uniformCount = GL20.glGetProgrami(id, GL20.GL_ACTIVE_UNIFORMS);
    final int maxLength = GL20.glGetProgrami(id, GL20.GL_ACTIVE_UNIFORM_MAX_LENGTH);
    final IntBuffer lengthBuffer = CausticUtil.createIntBuffer(1);
    final IntBuffer ignored1 = CausticUtil.createIntBuffer(1);
    final IntBuffer ignored2 = CausticUtil.createIntBuffer(1);
    final ByteBuffer nameBuffer = CausticUtil.createByteBuffer(maxLength);
    final byte[] nameBytes = new byte[maxLength];
    for (int i = 0; i < uniformCount; i++) {
        lengthBuffer.clear();
        ignored1.clear();
        ignored2.clear();
        nameBuffer.clear();
        GL20.glGetActiveUniform(id, i, lengthBuffer, ignored1, ignored2, nameBuffer);
        final int length = lengthBuffer.get();
        nameBuffer.get(nameBytes, 0, length);
        // Simplify array names
        final String name = new String(nameBytes, 0, length).replaceFirst("\\[\\d+\\]", "");
        uniforms.put(name, GL20.glGetUniformLocation(id, name));
        uniformValues.put(name, UNSET);
    }
    // Check for errors
    LWJGLUtil.checkForGLError();
}

From source file:com.github.begla.blockmania.game.mobs.GelatinousCube.java

License:Apache License

public void render() {
    super.render();

    glPushMatrix();/*  w  w w.  j a  v  a 2 s. c om*/

    glTranslatef(getPosition().x - _parent.getWorldProvider().getRenderingReferencePoint().x,
            getPosition().y - _parent.getWorldProvider().getRenderingReferencePoint().y,
            getPosition().z - _parent.getWorldProvider().getRenderingReferencePoint().z);
    glRotatef((float) _yaw, 0f, 1f, 0f);

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    TextureManager.getInstance().bindTexture("slime");

    // Setup the shader
    ShaderManager.getInstance().enableShader("gelatinousCube");
    int tick = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("gelatinousCube"), "tick");
    GL20.glUniform1f(tick, _parent.getTick());
    int cOffset = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("gelatinousCube"),
            "colorOffset");
    GL20.glUniform4f(cOffset, COLORS[_randomColorId].x, COLORS[_randomColorId].y, COLORS[_randomColorId].z,
            1.0f);
    int light = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("gelatinousCube"), "light");
    GL20.glUniform1f(light, calcLightValue());

    if (_displayListOuterBody == -1 || _displayListInnerBody == -1) {
        generateDisplayList();
    }

    glPushMatrix();
    glScalef(_randomSize, _randomSize, _randomSize);
    glCallList(_displayListInnerBody);
    glCallList(_displayListOuterBody);
    glPopMatrix();

    glDisable(GL11.GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    ShaderManager.getInstance().enableShader(null);

    glPopMatrix();
}

From source file:com.github.begla.blockmania.rendering.particles.BlockParticle.java

License:Apache License

protected void renderParticle() {
    if (_displayLists[_blockType] == 0) {
        _displayLists[_blockType] = glGenLists(1);
        glNewList(_displayLists[_blockType], GL11.GL_COMPILE);
        drawParticle();/*  w  ww . ja v a 2 s .  c  o m*/
        glEndList();
    }

    BlockParticleEmitter pE = (BlockParticleEmitter) getParent();
    double lightValueSun = ((double) pE.getParent().getWorldProvider().getLightAtPosition(_position,
            Chunk.LIGHT_TYPE.SUN));
    lightValueSun = (lightValueSun / 15.0) * pE.getParent().getDaylight();
    double lightValueBlock = pE.getParent().getWorldProvider().getLightAtPosition(_position,
            Chunk.LIGHT_TYPE.BLOCK);
    lightValueBlock = lightValueBlock / 15.0;

    float lightValue = (float) Math.max(lightValueSun, lightValueBlock) * _lightOffset;

    int light = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("particle"), "light");
    int texOffsetX = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("particle"), "texOffsetX");
    int texOffsetY = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("particle"), "texOffsetY");
    GL20.glUniform1f(light, lightValue);
    GL20.glUniform1f(texOffsetX, _texOffsetX);
    GL20.glUniform1f(texOffsetY, _texOffsetY);

    glCallList(_displayLists[_blockType]);
}

From source file:com.github.begla.blockmania.world.horizon.Clouds.java

License:Apache License

public void render() {
    // Nothing to do if the player is swimming
    if (_parent.getPlayer().isHeadUnderWater())
        return;/*  w w w . j a va2  s.c o  m*/

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    ShaderManager.getInstance().enableShader("cloud");
    int daylight = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("cloud"), "daylight");
    GL20.glUniform1f(daylight, (float) _parent.getDaylight());

    glPushMatrix();
    glTranslatef(_parent.getPlayer().getPosition().x + _cloudOffset.x, 190f,
            _parent.getPlayer().getPosition().z + _cloudOffset.y);

    // Render two passes: The first one only writes to the depth buffer, the second one to the frame buffer
    for (int i = 0; i < 2; i++) {
        if (i == 0) {
            glColorMask(false, false, false, false);
        } else {
            glColorMask(true, true, true, true);
        }

        drawClouds();
    }

    glPopMatrix();

    ShaderManager.getInstance().enableShader(null);
    glDisable(GL_BLEND);
}

From source file:com.github.begla.blockmania.world.horizon.Skysphere.java

License:Apache License

public void render() {
    updateClouds();//from ww w  . ja v a2  s. co  m

    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);

    glEnable(GL13.GL_TEXTURE_CUBE_MAP);
    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, _textureIds.get(0));
    _sunPosAngle = (float) Math.toRadians(360.0 * _parent.getWorldProvider().getTime() - 90.0);
    Vector4f sunNormalise = new Vector4f(0.0f, (float) Math.cos(_sunPosAngle), (float) Math.sin(_sunPosAngle),
            1.0f);
    sunNormalise.normalize();

    _zenithColor = getAllWeatherZenith(sunNormalise.y);

    ShaderManager.getInstance().enableShader("sky");

    int sunPos = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("sky"), "sunPos");
    GL20.glUniform4f(sunPos, 0.0f, (float) Math.cos(_sunPosAngle), (float) Math.sin(_sunPosAngle), 1.0f);

    int time = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("sky"), "time");
    GL20.glUniform1f(time, (float) _parent.getWorldProvider().getTime());

    int sunAngle = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("sky"), "sunAngle");
    GL20.glUniform1f(sunAngle, _sunPosAngle);

    int turbidity = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("sky"), "turbidity");
    GL20.glUniform1f(turbidity, _turbidity);

    int zenith = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("sky"), "zenith");
    GL20.glUniform3f(zenith, _zenithColor.x, _zenithColor.y, _zenithColor.z);

    // DRAW THE SKYSPHERE
    drawSphere();

    glDisable(GL13.GL_TEXTURE_CUBE_MAP);

    ShaderManager.getInstance().enableShader("clouds");
    // Apply daylight
    int lightClouds = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("clouds"), "light");
    GL20.glUniform1f(lightClouds, getDaylight());

    // DRAW THE CLOUDS
    drawClouds();
    ShaderManager.getInstance().enableShader(null);

    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
}