Java Code Examples for org.lwjgl.opengl.GL20#glUseProgram()
The following examples show how to use
org.lwjgl.opengl.GL20#glUseProgram() .
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: ShaderProgram.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
/** * Binds this shader for use, Lazily allocates, links * and compiles all {@link ShaderObject}s. */ public void use() { if (bound) { throw new IllegalStateException("Already bound."); } if (programId == -1 || shaders.stream().anyMatch(ShaderObject::isDirty)) { shaders.forEach(ShaderObject::alloc); if (programId == -1) { programId = GL20.glCreateProgram(); if (programId == 0) { throw new IllegalStateException("Allocation of ShaderProgram has failed."); } shaders.forEach(shader -> GL20.glAttachShader(programId, shader.getShaderID())); } GL20.glLinkProgram(programId); if (GL20.glGetProgrami(programId, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) { throw new RuntimeException("ShaderProgram linkage failure. \n" + GL20.glGetProgramInfoLog(programId)); } shaders.forEach(shader -> shader.onLink(programId)); uniformCache.onLink(); } GL20.glUseProgram(programId); bound = true; }
Example 2
Source File: DesktopComputeJobManager.java From graphicsfuzz with Apache License 2.0 | 6 votes |
@Override public JsonObject executeComputeShader() { GL20.glUseProgram(program); checkError(); GL43.glDispatchCompute(numGroups[0], numGroups[1], numGroups[2]); checkError(); GL42.glMemoryBarrier(GL43.GL_SHADER_STORAGE_BARRIER_BIT); checkError(); GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, shaderStorageBufferObject); checkError(); final IntBuffer dataFromComputeShader = GL15.glMapBuffer(GL43.GL_SHADER_STORAGE_BUFFER, GL15.GL_READ_ONLY) .asIntBuffer(); checkError(); final JsonArray jsonArray = new JsonArray(); for (int i = 0; i < dataFromComputeShader.limit(); i++) { jsonArray.add(dataFromComputeShader.get(i)); } final JsonObject result = new JsonObject(); result.add("output", jsonArray); return result; }
Example 3
Source File: CurveRenderState.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * 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 4
Source File: CurveRenderState.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Backup the current state of the relevant OpenGL state and change it to * what's needed to draw the curve. */ private RenderState saveRenderState() { RenderState state = new RenderState(); state.smoothedPoly = GL11.glGetBoolean(GL11.GL_POLYGON_SMOOTH); state.blendEnabled = GL11.glGetBoolean(GL11.GL_BLEND); state.depthEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_TEST); state.depthWriteEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_WRITEMASK); state.texEnabled = GL11.glGetBoolean(GL11.GL_TEXTURE_2D); state.oldProgram = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM); state.oldArrayBuffer = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING); GL11.glDisable(GL11.GL_POLYGON_SMOOTH); GL11.glEnable(GL11.GL_BLEND); GL14.glBlendEquation(GL14.GL_FUNC_ADD); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthMask(true); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_TEXTURE_1D); GL11.glBindTexture(GL11.GL_TEXTURE_1D, staticState.gradientTexture); GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL20.glUseProgram(0); GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); return state; }
Example 5
Source File: LegacyCurveRenderState.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * 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 6
Source File: CurveRenderState.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
/** * 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 7
Source File: LegacyCurveRenderState.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Backup the current state of the relevant OpenGL state and change it to * what's needed to draw the curve. */ private RenderState saveRenderState() { RenderState state = new RenderState(); state.smoothedPoly = GL11.glGetBoolean(GL11.GL_POLYGON_SMOOTH); state.blendEnabled = GL11.glGetBoolean(GL11.GL_BLEND); state.depthEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_TEST); state.depthWriteEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_WRITEMASK); state.texEnabled = GL11.glGetBoolean(GL11.GL_TEXTURE_2D); state.texUnit = GL11.glGetInteger(GL13.GL_ACTIVE_TEXTURE); state.oldProgram = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM); state.oldArrayBuffer = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING); GL11.glDisable(GL11.GL_POLYGON_SMOOTH); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthMask(true); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_TEXTURE_1D); GL11.glBindTexture(GL11.GL_TEXTURE_1D, staticState.gradientTexture); GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL20.glUseProgram(0); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix(); GL11.glLoadIdentity(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPushMatrix(); GL11.glLoadIdentity(); return state; }
Example 8
Source File: LitematicaRenderer.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
public static void disableAlphaShader() { if (OpenGlHelper.shadersSupported) { GL20.glUseProgram(0); } }
Example 9
Source File: ShaderHelper.java From OpenModsLib with MIT License | 4 votes |
@Override public void glUseProgram(int program) { GL20.glUseProgram(program); }
Example 10
Source File: MixinFontRenderer.java From LiquidBounce with GNU General Public License v3.0 | 4 votes |
@Inject(method = "renderStringAtPos", at = @At(value = "RETURN"), require = 1) private void injectRainbow6(String text, boolean shadow, CallbackInfo ci) { if (rainbowEnabled1) { GL20.glUseProgram(RainbowFontShader.INSTANCE.getProgramId()); } }
Example 11
Source File: ShaderProgram.java From OpenGL-Animation with The Unlicense | 4 votes |
public void stop() { GL20.glUseProgram(0); }
Example 12
Source File: ShaderProgram.java From LowPolyWater with The Unlicense | 4 votes |
public void cleanUp() { GL20.glUseProgram(0); GL20.glDeleteProgram(programID); }
Example 13
Source File: ShaderProgram.java From LowPolyWater with The Unlicense | 4 votes |
public void stop() { GL20.glUseProgram(0); }
Example 14
Source File: ShaderProgram.java From LowPolyWater with The Unlicense | 4 votes |
public void start() { GL20.glUseProgram(programID); }
Example 15
Source File: OpenGL3_TheQuadTextured.java From ldparteditor with MIT License | 4 votes |
private void loopCycle() { // Logic while(Keyboard.next()) { // Only listen to events where the key was pressed (down event) if (!Keyboard.getEventKeyState()) continue; // Switch textures depending on the key released switch (Keyboard.getEventKey()) { case Keyboard.KEY_1: textureSelector = 0; break; case Keyboard.KEY_2: textureSelector = 1; break; } } // Render GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL20.glUseProgram(pId); // Bind the texture GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texIds[textureSelector]); // Bind to the VAO that has all the information about the vertices GL30.glBindVertexArray(vaoId); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); GL20.glEnableVertexAttribArray(2); // Bind to the index VBO that has all the information about the order of the vertices GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); // Draw the vertices GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0); // Put everything back to default (deselect) GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(2); GL30.glBindVertexArray(0); GL20.glUseProgram(0); this.exitOnGLError("loopCycle"); }
Example 16
Source File: GLShader.java From ldparteditor with MIT License | 4 votes |
public void use() { GL20.glUseProgram(program); }
Example 17
Source File: MixinFontRenderer.java From LiquidBounce with GNU General Public License v3.0 | 4 votes |
@Inject(method = "renderStringAtPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;color(FFFF)V", ordinal = 1), require = 1) private void injectRainbow4(String text, boolean shadow, CallbackInfo ci) { if (rainbowEnabled1) { GL20.glUseProgram(RainbowFontShader.INSTANCE.getProgramId()); } }
Example 18
Source File: MixinFontRenderer.java From LiquidBounce with GNU General Public License v3.0 | 4 votes |
@Inject(method = "renderStringAtPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;color(FFFF)V", ordinal = 0), require = 1) private void injectRainbow3(String text, boolean shadow, CallbackInfo ci) { if (rainbowEnabled1) { GL20.glUseProgram(0); } }
Example 19
Source File: GLShader.java From ldparteditor with MIT License | 4 votes |
void dispose() { GL20.glUseProgram(0); GL20.glDeleteProgram(program); uniformMap.clear(); }
Example 20
Source File: MixinFontRenderer.java From LiquidBounce with GNU General Public License v3.0 | 4 votes |
@Inject(method = "renderStringAtPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;setColor(FFFF)V", ordinal = 1), require = 1) private void injectRainbow4(String text, boolean shadow, CallbackInfo ci) { if (rainbowEnabled1) { GL20.glUseProgram(RainbowFontShader.INSTANCE.getProgramId()); } }