List of usage examples for org.lwjgl.opengl GL20 glGetUniformLocation
@NativeType("GLint") public static int glGetUniformLocation(@NativeType("GLuint") int program, @NativeType("GLchar const *") CharSequence name)
From source file:org.oscim.gdx.LwjglGL20.java
License:Apache License
public int getUniformLocation(int program, String name) { return GL20.glGetUniformLocation(program, name); }
From source file:org.spout.engine.renderer.shader.variables.ShaderVariable.java
License:Open Source License
@SuppressWarnings("unused") public ShaderVariable(int program, String name) { if (((Client) Spout.getEngine()).getRenderMode() == RenderMode.GL11) { return; //Shaders don't exist in OpenGL 1.1 }/*from ww w . ja va 2s . c o m*/ this.program = program; //If we are an attribute, we aren't a uniform. Don't continue if (this instanceof AttributeShaderVariable) { return; } this.location = GL20.glGetUniformLocation(program, name); //Error Checking. In production, leave this as a warning, because OpenGL doesn't care if you try to put something //into a variable that doesn't exist (it ignores it). // //If we want to have a debug mode, switch the final bool to true to throw an exception if the variable doesn't exist. //This is the same as treating warnings as errors, and could be useful for debugging shaders. if (this.location == -1 && variableError == 1) { System.out.println("[Warning] Shader Variable: " + name + " not found! (Was it optimized out?)"); } else if (this.location == -1 && variableError == 2) { throw new ShaderVariableNotFoundException(name); } }
From source file:org.spout.renderer.lwjgl.gl20.GL20Program.java
License:Open Source License
@Override public void link() { checkCreated();//w w w . ja v a2 s. c om // Add the attribute layouts to the program state final TObjectIntIterator<String> iterator = attributeLayouts.iterator(); while (iterator.hasNext()) { iterator.advance(); // Bind the index to the name GL20.glBindAttribLocation(id, iterator.value(), iterator.key()); } // Link program GL20.glLinkProgram(id); // Check program link status if (GL20.glGetProgrami(id, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) { throw new IllegalStateException("Program could not be linked\n" + GL20.glGetProgramInfoLog(id, 1000)); } if (CausticUtil.isDebugEnabled()) { // Validate program GL20.glValidateProgram(id); // Check program validation status if (GL20.glGetProgrami(id, GL20.GL_VALIDATE_STATUS) == GL11.GL_FALSE) { final Logger logger = CausticUtil.getCausticLogger(); logger.log(Level.WARNING, "Program validation failed. This doesn''t mean it won''t work, so you maybe able to ignore it\n{0}", GL20.glGetProgramInfoLog(id, 1000)); } } // Load uniforms uniforms.clear(); final int uniformCount = GL20.glGetProgrami(id, GL20.GL_ACTIVE_UNIFORMS); for (int i = 0; i < uniformCount; i++) { final ByteBuffer nameBuffer = CausticUtil.createByteBuffer(256); GL20.glGetActiveUniform(id, i, CausticUtil.createIntBuffer(1), CausticUtil.createIntBuffer(1), CausticUtil.createIntBuffer(1), nameBuffer); nameBuffer.rewind(); final byte[] nameBytes = new byte[256]; nameBuffer.get(nameBytes); // Simplify array names final String name = new String(nameBytes).trim().replaceFirst("\\[\\d+\\]", ""); uniforms.put(name, GL20.glGetUniformLocation(id, name)); } // Check for errors LWJGLUtil.checkForGLError(); }
From source file:org.terasology.logic.characters.GelatinousCube.java
License:Apache License
public void render() { super.render(); glPushMatrix();/* w w w.j ava 2 s. c o m*/ glTranslated(getPosition().x - _parent.getWorldProvider().getRenderingReferencePoint().x, getPosition().y - _parent.getWorldProvider().getRenderingReferencePoint().y, getPosition().z - _parent.getWorldProvider().getRenderingReferencePoint().z); glRotatef((float) _yaw, 0f, 1f, 0f); TextureManager.getInstance().bindTexture("slime"); // Setup the shader ShaderManager.getInstance().enableShader("gelatinousCube"); int tick = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("gelatinousCube"), "tick"); GL20.glUniform1f(tick, _parent.getTick()); int cOffset = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("gelatinousCube"), "colorOffset"); GL20.glUniform4f(cOffset, COLORS[_randomColorId].x, COLORS[_randomColorId].y, COLORS[_randomColorId].z, 1.0f); int light = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("gelatinousCube"), "light"); GL20.glUniform1f(light, _parent.getRenderingLightValueAt(getPosition())); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); _mesh.render(); glDisable(GL_BLEND); ShaderManager.getInstance().enableShader(null); glPopMatrix(); }
From source file:org.terasology.logic.characters.Player.java
License:Apache License
/** * Renders a simple hand displayed in front of the player's first person perspective. *///from www. j a v a 2s. c o m public void renderHand() { glEnable(GL11.GL_TEXTURE_2D); TextureManager.getInstance().bindTexture("char"); ShaderManager.getInstance().enableShader("block"); int light = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("block"), "light"); GL20.glUniform1f(light, _parent.getRenderingLightValueAt(getPosition())); // Make sure the hand is not affected by the biome color. ZOMBIES!!!! FloatBuffer colorBuffer = BufferUtils.createFloatBuffer(3); colorBuffer.put(1.0f); colorBuffer.put(1.0f); colorBuffer.put(1.0f); colorBuffer.flip(); int colorOffset = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("block"), "colorOffset"); GL20.glUniform3(colorOffset, colorBuffer); glPushMatrix(); glTranslatef(0.8f, -1.1f + (float) calcBobbingOffset((float) Math.PI / 8f, 0.05f, 2.5f) - _handMovementAnimationOffset * 0.5f, -1.0f - _handMovementAnimationOffset * 0.5f); glRotatef(-45f - _handMovementAnimationOffset * 64.0f, 1.0f, 0.0f, 0.0f); glRotatef(35f, 0.0f, 1.0f, 0.0f); glTranslatef(0f, 0.25f, 0f); glScalef(0.3f, 0.6f, 0.3f); if (_handMesh == null) { Vector2f texPos = new Vector2f(40.0f * 0.015625f, 32.0f * 0.03125f); Vector2f texWidth = new Vector2f(4.0f * 0.015625f, -12.0f * 0.03125f); MeshCollection.addBlockMesh(new Vector4f(1, 1, 1, 1), texPos, texWidth, 1.0f, 1.0f, 0.5f, 0.0f, 0.0f, 0.0f); _handMesh = Tessellator.getInstance().generateMesh(); Tessellator.getInstance().resetAll(); } _handMesh.render(); glPopMatrix(); glDisable(GL11.GL_TEXTURE_2D); ShaderManager.getInstance().enableShader(null); }
From source file:org.terasology.model.inventory.ItemBlock.java
License:Apache License
@Override public boolean renderFirstPersonView() { Block activeBlock = BlockManager.getInstance().getBlock(_blockId); TextureManager.getInstance().bindTexture("terrain"); ShaderManager.getInstance().enableShader("block"); // Adjust the brightness of the block according to the current position of the player int light = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("block"), "light"); GL20.glUniform1f(light, Terasology.getInstance().getActiveWorldRenderer().getRenderingLightValue()); // Apply biome and overall color offset FloatBuffer colorBuffer = BufferUtils.createFloatBuffer(3); Vector4f color = activeBlock.calcColorOffsetFor(Block.SIDE.FRONT, Terasology.getInstance().getActiveWorldRenderer().getActiveTemperature(), Terasology.getInstance().getActiveWorldRenderer().getActiveTemperature()); colorBuffer.put(color.x);// w w w .j a va2 s.com colorBuffer.put(color.y); colorBuffer.put(color.z); colorBuffer.flip(); int colorOffset = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("block"), "colorOffset"); GL20.glUniform3(colorOffset, colorBuffer); glEnable(GL11.GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glAlphaFunc(GL_GREATER, 0.1f); glPushMatrix(); glTranslatef(1.0f, -1.3f + (float) getParent().calcBobbingOffset((float) Math.PI / 8f, 0.05f, 2.5f) - getParent().getHandMovementAnimationOffset() * 0.5f, -1.5f - getParent().getHandMovementAnimationOffset() * 0.5f); glRotatef(-25f - getParent().getHandMovementAnimationOffset() * 64.0f, 1.0f, 0.0f, 0.0f); glRotatef(35f, 0.0f, 1.0f, 0.0f); glTranslatef(0f, 0.25f, 0f); activeBlock.render(); glPopMatrix(); glDisable(GL11.GL_BLEND); ShaderManager.getInstance().enableShader(null); return true; }
From source file:org.terasology.model.inventory.VoxelItem.java
License:Apache License
@Override public boolean renderFirstPersonView() { ShaderManager.getInstance().enableShader("block"); int light = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("block"), "light"); GL20.glUniform1f(light, Terasology.getInstance().getActiveWorldRenderer().getRenderingLightValue()); int textured = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("block"), "textured"); GL20.glUniform1i(textured, 0);/*w w w. ja v a2s .c o m*/ glPushMatrix(); glTranslatef(1.0f, -1.3f + (float) getParent().calcBobbingOffset((float) Math.PI / 8f, 0.05f, 2.5f) - getParent().getHandMovementAnimationOffset() * 0.5f, -1.5f - getParent().getHandMovementAnimationOffset() * 0.5f); glRotatef(-getParent().getHandMovementAnimationOffset() * 64.0f, 1.0f, 0.0f, 0.0f); glRotatef(-20f, 1.0f, 0.0f, 0.0f); glRotatef(-80f, 0.0f, 1.0f, 0.0f); glRotatef(45f, 0.0f, 0.0f, 1.0f); if (_itemMesh == null) _itemMesh = MeshFactory.getInstance().generateItemMesh(_iconX, _iconY); _itemMesh.render(); glPopMatrix(); ShaderManager.getInstance().enableShader(null); return true; }
From source file:org.terasology.rendering.assets.GLSLShaderProgramInstance.java
License:Apache License
private int getUniformLocation(int activeShaderProgramId, String desc) { Integer id = uniformLocationMap.get(desc + ":" + getActiveShaderProgramId()); if (id == null) { id = GL20.glGetUniformLocation(activeShaderProgramId, desc); //The ';' character ensures uniqueness. uniformLocationMap.put(desc + ":" + activeShaderProgramId, id); }//from w w w . jav a 2 s . com return id; }
From source file:org.terasology.rendering.assets.Material.java
License:Apache License
public void setFloat(String desc, float f) { if (isDisposed()) return;//from w w w . j a v a 2 s . c o m enable(); int id = GL20.glGetUniformLocation(shaderProgram, desc); if (id != -1) { GL20.glUniform1f(id, f); } }
From source file:org.terasology.rendering.assets.Material.java
License:Apache License
public void setFloat2(String desc, float f1, float f2) { if (isDisposed()) return;//w w w . j a v a 2 s. c o m enable(); int id = GL20.glGetUniformLocation(shaderProgram, desc); if (id != -1) { GL20.glUniform2f(id, f1, f2); } }