List of usage examples for org.lwjgl.opengl GL11 glTexParameteri
public static void glTexParameteri(@NativeType("GLenum") int target, @NativeType("GLenum") int pname, @NativeType("GLint") int param)
From source file:fi.conf.prograts.ar.gl.GLTextureRoutines.java
License:LGPL
/** * Request unused OpenGL texture ID's./*from ww w . j a v a2 s . c om*/ * * @param count - How many texture IDs are being requested. * @return Requested texture ID's as integer array. */ public static int[] allocateGLTextureIDs(int count) { if (count > textureIDbuffer.capacity()) { allocateNewTextureIDBuffer(count); } textureIDbuffer.clear(); textureIDbuffer.limit(count); GL11.glGenTextures(textureIDbuffer); int[] textureIDs = new int[count]; for (int i = 0; i < count; i++) { if (!textureIDbuffer.hasRemaining()) break; textureIDs[i] = textureIDbuffer.get(); // preset this texture's minification and magnification filter int prevTextureID = bindTexture(textureIDs[i]); // GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); // 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); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); bindTexture(prevTextureID); } return textureIDs; }
From source file:fr.guillaume.prive.viper.core.model.texture.PNGTextureLoader.java
public static int loadTexture(String filename, int textureUnit) { ByteBuffer buf = null;//from w w w . j ava 2s .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.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;//w w w . jav a2s . c om } 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:game.engine.gfx.Texture.java
License:Open Source License
/** * Constructor./*w ww. ja v a 2 s. c o m*/ * * Note that this constructor changes the currently active texture unit * to GL_TEXTURE_2D to set the texture parameters. * * @param slickTexture the wrapped Slick texture */ public Texture(final org.newdawn.slick.opengl.Texture slickTexture) { this.slickTexture = slickTexture; glBindTexture(); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); }
From source file:go.graphics.swing.opengl.LWJGLDrawContext.java
License:Open Source License
/** * Sets the texture parameters, assuming that the texture was just created and is bound. *///from w w w.j av a 2 s. c o m private void setTextureParameters() { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glAlphaFunc(GL11.GL_GREATER, 0.5f); // prevent writing of transparent pixels to z buffer }
From source file:illarion.graphics.lwjgl.TextureAtlasLWJGL.java
License:Open Source License
/** * Activate the texture and prepare it for usage by OpenGL. * /*from w ww . ja va 2 s . c o m*/ * @param resizeable true in case the texture shall be loaded with advanced * rescaling methods, that are more calculation intensive but * look better then the normal ones * @param allowCompression true if the texture is compressed at default * settings, false if not. Best disallow compression for static * images such as tiles, since the effects of the compression * will be quite visible there */ @Override @SuppressWarnings("nls") public void activateTexture(final boolean resizeable, final boolean allowCompression) { if (!hasTextureData()) { throw new IllegalStateException("No texturedata loaded"); } final int quality = Graphics.getInstance().getQuality(); if (getTextureID() != 0) { removeTexture(); } // generate new texture ID final int texID = getNewTextureID(); setTextureID(texID); // bind texture ID DriverSettingsLWJGL.getInstance().enableTexture(texID); // prepare texture data if (resizeable) { // Textures will be resized -> smoothing would be good if (quality <= Graphics.QUALITY_LOW) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); } else if ((quality <= Graphics.QUALITY_NORMAL) || isNoMipMaps()) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); } else { if (GLContext.getCapabilities().OpenGL14) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE); } else { setNoMipMaps(true); } if (!isNoMipMaps()) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); } else { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); } } } else { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); } GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); if (GLContext.getCapabilities().OpenGL13) { GL11.glHint(GL13.GL_TEXTURE_COMPRESSION_HINT, GL11.GL_NICEST); } // setup texture compression final boolean activateCompression = GLContext.getCapabilities().OpenGL13 && ((allowCompression && (quality < Graphics.QUALITY_MAX)) || (quality <= Graphics.QUALITY_LOW)); if (isTextureRGBA()) { internalFormat = GL11.GL_RGBA; sourceFormat = GL11.GL_RGBA; if (activateCompression) { internalFormat = GL13.GL_COMPRESSED_RGBA; } } else if (isTextureRGB()) { internalFormat = GL11.GL_RGB; sourceFormat = GL11.GL_RGB; if (activateCompression) { internalFormat = GL13.GL_COMPRESSED_RGB; } } else if (isTextureGrey()) { internalFormat = GL11.GL_LUMINANCE; sourceFormat = GL11.GL_LUMINANCE; if (activateCompression) { internalFormat = GL13.GL_COMPRESSED_LUMINANCE; } } else if (isTextureGreyAlpha()) { internalFormat = GL11.GL_LUMINANCE_ALPHA; sourceFormat = GL11.GL_LUMINANCE_ALPHA; if (activateCompression) { internalFormat = GL13.GL_COMPRESSED_LUMINANCE_ALPHA; } } final ByteBuffer texData = getTextureData(); final int texWidth = getTextureWidth(); final int texHeight = getTextureHeight(); // produce a texture from the byte buffer GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, internalFormat, texWidth, texHeight, 0, sourceFormat, GL11.GL_UNSIGNED_BYTE, texData); if (quality < Graphics.QUALITY_MAX) { texIDBuffer.rewind(); GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, 0, GL13.GL_TEXTURE_COMPRESSED, texIDBuffer); texData.rewind(); if (texIDBuffer.get(0) == GL11.GL_FALSE) { int newInternalFormat = internalFormat; if (internalFormat == GL13.GL_COMPRESSED_LUMINANCE_ALPHA) { newInternalFormat = GL13.GL_COMPRESSED_RGBA; } else if (internalFormat == GL13.GL_COMPRESSED_LUMINANCE) { newInternalFormat = GL13.GL_COMPRESSED_RGB; } final int orgSize = texData.remaining(); if (newInternalFormat != internalFormat) { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, newInternalFormat, texWidth, texHeight, 0, sourceFormat, GL11.GL_UNSIGNED_BYTE, texData); GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, 0, GL13.GL_TEXTURE_COMPRESSED_IMAGE_SIZE, texIDBuffer); final int newSize = texIDBuffer.get(0); if (newSize > orgSize) { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, internalFormat, texWidth, texHeight, 0, sourceFormat, GL11.GL_UNSIGNED_BYTE, texData); } } } } texIDBuffer.rewind(); GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_INTERNAL_FORMAT, texIDBuffer); internalFormat = texIDBuffer.get(); discardImageData(); }
From source file:im.bci.jnuit.lwjgl.LwjglHelper.java
License:Open Source License
public static void setupGLTextureParams() { if (GLContext.getCapabilities().OpenGL12) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); } else {//from w w w . java 2 s . c o m GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); } setupGLTextureQualityParams(); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); }
From source file:im.bci.jnuit.lwjgl.LwjglHelper.java
License:Open Source License
public static void setupGLTextureQualityParams() { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); }
From source file:im.bci.jnuit.lwjgl.LwjglNuitFont.java
License:Open Source License
public static int loadImage(BufferedImage bufferedImage) { short width = (short) bufferedImage.getWidth(); short height = (short) bufferedImage.getHeight(); // textureLoader.bpp = bufferedImage.getColorModel().hasAlpha() ? // (byte)32 : (byte)24; int bpp = (byte) bufferedImage.getColorModel().getPixelSize(); ByteBuffer byteBuffer;//from w w w. ja v a2s . c o m DataBuffer db = bufferedImage.getData().getDataBuffer(); if (db instanceof DataBufferInt) { int intI[] = ((DataBufferInt) (bufferedImage.getData().getDataBuffer())).getData(); byte newI[] = new byte[intI.length * 4]; for (int i = 0; i < intI.length; i++) { byte b[] = intToByteArray(intI[i]); int newIndex = i * 4; newI[newIndex] = b[1]; newI[newIndex + 1] = b[2]; newI[newIndex + 2] = b[3]; newI[newIndex + 3] = b[0]; } byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()) .put(newI); } else { byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()) .put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData()); } byteBuffer.flip(); int internalFormat = GL11.GL_RGBA8, format = GL11.GL_RGBA; IntBuffer textureId = BufferUtils.createIntBuffer(1); GL11.glGenTextures(textureId); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId.get(0)); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, internalFormat, width, height, format, GL11.GL_UNSIGNED_BYTE, byteBuffer); return textureId.get(0); }
From source file:io.root.gfx.glutils.GL.java
License:Apache License
public static void glTexParameteri(int target, int pname, int param) { GL11.glTexParameteri(target, pname, param); }