List of usage examples for org.lwjgl.opengl GL11 glTexImage2D
public static void glTexImage2D(@NativeType("GLenum") int target, @NativeType("GLint") int level, @NativeType("GLint") int internalformat, @NativeType("GLsizei") int width, @NativeType("GLsizei") int height, @NativeType("GLint") int border, @NativeType("GLenum") int format, @NativeType("GLenum") int type, @Nullable @NativeType("void const *") double[] pixels)
From source file:com.badlogic.gdx.backends.lwjgl.LwjglGL10.java
License:Apache License
public final void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels) { if (pixels == null) GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (ByteBuffer) null); else if (pixels instanceof ByteBuffer) GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (ByteBuffer) pixels); else if (pixels instanceof ShortBuffer) GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (ShortBuffer) pixels); else if (pixels instanceof IntBuffer) GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (IntBuffer) pixels); else if (pixels instanceof FloatBuffer) GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (FloatBuffer) pixels); else if (pixels instanceof DoubleBuffer) GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (DoubleBuffer) pixels); else// ww w .j a v a 2 s . c o m throw new GdxRuntimeException("Can't use " + pixels.getClass().getName() + " with this method. Use ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer or DoubleBuffer instead. Blame LWJGL"); }
From source file:com.badlogic.gdx.backends.lwjgl.LwjglGL20.java
License:Apache License
public void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels) { if (pixels == null) GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (ByteBuffer) null); else if (pixels instanceof ByteBuffer) GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (ByteBuffer) pixels); else if (pixels instanceof ShortBuffer) GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (ShortBuffer) pixels); else if (pixels instanceof IntBuffer) GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (IntBuffer) pixels); else if (pixels instanceof FloatBuffer) GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (FloatBuffer) pixels); else if (pixels instanceof DoubleBuffer) GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, (DoubleBuffer) pixels); else// w w w. ja v a2s. c o m throw new GdxRuntimeException("Can't use " + pixels.getClass().getName() + " with this method. Use ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer or DoubleBuffer instead. Blame LWJGL"); }
From source file:com.badlogic.gdx.hiero.Hiero4.java
License:Apache License
void updateFont(boolean force) { if (fontData == null || renderer.batch == null) return;/* w ww . j ava 2 s . co m*/ String text = sampleTextPane.getText(); if (!force) { // Don't regenerate font unless the text has new characters or has removed characters. boolean newCharFound = false; remainingSampleChars.clear(); remainingSampleChars.addAll(sampleChars); for (int i = text.length() - 1; i >= 0; i--) { Character ch = text.charAt(i); if (sampleChars.add(ch)) newCharFound = true; remainingSampleChars.remove(ch); } if (!newCharFound && remainingSampleChars.isEmpty()) return; } sampleChars.clear(); for (int i = text.length() - 1; i >= 0; i--) sampleChars.add(text.charAt(i)); int fontSize = ((Integer) fontSizeSpinner.getValue()).intValue(); int style = Font.PLAIN; if (boldCheckBox.isSelected()) { style = Font.BOLD; if (italicCheckBox.isSelected()) style |= Font.ITALIC; } else if (italicCheckBox.isSelected()) // style = Font.ITALIC; fontData = fontData.deriveFont(fontSize, style); int sampleFontSize = sampleTextPane.getFont().getSize(); if (sampleFontSize < 14) sampleFontSize = 14; sampleTextPane.setFont(fontData.getJavaFont().deriveFont((float) sampleFontSize)); Padding padding = new Padding((Integer) padTopSpinner.getValue(), (Integer) padLeftSpinner.getValue(), (Integer) padBottomSpinner.getValue(), (Integer) padRightSpinner.getValue(), (Integer) padAdvanceXSpinner.getValue()); final int width = (Integer) glyphPageWidthCombo.getSelectedItem(); final int height = (Integer) glyphPageHeightCombo.getSelectedItem(); GeneratorMethod method; if (vectorRadio.isSelected()) method = GeneratorMethod.AWT_VECTOR; else if (drawStringRadio.isSelected()) method = GeneratorMethod.AWT_DRAWSTRING; else method = GeneratorMethod.FREETYPE2; fontGenerator = new FontGenerator(fontData, method); CharSet charset = new CharSet(); charset.setManualCharacters(text); try { fontGenerator.generate(width, height, charset, padding, new Effect.Renderer[0], true); final ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 1024 * 4); buffer.order(ByteOrder.LITTLE_ENDIAN); fontGenerator.getTextureData(buffer.asIntBuffer()); TextureRegion glyphRegion = new TextureRegion(new Texture(new TextureData() { public void load() { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); } public int getWidth() { return width; } public int getHeight() { return height; } })); fontGenerator.write(new File("out"), ExportFormat.TEXT); renderer.font = new BitmapFont(Gdx.files.absolute("out"), glyphRegion, false); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.dinasgames.engine.graphics.Texture.java
public boolean create(int width, int height) { if (width == 0 && height == 0) { return false; }//from ww w.j a va 2 s . c o m Vector2i actualSize = new Vector2i(getValidSize(width), getValidSize(height)); int maxSize = getMaximumSize(); if ((actualSize.x > maxSize) || (actualSize.y > maxSize)) { System.out.println("Failed to create texture, its internal size is too high (" + actualSize.x + ", " + actualSize.y + ") maximum is (" + maxSize + ", " + maxSize + ")"); return false; } mWidth = width; mHeight = height; mActualWidth = actualSize.x; mActualHeight = actualSize.y; mPixelsFlipped = false; if (mTexture <= 0) { mTexture = GL11.glGenTextures(); } int textureEdgeClamp = GL.clampToEdge(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, mTexture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, mActualWidth, mActualHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, 0); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, (mRepeated ? GL11.GL_REPEAT : textureEdgeClamp)); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, (mRepeated ? GL11.GL_REPEAT : textureEdgeClamp)); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, (mSmooth ? GL11.GL_LINEAR : GL11.GL_NEAREST)); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, (mSmooth ? GL11.GL_LINEAR : GL11.GL_NEAREST)); mCacheId = getUniqueId(); return true; }
From source file:com.flowpowered.caustic.lwjgl.gl20.GL20Texture.java
License:MIT License
@Override public void setImageData(ByteBuffer imageData, int width, int height) { checkCreated();/*ww w . ja v a 2 s. c om*/ if (width <= 0) { throw new IllegalArgumentException("Width must be greater than zero"); } if (height <= 0) { throw new IllegalArgumentException("Height must be greater than zero"); } // Back up the old values int oldWidth = this.width; int oldHeight = this.height; // Update the texture width and height this.width = width; this.height = height; // Bind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); // Upload the texture to the GPU final boolean hasInternalFormat = internalFormat != null; if (minFilter.needsMipMaps() && imageData != null) { // Build mipmaps if using mip mapped filters GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, hasInternalFormat ? internalFormat.getGLConstant() : format.getGLConstant(), width, height, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); } else { // Else just make it a normal texture, use byte alignment GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // Check if we can only upload without reallocating if (imageData != null && width == oldWidth && height == oldHeight) { GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, width, height, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); } else { // Reallocate and upload the image GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, hasInternalFormat ? internalFormat.getGLConstant() : format.getGLConstant(), width, height, 0, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); } } // Unbind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); // Check for errors LWJGLUtil.checkForGLError(); }
From source file:com.flowpowered.caustic.lwjgl.gl30.GL30Texture.java
License:MIT License
@Override public void setImageData(ByteBuffer imageData, int width, int height) { checkCreated();//from w w w . j a va2 s . com if (width <= 0) { throw new IllegalArgumentException("Width must be greater than zero"); } if (height <= 0) { throw new IllegalArgumentException("Height must be greater than zero"); } // Back up the old values int oldWidth = this.width; int oldHeight = this.height; // Update the texture width and height this.width = width; this.height = height; // Bind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); // Use byte alignment GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // Upload the texture final boolean hasInternalFormat = internalFormat != null; // Check if we can only upload without reallocating if (imageData != null && width == oldWidth && height == oldHeight) { GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, width, height, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); } else { // Reallocate and upload the image GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, hasInternalFormat ? internalFormat.getGLConstant() : format.getGLConstant(), width, height, 0, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); } // Generate mipmaps if necessary if (minFilter.needsMipMaps() && imageData != null) { GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); } // Unbind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); // Check for errors LWJGLUtil.checkForGLError(); }
From source file:com.foudroyantfactotum.mod.fousarchive.midi.generation.MidiTexture.java
License:Open Source License
@Override public void loadTexture(IResourceManager resourceManager) throws IOException { final int xSize = getSmallTextureSize(); final int ySize = 88; byte[] res = null; try (final InputStream io = resourceManager.getResource(rl).getInputStream()) { res = getMidiTrack(io, xSize, ySize); } catch (InvalidMidiDataException e) { e.printStackTrace();/* w ww . j av a2s. c o m*/ } if (res != null) { this.deleteGlTexture(); GlStateManager.bindTexture(this.getGlTextureId()); final ByteBuffer bb = (ByteBuffer) BufferUtils.createByteBuffer(res.length).put(res).flip(); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 0); 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.glTexParameterf(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MIN_LOD, 0.0f); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, 0.0f); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0.0f); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, xSize, ySize, 0, GL11.GL_RGB, GL11.GL_BYTE, bb); } }
From source file:com.github.begla.blockmania.world.horizon.Skysphere.java
License:Apache License
private void loadStarTextures() { int internalFormat = GL11.GL_RGBA8, format = GL12.GL_BGRA; GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, _textureIds.get(0)); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL12.GL_TEXTURE_WRAP_R, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); for (int i = 0; i < 6; i++) { byte[] data = TextureManager.getInstance().getTexture("stars" + (i + 1)).getTextureData(); ByteBuffer byteBuffer = BufferUtils.createByteBuffer(data.length); byteBuffer.put(data);/*w w w. j a v a2 s . c o m*/ byteBuffer.flip(); GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, 256, 256, 0, format, GL11.GL_UNSIGNED_BYTE, byteBuffer); } }
From source file:com.github.kajdreef.mazerunnermvn.Object.GameObject.java
protected void setTextureUnit(Texture texture, int textureUnit) { // Create a new texture object in memory and bind it texId = GL11.glGenTextures();//from w ww .ja v a 2s. com 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_RGB, texture.getWidth(), texture.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, texture.getTexBuffer()); 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); }
From source file:com.golden.gamedev.engine.lwjgl.TextureLoader.java
License:Open Source License
/** * Load a texture into OpenGL from a image reference on disk. * //from w w w.j a v a2s.c o m * @param resourceName The location of the resource to load * @param target The GL target to load the texture against * @param dstPixelFormat The pixel format of the screen * @param minFilter The minimising filter * @param magFilter The magnification filter * @return The loaded texture * @throws IOException Indicates a failure to access the resource */ public Texture getTexture(BufferedImage image, int target, int dstPixelFormat, int minFilter, int magFilter) { int srcPixelFormat = 0; // create the texture ID for this texture int textureID = this.createTextureID(); Texture texture = new Texture(target, textureID); // bind this texture GL11.glBindTexture(target, textureID); texture.setWidth(image.getWidth()); texture.setHeight(image.getHeight()); srcPixelFormat = (image.getColorModel().hasAlpha()) ? GL11.GL_RGBA : GL11.GL_RGB; // convert that image into a byte buffer of texture data ByteBuffer textureBuffer = this.convertImageData(image, texture); if (target == GL11.GL_TEXTURE_2D) { GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter); } // produce a texture from the byte buffer GL11.glTexImage2D(target, 0, dstPixelFormat, this.get2Fold(image.getWidth()), this.get2Fold(image.getHeight()), 0, srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer); return texture; }