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:rainwarrior.mt100.client.PstFont.java
License:Open Source License
public void bindFontTexture() { GL11.glLoadIdentity();/*from w ww. j a va2 s .c o m*/ GL11.glScalef(1F / textureWidth, 1F / textureHeight, 1F); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.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_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); }
From source file:resource.ResourceManager.java
License:Open Source License
public void bindTexture(Texture tex) { // Put Image In Memory ByteBuffer scratch = ByteBuffer.allocateDirect(4 * tex.getSize() * tex.getSize()); byte data[] = (byte[]) tex.getImage().getRaster().getDataElements(0, 0, tex.getSize(), tex.getSize(), null); scratch.clear();/*from ww w .j a v a2s. c om*/ scratch.put(data); scratch.rewind(); IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); GL11.glGenTextures(buf); // Create a texure ID tex.setID(buf.get(0)); GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getID()); 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); // Generate The Texture GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, GL11.GL_RGBA, tex.getSize(), tex.getSize(), GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, scratch); }
From source file:rtype.JNLPTextureLoader.java
License:Open Source License
private Texture loadTexture(String path, int xOffSet, int yOffSet, int textWidth, int textHeight) { BufferedImage buffImage = null; try {//from w w w.ja v a2 s . c om if (imageCache.get(path) != null) buffImage = (BufferedImage) imageCache.get(path); else { System.out.println("Loading image:" + path); buffImage = ImageIO.read(new FileImageInputStream(new File(path))); imageCache.put(path, buffImage); } } catch (IOException e) { e.printStackTrace(); } int bytesPerPixel = buffImage.getColorModel().getPixelSize() / 8; ByteBuffer scratch = ByteBuffer.allocateDirect(textWidth * textHeight * bytesPerPixel) .order(ByteOrder.nativeOrder()); DataBufferByte data = ((DataBufferByte) buffImage.getRaster().getDataBuffer()); for (int i = 0; i < textHeight; i++) scratch.put(data.getData(), (xOffSet + (yOffSet + i) * buffImage.getWidth()) * bytesPerPixel, textWidth * bytesPerPixel); scratch.rewind(); // Create A IntBuffer For Image Address In Memory IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); GL11.glGenTextures(buf); // Create Texture In OpenGL // Create Nearest Filtered Texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(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); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, textWidth, textHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, scratch); Texture newTexture = new Texture(); newTexture.textureId = buf.get(0); // Return Image Addresses In Memory newTexture.textureHeight = textHeight; newTexture.textureWidth = textWidth; return newTexture; }
From source file:rtype.Prototyp.java
License:Open Source License
private void createOffScreenBuffer() { int bytesPerPixel = 3; ByteBuffer scratch = ByteBuffer.allocateDirect(1024 * 1024 * bytesPerPixel); IntBuffer buf = ByteBuffer.allocateDirect(12).order(ByteOrder.nativeOrder()).asIntBuffer(); GL11.glGenTextures(buf); // Create Texture In OpenGL GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0)); SCREEN_TEXTURE_ID = buf.get(0);/*from w w w. j a va2 s. c o m*/ int glType = GL11.GL_RGB; 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.glTexImage2D(GL11.GL_TEXTURE_2D, 0, glType, 1024, 1024, 0, glType, GL11.GL_UNSIGNED_BYTE, scratch); }
From source file:rtype.WorkAroundTextureLoader.java
License:Open Source License
private Texture loadTexture(String path, int xOffSet, int yOffSet, int textWidth, int textHeight) { BufferedImage buffImage = null; try {//from w ww . j ava 2 s .c om if (imageCache.get(path) != null) buffImage = (BufferedImage) imageCache.get(path); else { System.out.println("Loading image:" + path); buffImage = ImageIO.read(this.getClass().getResource(path)); //February 2nd, 2011: Fix for JAVA 1.6 thanks to sonicWonder for the fix byte[] data = ((DataBufferByte) buffImage.getRaster().getDataBuffer()).getData(); switch (buffImage.getType()) { case BufferedImage.TYPE_4BYTE_ABGR: convertFromARGBToBGRA(data); break; case BufferedImage.TYPE_3BYTE_BGR: convertFromBGRToRGB(data); break; default: System.out.println("Unknown type:" + buffImage.getType()); break; } //End February 2nd, 2011: Fix for JAVA 1.6 thanks to sonicWonder for the fix imageCache.put(path, buffImage); } } catch (IOException e) { e.printStackTrace(); } int bytesPerPixel = buffImage.getColorModel().getPixelSize() / 8; ByteBuffer scratch = ByteBuffer.allocateDirect(textWidth * textHeight * bytesPerPixel) .order(ByteOrder.nativeOrder()); DataBufferByte dataBufferByte = ((DataBufferByte) buffImage.getRaster().getDataBuffer()); for (int i = 0; i < textHeight; i++) scratch.put(dataBufferByte.getData(), (xOffSet + (yOffSet + i) * buffImage.getWidth()) * bytesPerPixel, textWidth * bytesPerPixel); scratch.rewind(); // Create A IntBuffer For Image Address In Memory IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); GL11.glGenTextures(buf); // Create Texture In OpenGL // Create Nearest Filtered Texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(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); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, textWidth, textHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, scratch); Texture newTexture = new Texture(); newTexture.textureId = buf.get(0); // Return Image Addresses In Memory newTexture.textureHeight = textHeight; newTexture.textureWidth = textWidth; return newTexture; }
From source file:se.angergard.engine.graphics.FrameBuffer.java
License:Apache License
public FrameBuffer(int width, int height, boolean hasDepth, boolean hasStencil) { this.width = width; this.height = height; if ((width + height) % 4 != 0.0) { new Exception("Width + Height must be divisible by 4"); }/*from w ww .ja v a 2s .c o m*/ frameBufferID = GL30.glGenFramebuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID); if (hasDepth && hasStencil) { depthAndStencilBufferID = GL30.glGenRenderbuffers(); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthAndStencilBufferID); GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_DEPTH24_STENCIL8, width, height); GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_STENCIL_ATTACHMENT, GL30.GL_RENDERBUFFER, depthAndStencilBufferID); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, 0); } else if (hasDepth) { depthBufferID = GL30.glGenRenderbuffers(); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthBufferID); GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_DEPTH_COMPONENT32F, width, height); GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, depthBufferID); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, 0); } else if (hasStencil) { stencilBufferID = GL30.glGenRenderbuffers(); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, stencilBufferID); GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_STENCIL_INDEX16, width, height); GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_STENCIL_ATTACHMENT, GL30.GL_RENDERBUFFER, stencilBufferID); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, 0); } colorTexture = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, colorTexture); 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.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, colorTexture, 0); int result = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); if (result != GL30.GL_FRAMEBUFFER_COMPLETE) { if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) { new Exception("Frame Buffer Error: incomplete attachment").printStackTrace(); } if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER) { new Exception("Frame Buffer Error: incomplete draw buffer").printStackTrace(); } if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) { new Exception("Frame Buffer Error: missing attachment").printStackTrace(); } if (result == GL30.GL_FRAMEBUFFER_UNSUPPORTED) { new Exception("Frame Buffer Error: unsupported combination of formats").printStackTrace(); } if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE) { new Exception("Frame Buffer Error: incomplete multisample").printStackTrace(); } if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER) { new Exception("Frame Buffer Error: incomplete read buffer").printStackTrace(); } new Exception("frame buffer couldn't be constructed: unknown error " + result).printStackTrace(); } RenderUtil.unbindFrameBuffer(); RenderUtil.unbindTexture(); frameBufferShader = new ShaderProgram().createDefault2DShader(); }
From source file:se.angergard.engine.graphics.Texture.java
License:Apache License
private void loadTexture(ByteBuffer buffer, int textureID, int width, int height) { 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); // Not all computer will support this, fix //TODO GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); 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.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:shadowmage.meim.client.gui.GuiTextureElement.java
License:Open Source License
private void updateTextureContents(BufferedImage image) { bindTexture();//from ww w.j a v a 2 s. co m if (image != null) { int size = image.getWidth() * image.getHeight(); if (bufferSize < size) { bufferSize = size; dataBuffer = BufferUtils.createIntBuffer(bufferSize); inBuff = new int[bufferSize]; outBuff = new int[bufferSize]; } dataBuffer.clear(); fillImageArray(image, dataBuffer); 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.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); //GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); //GL11.GL_NEAREST); uploadTextureRGBAInts(dataBuffer, image.getWidth(), image.getHeight()); } resetBoundTexture(); }
From source file:shadowmage.meim.client.texture.TextureManager.java
License:Open Source License
public static void allocateTexture() { if (texNum >= 0) { GL11.glDeleteTextures(texNum);/*www . ja v a2 s . c o m*/ } texNum = GL11.glGenTextures(); bindTexture(); for (int i = 0; i < 256 * 256; i++) { dataBuffer.put(i, 0xfffffff); } dataBuffer.rewind(); 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_NEAREST); //GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); //GL11.GL_NEAREST); uploadTextureRGBAInts(dataBuffer, 256, 256);//upload empty data to texture so that it is 'valid'? resetBoundTexture(); }
From source file:shadowmage.meim.client.texture.TextureManager.java
License:Open Source License
public static void updateTextureContents(BufferedImage image) { bindTexture();//from w ww . ja v a2s. c o m if (image != null) { int size = image.getWidth() * image.getHeight(); if (bufferSize < size) { bufferSize = size; dataBuffer = BufferUtils.createIntBuffer(bufferSize); inBuff = new int[bufferSize]; outBuff = new int[bufferSize]; } dataBuffer.clear(); fillImageArray(image, dataBuffer); 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.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); //GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); //GL11.GL_NEAREST); uploadTextureRGBAInts(dataBuffer, image.getWidth(), image.getHeight()); } resetBoundTexture(); }