Java Code Examples for org.lwjgl.opengl.GL11#glTexImage2D()
The following examples show how to use
org.lwjgl.opengl.GL11#glTexImage2D() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Rendertarget.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Creates a Rendertarget with a Texture that it renders the color buffer in * and a renderbuffer that it renders the depth to. * @param width the width * @param height the height * @return the newly created Rendertarget instance */ public static Rendertarget createRTTFramebuffer(int width, int height) { int old_framebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT); int old_texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); Rendertarget buffer = new Rendertarget(width,height); buffer.bind(); int fboTexture = buffer.textureID; GL11.glBindTexture(GL11.GL_TEXTURE_2D, fboTexture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_INT, (ByteBuffer) null); 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); EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID); EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL11.GL_DEPTH_COMPONENT, width, height); EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fboTexture, 0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, old_texture); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, old_framebuffer); return buffer; }
Example 2
Source File: FrameBufferContainer.java From LookingGlass with GNU General Public License v3.0 | 6 votes |
private void allocateFrameBuffer() { if (this.framebuffer != 0) return; this.framebuffer = EXTFramebufferObject.glGenFramebuffersEXT(); //Release via: EXTFramebufferObject.glDeleteFramebuffersEXT(framebuffer); this.depthBuffer = EXTFramebufferObject.glGenRenderbuffersEXT(); //Release via: EXTFramebufferObject.glDeleteRenderbuffersEXT(depthBuffer); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, this.framebuffer); EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthBuffer); if (MinecraftForgeClient.getStencilBits() == 0) EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, width, height); else EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, org.lwjgl.opengl.EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT, width, height); EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthBuffer); if (MinecraftForgeClient.getStencilBits() != 0) EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_STENCIL_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthBuffer); this.texture = GL11.glGenTextures(); //Release via: GL11.glDeleteTextures(colorTexture); GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.texture); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_INT, (java.nio.ByteBuffer) null); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, this.texture, 0); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0); }
Example 3
Source File: ClientDynamicTexture.java From AdvancedRocketry with MIT License | 6 votes |
private void init() { //create array, every single pixel ByteBuffer buffer = BufferUtils.createByteBuffer(image.getHeight() * image.getWidth() * BYTES_PER_PIXEL); for(int i = 0; i < image.getHeight() * image.getWidth(); i++) { buffer.putInt(0x00000000); } buffer.flip(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureId()); //Just clamp to edge 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); //Scale linearly 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.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); }
Example 4
Source File: Rendertarget.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Creates a Rendertarget with a Texture that it renders the color buffer in * and a renderbuffer that it renders the depth to. * @param width the width * @param height the height * @return the newly created Rendertarget instance */ public static Rendertarget createRTTFramebuffer(int width, int height) { int old_framebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT); int old_texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); Rendertarget buffer = new Rendertarget(width,height); buffer.bind(); int fboTexture = buffer.textureID; GL11.glBindTexture(GL11.GL_TEXTURE_2D, fboTexture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_INT, (ByteBuffer) null); 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); EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID); EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL11.GL_DEPTH_COMPONENT, width, height); EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fboTexture, 0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, old_texture); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, old_framebuffer); return buffer; }
Example 5
Source File: LWJGL15DrawContext.java From settlers-remake with MIT License | 6 votes |
@Override public TextureHandle generateTexture(int width, int height, ShortBuffer data, String name) { int texture = GL11.glGenTextures(); if (texture == 0) { return null; } //fix strange alpha test problem (minimap and landscape are unaffected) ShortBuffer bfr = BufferUtils.createShortBuffer(data.capacity()); int cap = data.capacity(); for(int i = 0;i != cap;i++) bfr.put(i, data.get(i)); TextureHandle textureHandle = new TextureHandle(this, texture); bindTexture(textureHandle); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL12.GL_UNSIGNED_SHORT_4_4_4_4, bfr); setTextureParameters(); setObjectLabel(GL11.GL_TEXTURE, texture, name + "-tex"); return textureHandle; }
Example 6
Source File: GenericShader.java From LWJGUI with MIT License | 5 votes |
public GenericShader(URL vertexShader, URL fragmentShader) { // make the shader vertexId = compileShader(vertexShader, true); fragmentId = compileShader(fragmentShader, false); posLoc = 0; texCoordLoc = 1; id = createProgram( vertexId, new int[] { fragmentId }, new String[] { "inPos", "inTexCoord" }, new int[] { posLoc, texCoordLoc } ); projMatLoc = GL20.glGetUniformLocation(id, "projectionMatrix"); viewMatLoc = GL20.glGetUniformLocation(id, "viewMatrix"); worldMatLoc = GL20.glGetUniformLocation(id, "worldMatrix"); // Generic white texture texId = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); int wid = 1; int hei = 1; ByteBuffer data = BufferUtils.createByteBuffer(wid*hei*4); while(data.hasRemaining()) { data.put((byte) (255 & 0xff)); } data.flip(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, wid, hei, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data); 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); }
Example 7
Source File: TextureAttachment.java From LowPolyWater with The Unlicense | 5 votes |
private void indicateStorageType(int width, int height){ if(isDepthAttachment()){ GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, format, width, height, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null); }else{ GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, format, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); } }
Example 8
Source File: TextureUtils.java From OpenGL-Animation with The Unlicense | 5 votes |
protected static int loadTextureToOpenGL(TextureData data, TextureBuilder builder) { int texID = GL11.glGenTextures(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, data.getBuffer()); if (builder.isMipmap()) { GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); 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_MIPMAP_LINEAR); if (builder.isAnisotropic() && GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) { GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, 4.0f); } } else if (builder.isNearest()) { 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_NEAREST); } else { 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); } if (builder.isClampEdges()) { 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 { 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); } GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); return texID; }
Example 9
Source File: Texture.java From mapwriter with MIT License | 5 votes |
public Texture(int w, int h, int fillColour, int minFilter, int maxFilter, int textureWrap) { this.id = GL11.glGenTextures(); this.w = w; this.h = h; this.pixelBuf = MwUtil.allocateDirectIntBuffer(w * h); this.fillRect(0, 0, w, h, fillColour); this.pixelBuf.position(0); this.bind(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, w, h, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, this.pixelBuf); this.setTexParameters(minFilter, maxFilter, textureWrap); }
Example 10
Source File: ClientDynamicTexture.java From AdvancedRocketry with MIT License | 5 votes |
/** * * @param x x location of the pixel * @param y y location of the pixel * @param color color in RGBA8 */ public void setPixel(int x, int y, int color) { ByteBuffer buffer = BufferUtils.createByteBuffer(image.getHeight() * image.getWidth() * BYTES_PER_PIXEL);; GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureId()); GL11.glGetTexImage(GL11.GL_TEXTURE_2D,0 , GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); buffer.putInt(x + (y * image.getHeight()), color); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); }
Example 11
Source File: Test.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
private final static int createTexture(int width, int height, IntBuffer pixel_data) { IntBuffer handle_buffer = BufferUtils.createIntBuffer(1); GL11.glGenTextures(handle_buffer); int tex_handle = handle_buffer.get(0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_handle); 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.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL12.GL_UNSIGNED_INT_8_8_8_8, pixel_data); return tex_handle; }
Example 12
Source File: Texture.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
private final void uploadDXTTexture(DXTImage dxt_image, TextureFile texture_file) { int detail_shift = getDetailShift(dxt_image.getNumMipMaps()); int max_index = getMaxMipmapIndex(dxt_image.getNumMipMaps(), texture_file.getMaxMipmapLevel(), detail_shift); int total_size = 0; for (int i = 0; i < max_index; i++) { int mipmap_level = i + detail_shift; dxt_image.position(mipmap_level); if (GLContext.getCapabilities().GL_EXT_texture_compression_s3tc) { total_size += dxt_image.getMipMap().remaining(); GLState.glCompressedTexImage2D(GL11.GL_TEXTURE_2D, i, dxt_image.getInternalFormat(), dxt_image.getWidth(mipmap_level), dxt_image.getHeight(mipmap_level), 0, dxt_image.getMipMap()); } else { byte[] blocks = new byte[dxt_image.getMipMap().remaining()]; dxt_image.getMipMap().get(blocks); Squish.CompressionType type = dxt_image.getInternalFormat() == EXTTextureCompressionS3TC.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ? Squish.CompressionType.DXT5 : Squish.CompressionType.DXT1; byte[] rgba = Squish.decompressImage(null, dxt_image.getWidth(mipmap_level), dxt_image.getHeight(mipmap_level), blocks, type); ByteBuffer buf = BufferUtils.createByteBuffer(rgba.length); buf.put(rgba); buf.flip(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, i, texture_file.getInternalFormat(), dxt_image.getWidth(mipmap_level), dxt_image.getHeight(mipmap_level), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf); total_size += determineMipMapSize(i, texture_file.getInternalFormat(), dxt_image.getWidth(mipmap_level), dxt_image.getHeight(mipmap_level)); } } setSize(total_size); /*for (int i = 0; i < max_index; i++) { int mipmap_level = i + detail_shift; GLUtils.saveTexture(i, new java.io.File(texture_file.getURL().getFile() + dxt_image.getWidth(mipmap_level) + "x" + dxt_image.getHeight(mipmap_level)).getName()); }*/ }
Example 13
Source File: Texture.java From mapwriter with MIT License | 4 votes |
public synchronized void updateTexture() { this.bind(); this.pixelBuf.position(0); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, this.w, this.h, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, this.pixelBuf); }
Example 14
Source File: ImmediateModeOGLRenderer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void glTexImage2D(int target, int i, int dstPixelFormat, int width, int height, int j, int srcPixelFormat, int glUnsignedByte, ByteBuffer textureBuffer) { GL11.glTexImage2D(target, i, dstPixelFormat, width, height, j, srcPixelFormat,glUnsignedByte,textureBuffer); }
Example 15
Source File: LwjglTextureUtils.java From tectonicus with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static int createTexture(BufferedImage[] mips, TextureFilter filterMode) { IntBuffer buff = BufferUtils.createIntBuffer(16); buff.limit(1); GL11.glGenTextures(buff); int textureId = buff.get(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); if (filterMode == TextureFilter.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_NEAREST_MIPMAP_LINEAR); } else { 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_MIPMAP_LINEAR); } 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); for (int mip=0; mip<mips.length; mip++) { BufferedImage imageData = mips[mip]; imageData = convertToGlFormat(imageData); ByteBuffer scratch = ByteBuffer.allocateDirect(4*imageData.getWidth()*imageData.getHeight()); Raster raster = imageData.getRaster(); byte data[] = (byte[])raster.getDataElements(0, 0, imageData.getWidth(), imageData.getHeight(), null); scratch.clear(); scratch.put(data); scratch.rewind(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, mip, GL11.GL_RGBA, // Mip level & Internal format imageData.getWidth(), imageData.getHeight(), 0, // width, height, border GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // pixel data format scratch); // pixel data // GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, // 0, 0, // imageData.getWidth(), imageData.getHeight(), // GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // format, type // scratch); } return textureId; }
Example 16
Source File: LwjglTextureUtils.java From tectonicus with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static int createTexture(BufferedImage imageData, TextureFilter filterMode) { imageData = convertToGlFormat(imageData); IntBuffer buff = BufferUtils.createIntBuffer(16); buff.limit(1); GL11.glGenTextures(buff); int textureId = buff.get(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); if (filterMode == TextureFilter.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_NEAREST); } else { 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.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); ByteBuffer scratch = ByteBuffer.allocateDirect(4*imageData.getWidth()*imageData.getHeight()); Raster raster = imageData.getRaster(); byte data[] = (byte[])raster.getDataElements(0, 0, imageData.getWidth(), imageData.getHeight(), null); scratch.clear(); scratch.put(data); scratch.rewind(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, // Mip level & Internal format imageData.getWidth(), imageData.getHeight(), 0, // width, height, border GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // pixel data format scratch); // pixel data GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, imageData.getWidth(), imageData.getHeight(), GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // format, type scratch); return textureId; }
Example 17
Source File: OpenGL3_TheQuadTextured.java From ldparteditor with MIT License | 4 votes |
private int loadPNGTexture(String filename, int textureUnit) { ByteBuffer buf = null; int tWidth = 0; int tHeight = 0; try { // Open the PNG file as an InputStream InputStream in = new FileInputStream(filename); // Link the PNG decoder to this stream PNGDecoder decoder = new PNGDecoder(in); // Get the width and height of the texture tWidth = decoder.getWidth(); tHeight = decoder.getHeight(); // Decode the PNG file in a ByteBuffer buf = ByteBuffer.allocateDirect( 4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); buf.flip(); in.close(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } // 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_RGB, 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); this.exitOnGLError("loadPNGTexture"); return texId; }
Example 18
Source File: OffscreenBuffer.java From LWJGUI with MIT License | 4 votes |
/** * Resize the buffer to desired width/height * @param width * @param height * @return */ public boolean resize(int width, int height) { if (this.width == width && this.height == height) { return false; } this.width = width; this.height = height; // resize the texture if (texId != 0) { GL11.glDeleteTextures(texId); GL30.glDeleteFramebuffers(fboId); GL30.glDeleteRenderbuffers(renderId); texId = 0; fboId = 0; renderId = 0; } // Create texture if ( texId == 0 ) texId = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, 0); // Set default filtering 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.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); // update the framebuf if (fboId == 0) fboId = GL30.glGenFramebuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fboId); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, texId, 0); // The depth buffer if ( renderId == 0 ) renderId = GL30.glGenRenderbuffers(); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, renderId); GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, width, height); GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, renderId); // remove the old quad quadDirty = true; GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); return true; }