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.xrbpowered.gl.res.textures.BufferTexture.java
License:Open Source License
public void update() { if (this.imgBuffer == null) createBuffers();/*from ww w . j av a 2 s .c o m*/ if (updateBuffer((Graphics2D) imgBuffer.getGraphics(), width, height)) { pixels = imgBuffer.getRGB(0, 0, width, height, pixels, 0, width); intBuffer.put(pixels); intBuffer.flip(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, getId()); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer); // GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); // TODO needless mipmaps? } if (!staticBuffers) destroyBuffers(); }
From source file:com.xrbpowered.gl.res.textures.Texture.java
License:Open Source License
protected void put(int targetType, int w, int h, IntBuffer buf) { GL11.glTexImage2D(targetType, 0, GL11.GL_RGBA, w, h, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, buf);/*from ww w. j a v a 2s . c o m*/ }
From source file:cuchaz.jfxgl.prism.JFXGLContext.java
License:Open Source License
@Override public int createTexture(int width, int height) { int texId = GL11.glGenTextures(); if (texId == 0) { return 0; }/*from w ww .j av a 2 s . c o m*/ GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); // make the texture clearGLErrors(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, 0); // if something bad happened, delete the texture if (hasGLError()) { GL11.glDeleteTextures(texId); return 0; } 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); return texId; }
From source file:cuchaz.jfxgl.prism.JFXGLContext.java
License:Open Source License
@Override public boolean texImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, Buffer pixels, boolean useMipmap) { // NOTE: null pixels are allowed if (pixels != null && !(pixels instanceof ByteBuffer)) { throw new Error( "buffer should be a " + ByteBuffer.class.getName() + ", not a " + pixels.getClass().getName()); }/*from w w w .j ava2 s. co m*/ ByteBuffer buf = (ByteBuffer) pixels; if (useMipmap) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE); } // if buf is not direct, copy it to a direct buffer if (buf != null && !buf.isDirect()) { imageBuf = updateBuffer(imageBuf, buf); buf = imageBuf; } clearGLErrors(); GL11.glTexImage2D(translatePrismToGL(target), level, translatePrismToGL(internalFormat), width, height, border, translatePrismToGL(format), translatePrismToGL(type), buf); int glerror = getGLError(); boolean hasError = glerror != GL11.GL_NO_ERROR; if (hasError) { System.err.println(String .format("WARNING: couldn't upload texture. glTexImage2D failed with code: 0x%x", glerror)); } return !hasError; }
From source file:dataAccess.lwjgl.VAO_Loader.java
public static int loadCubeMap(String... textureFiles) { int texID = GL11.glGenTextures(); GL13.glActiveTexture(texID);//from w w w . j a v a 2 s . co m GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texID); for (int i = 0; i < textureFiles.length; i++) { TextureData data = dataAccess.fileLoaders.TextureLoader .decodeTextureFile("res/textures/skybox/" + textureFiles[i] + ".png"); GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL11.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data.getBuffer()); } GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); textureMap.put("cubeMap", texID); return texID; }
From source file:de.ikosa.mars.viewer.glviewer.engine.GLTextureBuilder.java
License:Open Source License
public static GLTexture createEmptyTexture(String name, int width, int height, byte r, byte g, byte b, byte a) { try {/* ww w . ja v a 2 s . c om*/ int textureId = GL11.glGenTextures(); ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 4); for (int i = 0; i < width * height; i++) { buffer.put(r); buffer.put(g); buffer.put(b); buffer.put(a); } buffer.flip(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); return new GLTexture(name, textureId); } catch (Exception e) { ML.f(e); } return null; }
From source file:de.ikosa.mars.viewer.glviewer.engine.GLTextureBuilder.java
License:Open Source License
public static GLTexture createEmptyTexture(String name, int width, int height, float initial) { try {// w w w. java2 s . c om int textureId = GL11.glGenTextures(); ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 4); for (int i = 0; i < width * height * 4; i++) { buffer.put((byte) 0); } buffer.flip(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_DEPTH_COMPONENT, width, height, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, buffer); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); return new GLTexture(name, textureId); } catch (Exception e) { ML.f(e); } return null; }
From source file:de.ikosa.mars.viewer.glviewer.engine.GLTextureBuilder.java
License:Open Source License
private int createRGBTexture(BufferedImage image, byte[] x) { ByteBuffer buffer;/*w ww. j a v a2 s . c o m*/ buffer = ByteBuffer.allocateDirect(x.length); for (int i = 0; i < x.length; i++) { buffer.put(x[i]); } buffer.flip(); int textureId = GL11.glGenTextures(); GLRenderer2Stage.errorCheck("generating texture id"); GL13.glActiveTexture(GL13.GL_TEXTURE0); GLRenderer2Stage.errorCheck("activating texture image unit"); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); GLRenderer2Stage.errorCheck("binding 2d texture"); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GLRenderer2Stage.errorCheck("setting unpack aligment"); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); GLRenderer2Stage.errorCheck("storing 2d texture data"); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); GLRenderer2Stage.errorCheck("generating 2d texture array mipmaps"); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); GLRenderer2Stage.errorCheck("unbinding 2d texture array"); return textureId; }
From source file:de.ikosa.mars.viewer.glviewer.engine.GLTextureBuilder.java
License:Open Source License
private int createGrayscaleTexture(BufferedImage image, byte[] x) { ShortBuffer buffer;/*from w w w . j av a 2 s .c om*/ buffer = BufferUtils.createShortBuffer(image.getHeight() * image.getWidth()); for (int i = 0; i < x.length; i += 2) { short val = (short) (fromByte(x[i]) + (fromByte(x[i + 1]) << 8)); buffer.put(val); } buffer.flip(); int textureId = GL11.glGenTextures(); GLRenderer2Stage.errorCheck("generating texture id"); GL13.glActiveTexture(GL13.GL_TEXTURE0); GLRenderer2Stage.errorCheck("activating texture image unit"); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); GLRenderer2Stage.errorCheck("binding 2d texture"); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 2); GLRenderer2Stage.errorCheck("setting unpack aligment"); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL30.GL_R16, image.getWidth(), image.getHeight(), 0, GL11.GL_RED, GL11.GL_UNSIGNED_SHORT, buffer); GLRenderer2Stage.errorCheck("storing 2d texture data"); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); GLRenderer2Stage.errorCheck("generating 2d texture array mipmaps"); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); GLRenderer2Stage.errorCheck("unbinding 2d texture array"); return textureId; }
From source file:edu.csun.ecs.cs.multitouchj.ui.graphic.image.TextureHandler.java
License:Apache License
public Texture generateTexture(Image image) { Integer textureId = generateTextureId(); ByteBuffer imageData = prepareImage(image); GL11.glEnable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT); GL11.glBindTexture(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, textureId.intValue()); GL11.glTexParameteri(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);/* w w w . j ava2 s .c o m*/ GL11.glTexParameteri(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); // GL11.glTexParameteri(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, // GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); // GL11.glTexParameteri(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, // GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); GL11.glTexImage2D(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, 0, (image.hasAlpha()) ? GL11.GL_RGBA8 : GL11.GL_RGB8, image.getWidth(), image.getHeight(), 0, (image.hasAlpha()) ? GL11.GL_RGBA : GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, imageData); System.out.println("Texture generated: " + textureId); return new Texture(textureId, image); }