Java Code Examples for org.lwjgl.opengl.GL20#glUniform1f()

The following examples show how to use org.lwjgl.opengl.GL20#glUniform1f() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackgroundShader.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateUniforms() {
    final ScaledResolution scaledResolution = new ScaledResolution(mc);

    final int resolutionID = getUniform("iResolution");
    if(resolutionID > -1)
        GL20.glUniform2f(resolutionID, (float) scaledResolution.getScaledWidth() * 2, (float) scaledResolution.getScaledHeight() * 2);
    final int timeID = getUniform("iTime");
    if(timeID > -1) GL20.glUniform1f(timeID, time);

    time += 0.005F * RenderUtils.deltaTime;
}
 
Example 2
Source File: ShaderArgs.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Bind args.
 *
 * @param program the program
 */
public void bindArgs(int program) {
	for(int i=0; i<args.length; i++) {
		int loc = GL20.glGetUniformLocation(program, "arg"+i);
		GL20.glUniform1f(loc, args[i]);
	}
}
 
Example 3
Source File: ShaderUniformCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void apply() {
    if (dirty) {
        switch (type.getCarrier()) {
            //@formatter:off
            case FLOAT:
                switch (type.getSize()) {
                    case 1: GL20.glUniform1f(getLocation(), cache[0]); break;
                    case 2: GL20.glUniform2f(getLocation(), cache[0], cache[1]); break;
                    case 3: GL20.glUniform3f(getLocation(), cache[0], cache[1], cache[2]); break;
                    case 4: GL20.glUniform4f(getLocation(), cache[0], cache[1], cache[2], cache[3]); break;
                    default: throw new IllegalStateException("Invalid size for Float type." + type.getSize());
                }
                break;
            case D_MATRIX:
                switch (type) {
                    case MAT2: GL20.glUniformMatrix2fv  (getLocation(), transpose, cache); break;
                    case MAT3: GL20.glUniformMatrix3fv  (getLocation(), transpose, cache); break;
                    case MAT4: GL20.glUniformMatrix4fv  (getLocation(), transpose, cache); break;
                    case MAT2x3: GL21.glUniformMatrix2x3fv(getLocation(), transpose, cache); break;
                    case MAT2x4: GL21.glUniformMatrix2x4fv(getLocation(), transpose, cache); break;
                    case MAT3x2: GL21.glUniformMatrix3x2fv(getLocation(), transpose, cache); break;
                    case MAT3x4: GL21.glUniformMatrix3x4fv(getLocation(), transpose, cache); break;
                    case MAT4x2: GL21.glUniformMatrix4x2fv(getLocation(), transpose, cache); break;
                    case MAT4x3: GL21.glUniformMatrix4x3fv(getLocation(), transpose, cache); break;
                    default: throw new IllegalStateException("Invalid Matrix type: " + type);
                }
                break;
            default: throw new IllegalStateException("Invalid type for FloatUniformEntry: " + type.getCarrier());
            //@formatter:on
        }
        dirty = false;
    }
}
 
Example 4
Source File: UniformFloat.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
public void loadFloat(float value){
	if(!used || currentValue!=value){
		GL20.glUniform1f(super.getLocation(), value);
		used = true;
		currentValue = value;
	}
}
 
Example 5
Source File: UniformBoolean.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
public void loadBoolean(boolean bool){
	if(!used || currentBool != bool){
		GL20.glUniform1f(super.getLocation(), bool ? 1f : 0f);
		used = true;
		currentBool = bool;
	}
}
 
Example 6
Source File: UniformBoolean.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
public void loadBoolean(boolean bool){
	if(!used || currentBool != bool){
		GL20.glUniform1f(super.getLocation(), bool ? 1f : 0f);
		used = true;
		currentBool = bool;
	}
}
 
Example 7
Source File: OutlineShader.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateUniforms() {
    GL20.glUniform1i(getUniform("texture"), 0);
    GL20.glUniform2f(getUniform("texelSize"), 1F / mc.displayWidth * (radius * quality), 1F / mc.displayHeight * (radius * quality));
    GL20.glUniform4f(getUniform("color"), red, green, blue, alpha);
    GL20.glUniform1f(getUniform("radius"), radius);
}
 
Example 8
Source File: GLShader.java    From ldparteditor with MIT License 4 votes vote down vote up
public void pngModeOff() {
    GL20.glUniform1f(getUniformLocation("pngswitch"), 0f); //$NON-NLS-1$
}
 
Example 9
Source File: GLShader.java    From ldparteditor with MIT License 4 votes vote down vote up
public void pngModeOn() {
    GL20.glUniform1f(getUniformLocation("pngswitch"), 1f); //$NON-NLS-1$
}
 
Example 10
Source File: GLShader.java    From ldparteditor with MIT License 4 votes vote down vote up
public void transparentOff() {
    GL20.glUniform1f(getUniformLocation("alphaswitch"), 0f); //$NON-NLS-1$
}
 
