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

The following examples show how to use org.lwjgl.opengl.GL20#glUniform4f() . 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: 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 2
Source File: CurveRenderState.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int from, int to, boolean clearFirst) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, fbo.getVbo());
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
	if (clearFirst) {
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	}
	final int mirrors = OPTION_DANCE_MIRROR.state ? this.mirrors : 1;
	for (int i = 0; i < mirrors; i++) {
		if (pointsToRender == null) {
			renderCurve(from, to, i);
		} else {
			renderCurve(i);
		}
		//from++;
		//to++;
	}
	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
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: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int from, int to, boolean clearFirst) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, fbo.getVbo());
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
	if (clearFirst)
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	if (pointsToRender == null) {
		for (int i = from * 2; i < to * 2 - 1; ++i) {
			if (spliceFrom <= i && i <= spliceTo)
				continue;
			GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	} else {
		Iterator<Integer> iter = pointsToRender.iterator();
		while (iter.hasNext()) {
			for (int i = iter.next() * 2, end = iter.next() * 2 - 1; i < end; ++i)
				GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	}
	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 5
Source File: CurveRenderState.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int to) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform4f(staticState.colLoc, color.r, color.g, color.b, color.a);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);

	float lastSegmentX = to == 0 ? curve[1].x - curve[0].x : curve[to].x - curve[to-1].x;
	float lastSegmentY = to == 0 ? curve[1].y - curve[0].y : curve[to].y - curve[to-1].y;
	float lastSegmentInvLen = 1.f/(float)Math.hypot(lastSegmentX, lastSegmentY);
	GL20.glUniform4f(staticState.endPointLoc, curve[to].x, curve[to].y, lastSegmentX * lastSegmentInvLen, lastSegmentY * lastSegmentInvLen);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);

	GL11.glColorMask(false,false,false,false);
	GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, pointIndices[to]);
	GL11.glColorMask(true,true,true,true);
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GL11.glDepthFunc(GL11.GL_EQUAL);
	GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, pointIndices[to]);
	GL11.glDepthFunc(GL11.GL_LESS);

	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 6
Source File: BlurPane.java    From LWJGUI with MIT License 4 votes vote down vote up
@Override
public void render(Context context, int x, int y, int w, int h) {
	if ( !isVisible() )
		return;
	
	if ( this.quad == null || quadDirty ) {
		if ( this.quad != null ) {
			this.quad.cleanup();
		}
		quad = new TexturedQuad(0, 0, w, h, source.getTexId());
	}
	
	GL11.glViewport(x, y, w, h);
	this.quadDirty = false;
	quadShader.bind();
	quadShader.projectOrtho(0, h, w, -h);
	
	// bind stuff
	GL13.glActiveTexture(GL13.GL_TEXTURE0);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, source.getTexId());
	
	if ( internalBackground instanceof BackgroundSolid ) {
		BackgroundSolid bg = (BackgroundSolid)internalBackground;
		GL20.glUniform4f(GL20.glGetUniformLocation(quadShader.getProgram(), "uColor"),
				bg.getColor().getRed()/255f-0.5f,
				bg.getColor().getGreen()/255f-0.5f,
				bg.getColor().getBlue()/255f-0.5f,
				bg.getColor().getAlpha()/255f);
	}
	GL20.glUniform1f(GL20.glGetUniformLocation(quadShader.getProgram(), "uBlurSize"), blurRadius);
	GL20.glUniform2f(GL20.glGetUniformLocation(quadShader.getProgram(), "uTexelSize"), 1.0f/(float)w, 1.0f/(float)h);
	GL20.glUniform4f(GL20.glGetUniformLocation(quadShader.getProgram(), "uCornerRadii"), (float)Math.max(BlurPane.this.getBorderRadii()[0], 0.1), (float)Math.max(BlurPane.this.getBorderRadii()[1], 0.1), (float)Math.max(BlurPane.this.getBorderRadii()[2], 0.1), (float)Math.max(BlurPane.this.getBorderRadii()[3], 0.1));
	
	
	// Draw quad
	if ( context.isCoreOpenGL() ) {
		if ( quad != null ) {
			quad.render();
		}
	} else {

		GL13.glActiveTexture(GL13.GL_TEXTURE0);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, source.getTexId());
		
		GL11.glBegin(GL11.GL_QUADS);
			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(0, 0);
			GL11.glVertex2f(0, 0);
	
			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(1, 0);
			GL11.glVertex2f(w, 0);
	
			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(1, 1);
			GL11.glVertex2f(w, h);
	
			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(0, 1);
			GL11.glVertex2f(0, h);
		GL11.glEnd();
	}
}
 
