List of usage examples for org.lwjgl.opengl GL20 glUseProgram
public static void glUseProgram(@NativeType("GLuint") int program)
From source file:org.oscim.gdx.LwjglGL20.java
License:Apache License
public void useProgram(int program) { GL20.glUseProgram(program); }
From source file:org.spout.engine.renderer.shader.ClientShader.java
License:Open Source License
@Override public void assign() { if (((Client) Spout.getEngine()).getRenderMode() == RenderMode.GL11) { assign(true);/*from w ww. ja va 2s. co m*/ return; } GL20.glUseProgram(program); for (ShaderVariable v : variables.values()) { v.assign(); } int i = 0; for (TextureSamplerShaderVariable v : textures.values()) { v.bind(i); i++; } }
From source file:org.terasology.logic.manager.ShaderManager.java
License:Apache License
public void enableMaterial(Material material) { if (material.isDisposed()) { // TODO: Fallback on default material return;//from ww w. j a va 2 s .com } if (!material.equals(activateMaterial)) { GL20.glUseProgram(material.getShaderId()); activateMaterial = material; _activeShaderProgram = null; } }
From source file:org.terasology.rendering.assets.GLSLShaderProgramInstance.java
License:Apache License
/** * Makes sure this shader program is the current shader program in the * OpenGL state./*from w w w . jav a2 s. c o m*/ * It checks if this shader program is the active shader program in the OpenGL * state, if not it sets this shader program to be the current shader program. */ public void enable() { GLSLShaderProgramInstance activeProgram = ShaderManager.getInstance().getActiveShaderProgram(); if (activeProgram != this || activeFeaturesChanged) { GL13.glActiveTexture(GL13.GL_TEXTURE0); GL20.glUseProgram(getActiveShaderProgramId()); // Make sure the shader manager knows that this program is currently active ShaderManager.getInstance().setActiveShaderProgram(this); activeFeaturesChanged = false; // Set the shader parameters if available if (shaderParameters != null) { shaderParameters.applyParameters(this); } prevValues.clear(); } }
From source file:org.terasology.rendering.assets.GLSLShaderProgramInstance.java
License:Apache License
/** * Sets the shader uniform of the current shader of this shader * program to be the given value.//from ww w. j a va 2 s . c o m * @param desc the uniform name, as used in the shader program itself. * @param i */ public void setIntForAllPermutations(String desc, int i) { TIntIntIterator it = shaderPrograms.iterator(); while (it.hasNext()) { it.advance(); GL20.glUseProgram(it.value()); int id = getUniformLocation(it.value(), desc); GL20.glUniform1i(id, i); } enable(); }
From source file:org.terasology.rendering.assets.GLSLShaderProgramInstance.java
License:Apache License
/** * Sets the shader uniform of the current shader of this shader * program to be the given value./*www. j a va 2 s . c om*/ * @param desc the uniform name, as used in the shader program itself. * @param b */ public void setBooleanForAllPermutations(String desc, boolean b) { TIntIntIterator it = shaderPrograms.iterator(); while (it.hasNext()) { it.advance(); GL20.glUseProgram(it.value()); int id = getUniformLocation(it.value(), desc); GL20.glUniform1i(id, b ? 1 : 0); } enable(); }
From source file:org.terasology.rendering.assets.GLSLShaderProgramInstance.java
License:Apache License
/** * Sets the shader uniform of the current shader of this shader * program to be the given value.//from ww w .j a v a 2s . c om * @param desc the uniform name, as used in the shader program itself. * @param f1 * @param f2 * @param f3 */ public void setFloat3ForAllPermutations(String desc, float f1, float f2, float f3) { TIntIntIterator it = shaderPrograms.iterator(); while (it.hasNext()) { it.advance(); GL20.glUseProgram(it.value()); int id = getUniformLocation(it.value(), desc); GL20.glUniform3f(id, f1, f2, f3); } enable(); }
From source file:org.terasology.rendering.nui.internal.Line.java
License:Apache License
public void draw(float x1, float y1, float x2, float y2, float width, Color color, Color background, float alpha) { GL20.glUseProgram(0); GL11.glDisable(GL11.GL_CULL_FACE);/*from w ww. j a v a2 s .c o m*/ GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); GL11.glEnableClientState(GL11.GL_COLOR_ARRAY); float t = 0; float r = 0; float f = width - (int) width; float a; boolean alphaBlend = alpha > 0; float cRed = color.rf(); float cGreen = color.gf(); float cBlue = color.bf(); float bRed = background.rf(); float bGreen = background.gf(); float bBlue = background.bf(); if (alphaBlend) { a = alpha; } else { a = 1.f; } if (width >= 0.0 && width < 1.0) { t = 0.05f; r = 0.48f + 0.32f * f; if (!alphaBlend) { cRed += 0.88 * (1 - f); cGreen += 0.88 * (1 - f); cBlue += 0.88 * (1 - f); if (cRed > 1.0f) { cRed = 1.0f; } if (cGreen > 1.0f) { cGreen = 1.0f; } if (cBlue > 1.0f) { cBlue = 1.0f; } } else { a *= f; } } else if (width >= 1.0 && width < 2.0) { t = 0.05f + f * 0.33f; r = 0.768f + 0.312f * f; } else if (width >= 2.0 && width < 3.0) { t = 0.38f + f * 0.58f; r = 1.08f; } else if (width >= 3.0 && width < 4.0) { t = 0.96f + f * 0.48f; r = 1.08f; } else if (width >= 4.0 && width < 5.0) { t = 1.44f + f * 0.46f; r = 1.08f; } else if (width >= 5.0 && width < 6.0) { t = 1.9f + f * 0.6f; r = 1.08f; } else if (width >= 6.0) { float ff = width - 6.0f; t = 2.5f + ff * 0.50f; r = 1.08f; } //determine angle of the line to horizontal float tx = 0; //core thinkness of a line float ty = 0; float rx = 0; //fading edge of a line float ry = 0; float cx = 0; //cap of a line float cy = 0; float epsilon = 0.01f; float dx = x2 - x1; float dy = y2 - y1; if (Math.abs(dx) < epsilon) { //vertical tx = t; ty = 0; rx = r; ry = 0; if (width > 0.0 && width < 1.0) { tx *= 8; } else if (width == 1.0) { tx *= 10; } } else if (Math.abs(dy) < epsilon) { //horizontal tx = 0; ty = t; rx = 0; ry = r; if (width > 0.0 && width < 1.0) { ty *= 8; } else if (width == 1.0) { ty *= 10; } } else { if (width < 3) { //approximate to make things even faster float m = dy / dx; //and calculate tx,ty,rx,ry if (m > -0.4142 && m <= 0.4142) { // -22.5< angle <= 22.5, approximate to 0 (degree) tx = t * 0.1f; ty = t; rx = r * 0.6f; ry = r; } else if (m > 0.4142 && m <= 2.4142) { // 22.5< angle <= 67.5, approximate to 45 (degree) tx = t * -0.7071f; ty = t * 0.7071f; rx = r * -0.7071f; ry = r * 0.7071f; } else if (m > 2.4142 || m <= -2.4142) { // 67.5 < angle <=112.5, approximate to 90 (degree) tx = t; ty = t * 0.1f; rx = r; ry = r * 0.6f; } else if (m > -2.4142 && m < -0.4142) { // 112.5 < angle < 157.5, approximate to 135 (degree) tx = t * 0.7071f; ty = t * 0.7071f; rx = r * 0.7071f; ry = r * 0.7071f; } } else { //calculate to exact dx = y1 - y2; dy = x2 - x1; float len = (float) Math.sqrt(dx * dx + dy * dy); dx /= len; dy /= len; cx = -0.6f * dy; cy = 0.6f * dx; tx = t * dx; ty = t * dy; rx = r * dx; ry = r * dy; } } //draw the line by triangle strip float[] lineVertex = { x1 - tx - rx, y1 - ty - ry, //fading edge1 x2 - tx - rx, y2 - ty - ry, x1 - tx, y1 - ty, //core x2 - tx, y2 - ty, x1 + tx, y1 + ty, x2 + tx, y2 + ty, x1 + tx + rx, y1 + ty + ry, //fading edge2 x2 + tx + rx, y2 + ty + ry }; GL11.glVertexPointer(2, 0, wrap(lineVertex)); if (!alphaBlend) { float[] lineColor = { bRed, bGreen, bBlue, bRed, bGreen, bBlue, cRed, cGreen, cBlue, cRed, cGreen, cBlue, cRed, cGreen, cBlue, cRed, cGreen, cBlue, bRed, bGreen, bBlue, bRed, bGreen, bBlue }; GL11.glColorPointer(3, 0, wrap(lineColor)); } else { float[] lineColor = { cRed, cGreen, cBlue, 0, cRed, cGreen, cBlue, 0, cRed, cGreen, cBlue, a, cRed, cGreen, cBlue, a, cRed, cGreen, cBlue, a, cRed, cGreen, cBlue, a, cRed, cGreen, cBlue, 0, cRed, cGreen, cBlue, 0 }; GL11.glColorPointer(4, 0, wrap(lineColor)); } if ((Math.abs(dx) < epsilon || Math.abs(dy) < epsilon) && width <= 1.0) { GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 6); } else { GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 8); } //cap (do not draw if too thin) if (width >= 3) { //draw cap lineVertex = new float[] { x1 - rx + cx, y1 - ry + cy, //cap1 x1 + rx + cx, y1 + ry + cy, x1 - tx - rx, y1 - ty - ry, x1 + tx + rx, y1 + ty + ry, x2 - rx - cx, y2 - ry - cy, //cap2 x2 + rx - cx, y2 + ry - cy, x2 - tx - rx, y2 - ty - ry, x2 + tx + rx, y2 + ty + ry }; GL11.glVertexPointer(2, 0, wrap(lineVertex)); if (!alphaBlend) { float[] lineColor = { bRed, bGreen, bBlue, //cap1 bRed, bGreen, bBlue, cRed, cGreen, cBlue, cRed, cGreen, cBlue, bRed, bGreen, bBlue, //cap2 bRed, bGreen, bBlue, cRed, cGreen, cBlue, cRed, cGreen, cBlue }; GL11.glColorPointer(3, 0, wrap(lineColor)); } else { float[] lineColor = { cRed, cGreen, cBlue, 0, //cap1 cRed, cGreen, cBlue, 0, cRed, cGreen, cBlue, a, cRed, cGreen, cBlue, a, cRed, cGreen, cBlue, 0, //cap2 cRed, cGreen, cBlue, 0, cRed, cGreen, cBlue, a, cRed, cGreen, cBlue, a }; GL11.glColorPointer(4, 0, wrap(lineColor)); } GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4); GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 4, 4); } GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY); GL11.glDisableClientState(GL11.GL_COLOR_ARRAY); GL11.glEnable(GL11.GL_CULL_FACE); }
From source file:org.terasology.rendering.opengl.GLSLMaterial.java
License:Apache License
@Override public void enable() { if (shaderManager.getActiveMaterial() != this || activeFeaturesChanged) { GL13.glActiveTexture(GL13.GL_TEXTURE0); GL20.glUseProgram(getActiveShaderProgramId()); // Make sure the shader manager knows that this program is currently active shaderManager.setActiveMaterial(this); activeFeaturesChanged = false;/*from w w w. j a va2 s . co m*/ // Set the shader parameters if available if (shaderParameters != null) { shaderParameters.applyParameters(this); } } }
From source file:org.terasology.rendering.opengl.GLSLMaterial.java
License:Apache License
@Override public void setFloat(String desc, float f, boolean currentOnly) { if (isDisposed()) { return;//from w w w . j ava 2s . c om } if (currentOnly) { enable(); int id = getUniformLocation(getActiveShaderProgramId(), desc); GL20.glUniform1f(id, f); } else { TIntIntIterator it = shaderPrograms.iterator(); while (it.hasNext()) { it.advance(); GL20.glUseProgram(it.value()); int id = getUniformLocation(it.value(), desc); GL20.glUniform1f(id, f); } restoreStateAfterUniformsSet(); } }