Example 11
Source File: ShaderArgs.java    From FEMultiplayer with GNU General Public License v3.0 4 votes vote down vote up
public void bindArgs(int program) {
	for(int i=0; i<args.length; i++) {
		int loc = GL20.glGetUniformLocation(program, "arg"+i);
		GL20.glUniform1f(loc, args[i]);
	}
}
 
Example 12
Source File: GTexture.java    From ldparteditor with MIT License 4 votes vote down vote up
public void bind(boolean drawSolidMaterials, boolean normalSwitch, boolean lightOn, OpenGLRenderer20 renderer, int useCubeMap) {

        int ID = -1;
        int ID_glossmap = -1;
        int ID_cubemap = -1;
        int ID_cubemap_matte = -1;
        int ID_cubemap_metal = -1;
        boolean disposed = true;

        if (OpenGlDisposed.containsKey(renderer)) {
            disposed = OpenGlDisposed.get(renderer);
            ID = OpenGlID.get(renderer);
            ID_glossmap = OpenGlID_glossmap.get(renderer);
            ID_cubemap = OpenGlID_cubemap.get(renderer);
            ID_cubemap_matte = OpenGlID_cubemapMatte.get(renderer);
            ID_cubemap_metal = OpenGlID_cubemapMetal.get(renderer);
        } else {
            OpenGlDisposed.put(renderer, true);
        }

        if (disposed) {

            DatFile df = renderer.getC3D().getLockableDatFileReference();

            ID = loadPNGTexture(texture, GL13.GL_TEXTURE0, df);
            if (glossy)
                ID_glossmap = loadPNGTexture(glossmap, GL13.GL_TEXTURE1, df);
            if (cubeMapIndex > 0) {
                switch (cubeMapIndex) {
                case 1:
                    ID_cubemap = loadPNGTexture("cmap.png", GL13.GL_TEXTURE2, df ); //$NON-NLS-1$
                    break;
                case 2:
                    ID_cubemap_matte = loadPNGTexture("matte_metal.png", GL13.GL_TEXTURE3, df); //$NON-NLS-1$
                    break;
                case 3:
                    ID_cubemap_metal = loadPNGTexture("metal.png", GL13.GL_TEXTURE4, df); //$NON-NLS-1$
                    break;
                }
            }
            OpenGlDisposed.put(renderer, false);
            renderer.registerTexture(this);
            OpenGlID.put(renderer, ID);
            OpenGlID_glossmap.put(renderer, ID_glossmap);
            OpenGlID_cubemap.put(renderer, ID_cubemap);
            OpenGlID_cubemapMatte.put(renderer, ID_cubemap_matte);
            OpenGlID_cubemapMetal.put(renderer, ID_cubemap_metal);
        } else if (ID != -1) {
            accessTime = System.currentTimeMillis();
            GL13.glActiveTexture(GL13.GL_TEXTURE0 + 0);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID);
            GL20.glUniform1f(renderer.getAlphaSwitchLoc(), drawSolidMaterials ? 1f : 0f); // Draw transparent
            GL20.glUniform1f(renderer.getNormalSwitchLoc(), normalSwitch ? 1f : 0f); // Draw transparent
            GL20.glUniform1i(renderer.getBaseImageLoc(), 0); // Texture unit 0 is for base images.
            GL20.glUniform1f(renderer.getNoTextureSwitch(), 0f);
            GL20.glUniform1f(renderer.getNoLightSwitch(), lightOn ? 0f : 1f);
            GL20.glUniform1f(renderer.getCubeMapSwitch(), useCubeMap);

            if (glossy) {
                GL13.glActiveTexture(GL13.GL_TEXTURE0 + 2);
                GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_glossmap);
                GL20.glUniform1i(renderer.getGlossMapLoc(), 2); // Texture unit 2 is for gloss maps.
                GL20.glUniform1f(renderer.getNoGlossMapSwitch(), 0f);
            } else {
                GL20.glUniform1f(renderer.getNoGlossMapSwitch(), 1f);
            }
            if (cubeMapIndex > 0) {
                switch (cubeMapIndex) {
                case 1:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 4);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap);
                    GL20.glUniform1i(renderer.getCubeMapLoc(), 4); // Texture unit 4 is for cube maps.
                    break;
                case 2:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 8);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap_matte);
                    GL20.glUniform1i(renderer.getCubeMapMatteLoc(), 8); // Texture unit 8 is for cube maps.
                    break;
                case 3:
                    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 16);
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID_cubemap_metal);
                    GL20.glUniform1i(renderer.getCubeMapMetalLoc(), 16); // Texture unit 16 is for cube maps.
                    break;
                }
            }
        }
    }
 