Example 7
Source File: UniformVec4.java    From LowPolyWater with The Unlicense 4 votes vote down vote up
public void loadVec4(float x, float y, float z, float w) {
	GL20.glUniform4f(super.getLocation(), x, y, z, w);
}
 
Example 8
Source File: UniformVec4.java    From OpenGL-Animation with The Unlicense 4 votes vote down vote up
public void loadVec4(float x, float y, float z, float w) {
	GL20.glUniform4f(super.getLocation(), x, y, z, w);
}
 
Example 9
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 4 votes vote down vote up
@Override
public void draw2D(GeometryHandle geometry, TextureHandle texture, int primitive, int offset, int vertices, float x, float y, float z, float sx, float sy, float sz, AbstractColor color, float intensity){
	boolean changeColor = false;

	float r, g, b, a;
	if(color != null) {
		r = color.red*intensity;
		g = color.green*intensity;
		b = color.blue*intensity;
		a = color.alpha;
	} else {
		r = g = b = intensity;
		a = 1;
	}

	if(texture == null) {
		useProgram(prog_color);
		if(clr != r || clg != g || clb != b || cla != a) {
			clr = r;
			clg = g;
			clb = b;
			cla = a;
			changeColor = true;
		}
	} else {
		bindTexture(texture);
		useProgram(prog_tex);
		if(tlr != r || tlg != g || tlb != b || tla != a) {
			tlr = r;
			tlg = g;
			tlb = b;
			tla = a;
			changeColor = true;
		}
	}

	GL20.glUniform3fv(lastProgram.ufs[TRANS], new float[] {x, y, z, sx, sy, sz});

	if(changeColor) {
		GL20.glUniform4f(lastProgram.ufs[COLOR], r, g, b, a);
	}

	if(glcaps.GL_ARB_vertex_array_object) {
		bindFormat(geometry.getInternalFormatId());
	} else {
		bindGeometry(geometry);
		specifyFormat(geometry.getFormat());
	}
	GL11.glDrawArrays(primitive, offset*vertices, vertices);
}
 
Example 10
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 4 votes vote down vote up
@Override
public void drawUnified2D(GeometryHandle geometry, TextureHandle texture, int primitive, int offset, int vertices, boolean image, boolean shadow, float x, float y, float z, float sx, float sy, float sz, AbstractColor color, float intensity) {
	useProgram(prog_unified);
	bindTexture(texture);

	if(image) {
		float r, g, b, a;
		if (color != null) {
			r = color.red * intensity;
			g = color.green * intensity;
			b = color.blue * intensity;
			a = color.alpha;
		} else {
			r = g = b = intensity;
			a = 1;
		}

		if(ulr != r || ulg != g || ulb != b || ula != a) {
			ulr = r;
			ulg = g;
			ulb = b;
			ula = a;
			GL20.glUniform4f(prog_unified.ufs[COLOR], r, g, b, a);
		}
	}

	if(ulim != image || ulsh != shadow || uli != intensity) {
		GL20.glUniform3f(prog_unified.ufs[UNI_INFO], image?1:0, shadow?1:0, intensity);
		ulim = image;
		ulsh = shadow;
		uli = intensity;
	}

	GL20.glUniform3fv(lastProgram.ufs[TRANS], new float[] {x, y, z, sx, sy, sz});

	if(glcaps.GL_ARB_vertex_array_object) {
		bindFormat(geometry.getInternalFormatId());
	} else {
		bindGeometry(geometry);
		specifyFormat(geometry.getFormat());
	}
	GL11.glDrawArrays(primitive, offset*vertices, vertices);
}