List of usage examples for org.lwjgl.opengl GL13 glActiveTexture
public static void glActiveTexture(@NativeType("GLenum") int texture)
From source file:flash.display.ShaderInput.java
License:Open Source License
public void JITB$unapplyInput() { GL13.glActiveTexture(GL13.GL_TEXTURE0 + index()); glBindTexture(TextureUtil.mode(), 0); }
From source file:fr.guillaume.prive.viper.core.graphic.GraphicMotor.java
public static void draw() { GraphicMotor.checkInstance();//from ww w .j a va 2s . co m GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL20.glUseProgram(instance.shipShaderId); GL20.glUniform1i(instance.useTextureLocation, instance.drawPolygonFrame ? 0 : 1); int drawStyle = instance.drawPolygonFrame ? GL11.GL_LINE_LOOP : GL11.GL_TRIANGLES; GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, instance.shipTextureId); GL30.glBindVertexArray(instance.shipVaoId); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); GL20.glEnableVertexAttribArray(2); GL20.glEnableVertexAttribArray(3); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, instance.shipVboiId); GL11.glDrawElements(drawStyle, instance.shipVboiLenght, GL11.GL_UNSIGNED_INT, 0); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(2); GL20.glDisableVertexAttribArray(3); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); GL20.glUseProgram(0); }
From source file:fr.guillaume.prive.viper.core.model.texture.PNGTextureLoader.java
public static int loadTexture(String filename, int textureUnit) { ByteBuffer buf = null;// w w w . j ava 2 s .co m int tWidth = 0; int tHeight = 0; try (InputStream in = new FileInputStream(filename)) { PNGDecoder decoder = new PNGDecoder(in); tWidth = decoder.getWidth(); tHeight = decoder.getHeight(); buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); buf.flip(); in.close(); } catch (IOException e) { throw new IllegalStateException("PNG file i/o error", e); } // Create a new texture object in memory and bind it int texId = GL11.glGenTextures(); GL13.glActiveTexture(textureUnit); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); // All RGB bytes are aligned to each other and each component is 1 byte GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // Upload the texture data and generate mip maps (for scaling) GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA16, tWidth, tHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); // Setup the ST coordinate system GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); // Setup what to do when the texture has to be scaled GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GraphicMotor.exitOnGLError("loadPNGTexture"); return texId; }
From source file:fr.ign.cogit.geoxygene.appli.gl.RasterImage.java
License:Open Source License
/** * initialize the texture rendering//from w w w . j a v a 2 s . c o m * * @param programId */ public boolean initializeRendering(int programId) { // Enable GL texture // glEnable(GL_TEXTURE_2D); // Go find imageID and pass buffer of data to GPU Integer imageIndex = this.getImageId(); // Very important, activate the texture Slot GL13.glActiveTexture(this.getTextureSlot()); // Send the uniform to shader and bind it // glUniform1i(GL20.glGetUniformLocation(programId, "bufferImage"), imageIndex); glBindTexture(GL_TEXTURE_2D, imageIndex); return true; }
From source file:fr.ign.cogit.geoxygene.appli.render.DisplayableTextRenderer.java
License:Open Source License
private void drawText() throws GLException { if (this.program == null || this.textImage == null) { Logger.getRootLogger().debug("The GeoxGLTextRenderer " + this.hashCode() + "is not ready yet"); return;/*from w w w. ja v a2s . c o m*/ } this.textImage.getRGB(0, 0, width, height, this.pixels, 0, width); this.buffer.rewind(); for (int y = height - 1; y >= 0; y--) { for (int x = 0; x < width; x++) { int pixel = this.pixels[y * width + x]; this.buffer.put((byte) (pixel >> 16 & 0xFF)); // Red component this.buffer.put((byte) (pixel >> 8 & 0xFF)); // Green component this.buffer.put((byte) (pixel >> 0 & 0xFF)); // Blue component this.buffer.put((byte) (pixel >> 24 & 0xFF)); // Alpha component } } this.buffer.rewind(); glEnable(GL_TEXTURE_2D); GL13.glActiveTexture(GL13.GL_TEXTURE0 + 2); glBindTexture(GL_TEXTURE_2D, this.getTextTextureId()); // Setup texture scaling filtering GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.buffer); Integer fbow = (Integer) GLContext.getActiveGlContext() .getSharedUniform(GeoxygeneConstants.GL_VarName_FboWidth); Integer fboh = (Integer) GLContext.getActiveGlContext() .getSharedUniform(GeoxygeneConstants.GL_VarName_FboHeight); GL11.glViewport(0, 0, fbow, fboh); glDisable(GL11.GL_POLYGON_SMOOTH); GLContext.getActiveGlContext().setCurrentProgram(program); program.setUniform1i("colorTexture2", 2); GLTools.glCheckError("texture binding"); GL11.glDepthMask(false); glDisable(GL11.GL_DEPTH_TEST); GL30.glBindVertexArray(LayerViewGLPanel.getScreenQuad().getVaoId()); GLTools.glCheckError("before drawing textured quad VAO binding"); program.setUniform(GeoxygeneConstants.GL_VarName_ObjectOpacityVarName, 1f); program.setUniform(GeoxygeneConstants.GL_VarName_GlobalOpacityVarName, 1f); glEnable(GL_BLEND); GL11.glBlendFunc(GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL); GLTools.glCheckError("blending set for textured quad"); LwjglLayerRenderer.drawComplex(LayerViewGLPanel.getScreenQuad()); GLTools.glCheckError("Drawing textured quad"); GL30.glBindVertexArray(0); // unbind VAO GLTools.glCheckError("exiting Text rendering"); glBindTexture(GL_TEXTURE_2D, 0); // unbind texture }
From source file:fr.ign.cogit.geoxygene.appli.render.texture.BinaryGradientTexture.java
License:Open Source License
/** * @return the generated texture id/*from ww w. j ava2s. com*/ */ public final Integer getTextureId() { if (this.textureId < 0) { GL13.glActiveTexture(this.textureSlot); BinaryGradientImage gradientImage = this.getBinaryGradientImage(); int width = gradientImage.getWidth(); int height = gradientImage.getHeight(); // 16 = 4 floats (float = 4 bytes) = 16 ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * 16); double uMin = gradientImage.getuMin(); double vMin = gradientImage.getvMin(); double uRange = gradientImage.getuMax() - gradientImage.getuMin(); double vRange = gradientImage.getvMax() - gradientImage.getvMin(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { GradientPixel pixel = gradientImage.getPixel(x, y); buffer.putFloat((float) ((pixel.uTexture - uMin) / uRange)); buffer.putFloat((float) ((pixel.vTexture - vMin) / vRange)); // System.err.println("uvTexture = " // + (float) ((pixel.uTexture - uMin) / uRange) + "x" // + (float) ((pixel.vTexture - vMin) / vRange)); if (pixel.vGradient != null) { buffer.putFloat((float) pixel.vGradient.x); buffer.putFloat((float) pixel.vGradient.y); } else { // TODO: !! compute gradient !! buffer.putFloat(0f); buffer.putFloat(0f); } } } buffer.rewind(); // You now have a ByteBuffer filled with the color data of each // pixel. // Now just create a texture ID and bind it. Then you can load it // using // whatever OpenGL method you want, for example: this.textureId = glGenTextures(); // Generate texture ID glBindTexture(GL_TEXTURE_2D, this.textureId); // Bind texture ID glTexImage2D(GL_TEXTURE_2D, 0, GL30.GL_RGBA32F, width, height, 0, GL11.GL_RGBA, GL11.GL_FLOAT, buffer); // Setup texture scaling filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Return the texture ID so we can bind it later again } return this.textureId; }
From source file:fr.ign.cogit.geoxygene.appli.render.texture.BinaryGradientTexture.java
License:Open Source License
/** * initialize the texture rendering//from w w w . j av a2 s. c o m */ @Override public boolean initializeRendering(int programId) { Integer texIndex = this.getTextureId(); if (texIndex == null) { GL11.glDisable(GL_TEXTURE_2D); return false; } glEnable(GL_TEXTURE_2D); GL13.glActiveTexture(this.textureSlot); glBindTexture(GL_TEXTURE_2D, texIndex); // vMin has a special value '-1' = out of polygon // consider that vMin is always equal to zero float uMin = (float) (double) this.binaryGradientImage.getuMin(); float vMin = 0; float uRange = (float) (this.binaryGradientImage.getuMax() - this.binaryGradientImage.getuMin()); float vRange = (float) (double) (this.binaryGradientImage.getvMax()); GL20.glUniform2f(GL20.glGetUniformLocation(programId, gradientUVMinUniformVarname), uMin, vMin); GL20.glUniform2f(GL20.glGetUniformLocation(programId, gradientUVRangeUniformVarname), uRange, vRange); return true; }
From source file:fr.ign.cogit.geoxygene.util.gl.BasicTexture.java
License:Open Source License
/** * @return the generated texture id/*from w ww.j ava 2 s. c om*/ */ public Integer getTextureId() { if (this.textureId < 0) { GL13.glActiveTexture(this.textureSlot); BufferedImage textureImage = this.getTextureImage(); if (textureImage != null) { this.textureId = GLTools.loadOrRetrieveTexture(textureImage, false); } } return this.textureId; }
From source file:fr.ign.cogit.geoxygene.util.gl.BasicTexture.java
License:Open Source License
/** * initialize the texture rendering//from w w w . j a va2 s . c om */ @Override public boolean initializeRendering(int programId) { Integer texIndex = this.getTextureId(); if (texIndex == null || texIndex == -1) { GL11.glDisable(GL_TEXTURE_2D); return false; } glEnable(GL_TEXTURE_2D); GL13.glActiveTexture(this.textureSlot); glBindTexture(GL_TEXTURE_2D, texIndex); return true; }
From source file:fr.veridiangames.client.rendering.renderers.guis.Font3DRenderer.java
License:Open Source License
public void render(Gui3DShader shader, Camera camera, Color4f color, float dropShadow) { glDisable(GL_CULL_FACE);/*from w w w . j ava2 s. com*/ glEnable(GL_TEXTURE_2D); GL13.glActiveTexture(GL13.GL_TEXTURE0); font.fontTexture.bind(shader); float dist = camera.getTransform().getPosition().copy().sub(transform.getPosition()).magnitude(); transform.setLocalRotation(camera.getTransform().getRotation()); transform.setLocalScale(new Vec3(10.0f / (float) font.fontTexture.getHeight() * 0.5f)); if (dropShadow > 0) { shader.setModelViewMatrix( transform.toMatrix().mul(Mat4.translate(-w / 2 + dropShadow, -h / 2 - dropShadow, 0.3f))); shader.setColor(new Color4f(0, 0, 0, 0.8f)); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, vbo); glVertexAttribPointer(0, 3, GL_FLOAT, false, 5 * 4, 0); glVertexAttribPointer(1, 2, GL_FLOAT, false, 5 * 4, 12); glDrawArrays(GL_QUADS, 0, text.length() * 4); glEnableVertexAttribArray(1); glEnableVertexAttribArray(0); } shader.setModelViewMatrix(transform.toMatrix().mul(Mat4.translate(-w / 2, -h / 2, 0))); shader.setColor(color); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, vbo); glVertexAttribPointer(0, 3, GL_FLOAT, false, 5 * 4, 0); glVertexAttribPointer(1, 2, GL_FLOAT, false, 5 * 4, 12); glDrawArrays(GL_QUADS, 0, text.length() * 4); glEnableVertexAttribArray(1); glEnableVertexAttribArray(0); Texture.unbind(shader); glDisable(GL_TEXTURE_2D); glEnable(GL_CULL_FACE); }