Example 13
Source File: GData5.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void drawGL20_BFC_Textured(Composite3D c3d) {
    // done :)
    if (GData.globalDrawObjects) {
        final OpenGLRenderer20 r = (OpenGLRenderer20) c3d.getRenderer();
        GL20.glUniform1f(r.getNormalSwitchLoc(), GData.globalNegativeDeterminant ^ GData.globalInvertNext ? 1f : 0f);
        GL20.glUniform1f(r.getNoTextureSwitch(), 1f);
        GL20.glUniform1f(r.getNoLightSwitch(), 1f);
        GL20.glUniform1f(r.getCubeMapSwitch(), 0f);

        if (!visible)
            return;
        if (!c3d.isDrawingSolidMaterials())
            return;

        float result;
        float zoom = c3d.getZoom();
        switch (c3d.getLineMode()) {
        case 1:
            result = 1f;
            break;
        case 2:
        case 4:
            return;
        default:
            final Matrix4f M2 = GData.CACHE_viewByProjection.get(parent);
            if (M2 == null) {
                Matrix4f.mul(c3d.getViewport(), parent.productMatrix, M);
                GData.CACHE_viewByProjection.put(parent, M);
            } else {
                M = M2;
            }
            // Calculate the real coordinates
            Matrix4f.transform(M, A2, A);
            Matrix4f.transform(M, B2, B);
            Matrix4f.transform(M, C2, C);
            Matrix4f.transform(M, D2, D);

            N.x = A.y - B.y;
            N.y = B.x - A.x;

            result = zoom / Vector4f.dot(N, Vector4f.sub(C, A, null)) * Vector4f.dot(N, Vector4f.sub(D, A, null));
            break;
        }

        if (result > -1e-20f) {

            float r2;
            float g2;
            float b2;
            int cn;
            if (colourNumber == 24 && (cn = parent.r == .5f && parent.g == .5f && parent.b == .5f && (parent.a == 1.1f || parent.a == -1)  ? 16 : View.getLDConfigIndex(parent.r,  parent.g,  parent.b)) != 16) {
                GColour c = View.getLDConfigEdgeColour(cn, c3d);
                r2 = c.getR();
                g2 = c.getG();
                b2 = c.getB();
            } else {
                r2 = this.r;
                g2 = this.g;
                b2 = this.b;
            }

            GL11.glLineWidth(View.lineWidthGL[0]);
            GL11.glColor4f(r2, g2, b2, 1f);
            GL11.glBegin(GL11.GL_LINES);
            GraphicalDataTools.setVertex(x1, y1, z1, this, true);
            GraphicalDataTools.setVertex(x2, y2, z2, this, true);
            GL11.glEnd();
        }
    }
    if (GData.globalFoundTEXMAPNEXT) {
        GData.globalFoundTEXMAPStack.pop();
        GData.globalTextureStack.pop();
        GData.globalFoundTEXMAPStack.push(false);
        GData.globalFoundTEXMAPNEXT = false;
    }
}
 
Example 14
Source File: GData2.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void drawGL20_BFC_Textured(Composite3D c3d) {
    // done :)
    if (GData.globalDrawObjects) {
        final OpenGLRenderer20 r = (OpenGLRenderer20) c3d.getRenderer();
        GL20.glUniform1f(r.getNormalSwitchLoc(), GData.globalNegativeDeterminant ^ GData.globalInvertNext ? 1f : 0f);
        GL20.glUniform1f(r.getNoTextureSwitch(), 1f);
        GL20.glUniform1f(r.getNoLightSwitch(), 1f);
        GL20.glUniform1f(r.getCubeMapSwitch(), 0f);
        if (!visible)
            return;
        if (!c3d.isDrawingSolidMaterials())
            return;
        switch (c3d.getLineMode()) {
        case 3:
        case 4:
            return;
        default:
            break;
        }
        if (!isLine)
            return;

        float r2;
        float g2;
        float b2;
        int cn;
        if (colourNumber == 24 && (cn = parent.r == .5f && parent.g == .5f && parent.b == .5f && (parent.a == 1.1f || parent.a == -1)  ? 16 : View.getLDConfigIndex(parent.r,  parent.g,  parent.b)) != 16) {
            GColour c = View.getLDConfigEdgeColour(cn, c3d);
            r2 = c.getR();
            g2 = c.getG();
            b2 = c.getB();
        } else {
            r2 = this.r;
            g2 = this.g;
            b2 = this.b;
        }

        GL11.glLineWidth(View.lineWidthGL[0]);
        GL11.glColor4f(r2, g2, b2, 1f);
        GL11.glBegin(GL11.GL_LINES);
        GraphicalDataTools.setVertex(x1, y1, z1, this, true);
        GraphicalDataTools.setVertex(x2, y2, z2, this, true);
        GL11.glEnd();
    }
    if (GData.globalFoundTEXMAPNEXT) {
        GData.globalFoundTEXMAPStack.pop();
        GData.globalTextureStack.pop();
        GData.globalFoundTEXMAPStack.push(false);
        GData.globalFoundTEXMAPNEXT = false;
    }
}
 
