List of usage examples for org.lwjgl.opengl GL20 glUniform1i
public static void glUniform1i(@NativeType("GLint") int location, @NativeType("GLint") int v0)
From source file:itdelatrisu.opsu.render.CurveRenderState.java
License:Open Source License
/** * Do the actual drawing of the curve into the currently bound framebuffer. * @param color the color of the curve//w w w . j ava2s. co m * @param borderColor the curve border color * @param curve the points along the curve */ private void draw_curve(Color color, Color borderColor, Vec2f[] curve) { staticState.initGradient(); RenderState state = startRender(); int vtx_buf; // the size is: floatsize * (position + texture coordinates) * (number of cones) * (vertices in a cone) FloatBuffer buff = BufferUtils .createByteBuffer(4 * (4 + 2) * (2 * curve.length - 1) * (NewCurveStyleState.DIVIDES + 2)) .asFloatBuffer(); staticState.initShaderProgram(); vtx_buf = GL15.glGenBuffers(); for (int i = 0; i < curve.length; ++i) { float x = curve[i].x; float y = curve[i].y; //if (i == 0 || i == curve.length - 1){ fillCone(buff, x, y, NewCurveStyleState.DIVIDES); if (i != 0) { float last_x = curve[i - 1].x; float last_y = curve[i - 1].y; double diff_x = x - last_x; double diff_y = y - last_y; x = (float) (x - diff_x / 2); y = (float) (y - diff_y / 2); fillCone(buff, x, y, NewCurveStyleState.DIVIDES); } } buff.flip(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vtx_buf); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buff, GL15.GL_STATIC_DRAW); 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); for (int i = 0; i < curve.length * 2 - 1; ++i) GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2); GL20.glDisableVertexAttribArray(staticState.texCoordLoc); GL20.glDisableVertexAttribArray(staticState.attribLoc); GL15.glDeleteBuffers(vtx_buf); endRender(state); }
From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java
License:Open Source License
@Override public void setUniform(int id, int value) { GL20.glUniform1i(id, value); }
From source file:kubex.gui.DepthPeelingLiquidRenderer.java
License:Creative Commons License
/** * Performs the depth peeling rendering//from w w w. java2s . co m */ @Override public void renderLayers(World w, int xres, int yres) { this.DPS.enable(); int upperLimitDepth = GL20.glGetUniformLocation(this.DPS.getID(), "upperLimitDepth"); int lowerLimitDepth = GL20.glGetUniformLocation(this.DPS.getID(), "lowerLimitDepth"); int upperLimitIndex = GL20.glGetUniformLocation(this.DPS.getID(), "upperLimitIndex"); GL20.glUniform1i(upperLimitDepth, KubexGame.LIQUIDLAYERS_TEXTURE_LOCATION); GL20.glUniform1i(lowerLimitDepth, KubexGame.BASEFBO_DEPTH_TEXTURE_LOCATION); GL20.glUniform1i(GL20.glGetUniformLocation(this.DPS.getID(), "xres"), xres); GL20.glUniform1i(GL20.glGetUniformLocation(this.DPS.getID(), "yres"), yres); w.overrideCurrentShader(this.DPS); //Makes world use the depth peeling shader when drawing chunks //Writes each liquid layer to a texture for (int i = 0; i < this.getNumLayers(); i++) { GL20.glUniform1i(upperLimitIndex, i - 1); glBindFramebuffer(GL_FRAMEBUFFER, this.layersFbos[i]); glClear(GL11.GL_DEPTH_BUFFER_BIT); GL11.glViewport(0, 0, xres, yres); w.drawLiquids(); } this.DPS.disable(); }
From source file:kubex.gui.FinalDrawManager.java
License:Creative Commons License
/** * Uploads to the deferred shader the uniforms it needs. For it, consults the shader capabilities. *//* w ww . ja v a2 s . c om*/ protected void uploadToShader(DeferredShaderProgram DSP, Matrix4f viewMatrix, Matrix4f projectionMatrix, float xres, float yres) { //Those uniforms are universal for all deferred shaders, they will be uploaded for each one of them MatrixHelper.uploadMatrix(viewMatrix, glGetUniformLocation(DSP.getID(), "viewMatrix")); MatrixHelper.uploadMatrix(projectionMatrix, glGetUniformLocation(DSP.getID(), "projectionMatrix")); glUniform1i(glGetUniformLocation(DSP.getID(), "colorTex"), DSP.colorTexLocation()); //The color texture of the shader can vary glUniform1i(glGetUniformLocation(DSP.getID(), "liquidLayersTex"), KubexGame.LIQUIDLAYERS_TEXTURE_LOCATION); glUniform1i(glGetUniformLocation(DSP.getID(), "baseFboDepthTex"), KubexGame.BASEFBO_DEPTH_TEXTURE_LOCATION); glUniform1i(glGetUniformLocation(DSP.getID(), "brightnessNormalTex"), KubexGame.BASEFBO_NORMALS_BRIGHTNESS_TEXTURE_LOCATION); glUniform1i(glGetUniformLocation(DSP.getID(), "liquidLayersTexLength"), this.liquidRenderer.getNumLayers()); if (DSP.miscTexLocation() != -1) glUniform1i(glGetUniformLocation(DSP.getID(), "miscTex"), DSP.miscTexLocation()); //Deferred shaders support up to 2 "misc" textures, if requested. if (DSP.miscTex2Location() != -1) glUniform1i(glGetUniformLocation(DSP.getID(), "miscTex2"), DSP.miscTex2Location()); //they are called misc to generalize them and upload them in different shaders //with different purposes each. glUniform1f(glGetUniformLocation(DSP.getID(), "cfar"), cfar); glUniform1f(glGetUniformLocation(DSP.getID(), "cnear"), cnear); glUniform1f(glGetUniformLocation(DSP.getID(), "cwidth"), xres); glUniform1f(glGetUniformLocation(DSP.getID(), "cheight"), yres); glUniform1f(glGetUniformLocation(DSP.getID(), "time"), (float) (System.currentTimeMillis() % 1000000) / 1000); //Uploads current time to the shaders, for them to do things like water flow. //The value can't grow forever as the float precission is moderate, so it will be truncated //to 1.000 sec maximum, moment in which the time will reset to 0 and the flow in the scene will blink //it will not be very noticeable and it will happen once each 20 min. //with one 0 more it will hapen once each 3 hours, but im scared of the float precision errors. GL20.glUniform1f(glGetUniformLocation(DSP.getID(), "daylightAmount"), this.world.getDaylightAmount()); Vector3f sunNormal = this.sky.getSunNormal(); GL20.glUniform3f(glGetUniformLocation(DSP.getID(), "sunNormal"), sunNormal.x, sunNormal.y, sunNormal.z); if (DSP.supportWorldPosition()) //If the shader needs to know the world position of the camera, upload it truncating it to a 500 val max, to avoid floating precision errors. { GL20.glUniform3f(glGetUniformLocation(DSP.getID(), "WorldPosition"), (float) (this.world.getCameraCenter().x % 500), (float) (this.world.getCameraCenter().y % 500), (float) (this.world.getCameraCenter().z % 500)); } //if shadows supported, upload the needed uniforms if (DSP.supportShadows()) { GL20.glUniform1i(glGetUniformLocation(DSP.getID(), "shadowMap"), KubexGame.SHADOW_TEXTURE_LOCATION); float[] dsplits = this.shadowsManager.getSplitDistances(); int splitDistances = glGetUniformLocation(DSP.getID(), "splitDistances"); switch (this.shadowsManager.getNumberSplits()) { case 1: GL20.glUniform4f(splitDistances, dsplits[1], 0, 0, 0); break; case 2: GL20.glUniform4f(splitDistances, dsplits[1], dsplits[2], 0, 0); break; case 3: GL20.glUniform4f(splitDistances, dsplits[1], dsplits[2], dsplits[3], 0); break; case 4: GL20.glUniform4f(splitDistances, dsplits[1], dsplits[2], dsplits[3], dsplits[4]); break; } int shadowMatrixes = glGetUniformLocation(DSP.getID(), "shadowMatrixes"); for (int i = 0; i < this.shadowsManager.getNumberSplits(); i++) { MatrixHelper.uploadMatrix(this.shadowsManager.getOrthoProjectionForSplitScreenAdjusted(i), shadowMatrixes + (i)); } } if (DSP.supportSkyParameters()) //if sky supported, upload all sky parameters { this.sky.uploadToShader(DSP); } if (DSP.supportPlayerLighting()) //If player lighting supported, upload players average lighting surrounding him. { int currentLightLoc = glGetUniformLocation(DSP.getID(), "currentLight"); GL20.glUniform1f(currentLightLoc, this.world.getAverageLightExposed()); } }
From source file:lessur.util.shader.ShaderManager.java
License:GNU General Public License
/** * //from www .j av a 2s . c om * @param program ID/index of the program * @param name Name of the variable * @param value Value to set the variable */ public void setUniform1i(int program, String name, int value) { if (has_opengl2) { int loc = GL20.glGetUniformLocation(program, name); checkVariableLocation(loc, name); GL20.glUniform1i(loc, value); } else if (has_arb) { int loc = ARBShaderObjects.glGetUniformLocationARB(program, name); checkVariableLocation(loc, name); ARBShaderObjects.glUniform1iARB(loc, value); } }
From source file:me.sunchiro.game.engine.gl.Graphic.java
License:Open Source License
private synchronized void render() { GL11.glClearColor(bgColor.x, bgColor.y, bgColor.z, 0); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL20.glUseProgram(shader.getPID());//from ww w . j ava2s . c o m // GL13.glActiveTexture(GL13.GL_TEXTURE0); GL30.glBindVertexArray(vaoId); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); GL20.glEnableVertexAttribArray(2); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid)); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); long offset = 0; int shift = 0; GL11.glAlphaFunc(GL11.GL_GREATER, 0.4f); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); for (Drawable object : objects) { Matrix4f finalMVP = new Matrix4f(mvpMat); Matrix4f modelMat = new Matrix4f(); Matrix4f scaler = new Matrix4f(); scaler.scale(object.scale * allScale); modelMat.translate(object.translation); modelMat.rotateXYZ(object.rotation.x, object.rotation.y, object.rotation.z); finalMVP.mul(modelMat); finalMVP.mul(scaler); finalMVP.get(0, matBuff); if (object.isChar) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid_charmap)); } GL20.glUniformMatrix4fv(shader.getMVPLocation(), false, matBuff); GL20.glUniform1i(shader.getInverseLocation(), object.inverseAlpha ? 1 : 0); if (object.isVisible()) GL32.glDrawElementsBaseVertex(GL11.GL_TRIANGLES, object.getIndices().length, GL11.GL_UNSIGNED_BYTE, offset, shift); offset += object.getIndices().length; shift += object.getVertex().length; if (object.isChar) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid)); } } render2d(offset, shift); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(2); GL30.glBindVertexArray(0); // GL20.glUseProgram(0); glfwSwapBuffers(window); glfwPollEvents(); }
From source file:me.sunchiro.game.engine.gl.Graphic.java
License:Open Source License
private void render2d(long offset, int shift) { cam.getOrthoMVP().get(0, matBuff);/*from ww w.j av a 2s. co m*/ GL20.glUniformMatrix4fv(shader.getMVPLocation(), false, matBuff); for (Drawable object : orthoObjects) { if (object.isChar) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid_charmap)); } GL20.glUniform1i(shader.getInverseLocation(), object.inverseAlpha ? 1 : 0); if (object.isVisible()) GL32.glDrawElementsBaseVertex(GL11.GL_TRIANGLES, object.getIndices().length, GL11.GL_UNSIGNED_BYTE, offset, shift); offset += object.getIndices().length; shift += object.getVertex().length; } // static utility function }
From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Program.java
License:Open Source License
@Override public void setUniform(String name, boolean b) { final int loc = uniforms.get(name); if (loc >= 0) { GL20.glUniform1i(loc, b ? 1 : 0); }/*from w ww . j a v a 2 s .com*/ }
From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Program.java
License:Open Source License
@Override public void setUniform(String name, int i) { final int loc = uniforms.get(name); if (loc >= 0) { GL20.glUniform1i(loc, i); }// w w w . j a v a 2 s . c o m }
From source file:net.betabears.the2dlibrary.graphics.shader.Uniform1i.java
@Override public void apply(int location) { GL20.glUniform1i(location, f0); }