Example 15
Source File: OpenGLRenderer33.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void init() {

    if (shaderProgram.isDefault()) shaderProgram = new GLShader("renderer.vert", "renderer.frag"); //$NON-NLS-1$ //$NON-NLS-2$
    if (shaderProgram2.isDefault()) shaderProgram2 = new GLShader("primitive.vert", "primitive.frag"); //$NON-NLS-1$ //$NON-NLS-2$
    if (shaderProgram2D.isDefault()) shaderProgram2D = new GLShader("2D.vert", "2D.frag"); //$NON-NLS-1$ //$NON-NLS-2$
    if (shaderProgramCondline.isDefault()) shaderProgramCondline = new GLShader("condline.vert", "condline.frag"); //$NON-NLS-1$ //$NON-NLS-2$

    shaderProgramCondline.use();

    GL20.glUniform1f(shaderProgramCondline.getUniformLocation("showAll"), c3d.getLineMode() == 1 ? 1f : 0f); //$NON-NLS-1$
    GL20.glUniform1f(shaderProgramCondline.getUniformLocation("condlineMode"), c3d.getRenderMode() == 6 ? 1f : 0f); //$NON-NLS-1$

    stack.setShader(shaderProgram);
    shaderProgram.use();
    shaderProgram.texmapOff();

    {
        GL20.glUniform1f(shaderProgram.getUniformLocation("l0_r"), View.light1_Colour_r[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l0_g"), View.light1_Colour_g[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l0_b"), View.light1_Colour_b[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l0s_r"), View.light1_specular_Colour_r[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l0s_g"), View.light1_specular_Colour_g[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l0s_b"), View.light1_specular_Colour_b[0]); //$NON-NLS-1$

        GL20.glUniform1f(shaderProgram.getUniformLocation("l1_r"), View.light2_Colour_r[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l1_g"), View.light2_Colour_g[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l1_b"), View.light2_Colour_b[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l1s_r"), View.light2_specular_Colour_r[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l1s_g"), View.light2_specular_Colour_g[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l1s_b"), View.light2_specular_Colour_b[0]); //$NON-NLS-1$

        GL20.glUniform1f(shaderProgram.getUniformLocation("l2_r"), View.light3_Colour_r[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l2_g"), View.light3_Colour_g[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l2_b"), View.light3_Colour_b[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l2s_r"), View.light3_specular_Colour_r[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l2s_g"), View.light3_specular_Colour_g[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l2s_b"), View.light3_specular_Colour_b[0]); //$NON-NLS-1$

        GL20.glUniform1f(shaderProgram.getUniformLocation("l3_r"), View.light4_Colour_r[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l3_g"), View.light4_Colour_g[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l3_b"), View.light4_Colour_b[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l3s_r"), View.light4_specular_Colour_r[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l3s_g"), View.light4_specular_Colour_g[0]); //$NON-NLS-1$
        GL20.glUniform1f(shaderProgram.getUniformLocation("l3s_b"), View.light4_specular_Colour_b[0]); //$NON-NLS-1$

        shaderProgram.setFactor(1f);
    }

    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_TEXTURE_2D);

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

    GL11.glDepthFunc(GL11.GL_LESS);
    GL11.glClearDepth(1.0f);
    GL11.glClearColor(View.background_Colour_r[0], View.background_Colour_g[0], View.background_Colour_b[0], 1.0f);

    GL11.glPointSize(5);

    modelRenderer.init();
    modelRendererLDrawStandard.init();
}
 
Example 16
Source File: GLShader.java    From ldparteditor with MIT License 4 votes vote down vote up
public void lightsOn() {
    GL20.glUniform1f(getUniformLocation("lightswitch"), 1f); //$NON-NLS-1$
}
 
Example 17
Source File: GLShader.java    From ldparteditor with MIT License 4 votes vote down vote up
public void setFactor(float f) {
    GL20.glUniform1f(getUniformLocation("factor"), f); //$NON-NLS-1$
}
 
Example 18
Source File: ShaderHelper.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void glUniform1f(int loc, float val) {
	GL20.glUniform1f(loc, val);
}
 
Example 19
Source File: GLShader.java    From ldparteditor with MIT License 4 votes vote down vote up
public void texmapOff() {
    GL20.glUniform1f(getUniformLocation("texmapswitch"), 0f); //$NON-NLS-1$
}
 
Example 20
Source File: GLShader.java    From ldparteditor with MIT License 4 votes vote down vote up
public void transparentOn() {
    GL20.glUniform1f(getUniformLocation("alphaswitch"), 1f); //$NON-NLS-1$
}