List of usage examples for org.lwjgl.opengl GL11 glGenTextures
@NativeType("void") public static int glGenTextures()
From source file:net.smert.frameworkgl.opengl.helpers.TextureHelper.java
License:Apache License
public int create() { return GL11.glGenTextures(); }
From source file:okkapel.kkplglutil.util.TextureLoader.java
License:Open Source License
public static Texture loadTexture(File imgFile, boolean pixelated) // Needs rewriting { String fullFilePath = null;/*from w w w .j av a 2 s .com*/ try { fullFilePath = imgFile.getAbsolutePath(); // The image BufferedImage image = ImageIO.read(imgFile); // The image pixel data int[] pixels = new int[image.getWidth() * image.getHeight() * 4]; // Write the pixel data into the array image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth()); // Create a byte buffer for pixel data ByteBuffer pixelBuffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4); // Put pixel data into the buffer for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { // Get the pixel from the array int pixel = pixels[y * image.getWidth() + x]; // Red pixelBuffer.put((byte) ((pixel >> 16) & 255)); // Green pixelBuffer.put((byte) ((pixel >> 8) & 255)); // Blue pixelBuffer.put((byte) ((pixel) & 255)); // Alpha pixelBuffer.put((byte) ((pixel >> 24) & 255)); } } pixelBuffer.flip(); int id = GL11.glGenTextures(); Texture ret = new Texture(id, image.getWidth(), image.getHeight()); GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); // Engine.out.debug(id); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixelBuffer); if (pixelated) { 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.glBindTexture(GL11.GL_TEXTURE_2D, 0); return ret; } catch (IOException e) { e.printStackTrace(); System.err.println("Failed to load texture from file: " + fullFilePath); } return null; // TODO: return missing texture }
From source file:opengl.test.object.CaroTable.java
@Override protected void initVertex() { GL30.glBindVertexArray(vao);//bind vao // position color texCoord float[] data = new float[] { -0.5f, -0.5f, 0f, 1f, 1f, 1f, 0f, 0f, 0.5f, -0.5f, 0f, 1f, 1f, 1f, 1f, 0f, -0.5f, 0.5f, 0f, 1f, 1f, 1f, 0f, 1f, 0.5f, 0.5f, 0f, 1f, 1f, 1f, 1f, 1f }; dataBuffer = BufferUtils.createFloatBuffer(data.length); dataBuffer.put(data);/*from w w w. ja v a 2 s .c o m*/ dataBuffer.flip(); Logger.getGlobal().log(Level.SEVERE, "FloatBuffer capacity : " + dataBuffer.capacity()); this.vbo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, dataBuffer, GL15.GL_STATIC_DRAW); this.VertexAttribPointer(); int[] indices = { 0, 1, 2, 2, 1, 3 }; IntBuffer indicesBuffer = BufferUtils.createIntBuffer(indices.length); indicesBuffer.put(indices); indicesBuffer.flip(); this.ebo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_DYNAMIC_DRAW); IntBuffer w = BufferUtils.createIntBuffer(1); IntBuffer h = BufferUtils.createIntBuffer(1); IntBuffer comp = BufferUtils.createIntBuffer(1); STBImage.stbi_set_flip_vertically_on_load(1); ByteBuffer image = STBImage.stbi_load("resource/3x3grid.png", w, h, comp, 0); int weight = w.get(0); int height = h.get(0); int compe = comp.get(0); Logger.getGlobal().log(Level.FINEST, "STBImage load status : " + weight + " " + height + " " + compe + " " + image); textureID = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); 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_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, weight, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, image); GL30.glBindVertexArray(0);//unbind vao }
From source file:opengl.test.object.cube.wall.java
/** * Must be override/*from w w w. j av a 2 s . co m*/ */ @Override protected void initVertex() { GL30.glBindVertexArray(vao);//bind IntBuffer w = BufferUtils.createIntBuffer(1); IntBuffer h = BufferUtils.createIntBuffer(1); IntBuffer comp = BufferUtils.createIntBuffer(1); STBImage.stbi_set_flip_vertically_on_load(1); ByteBuffer image = STBImage.stbi_load(this.path, w, h, comp, 0); int weight = w.get(0); int height = h.get(0); int compe = comp.get(0); //System.out.println(weight+":"+height+":"+this.path); float[] data = new float[] { -x, -y, 0f, 1f, 1f, 1f, 0f, 0f, x, -y, 0f, 1f, 1f, 1f, (2 * x) * (this.repeatCount), 0f, -x, y, 0f, 1f, 1f, 1f, 0f, (2 * y) * (this.repeatCount), x, y, 0f, 1f, 1f, 1f, (2 * x) * (this.repeatCount), (2 * y) * (this.repeatCount), }; dataBuffer = BufferUtils.createFloatBuffer(data.length); dataBuffer.put(data); dataBuffer.flip(); Logger.getGlobal().log(Level.SEVERE, "FloatBuffer capacity : " + dataBuffer.capacity()); this.vbo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, dataBuffer, GL15.GL_STATIC_DRAW); this.VertexAttribPointer(); int[] indices = { 0, 1, 2, 2, 1, 3, }; IntBuffer indicesBuffer = BufferUtils.createIntBuffer(indices.length); indicesBuffer.put(indices); indicesBuffer.flip(); this.ebo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_DYNAMIC_DRAW); textureID = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); 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); GL11.glTexParameteri(textureID, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(textureID, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, weight, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, image); GL30.glBindVertexArray(0);//unbind }
From source file:opengl.test.object.endgame.endgame.java
@Override protected void initVertex() { GL30.glBindVertexArray(vao);//bind vao Object[] dataInput = objLoad.Wavefront( endgame.class.getClassLoader().getResourceAsStream("opengl/test/object/endgame/endgame.obj"), 1.0f, 1.0f, 1.0f);/*from w w w.ja va 2 s . c o m*/ super.dataBuffer = (FloatBuffer) dataInput[0]; this.size = (int) dataInput[1]; this.vbo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, super.dataBuffer, GL15.GL_STATIC_DRAW); this.VertexAttribPointer(); IntBuffer w = BufferUtils.createIntBuffer(1); IntBuffer h = BufferUtils.createIntBuffer(1); IntBuffer comp = BufferUtils.createIntBuffer(1); STBImage.stbi_set_flip_vertically_on_load(1); ByteBuffer image = STBImage.stbi_load("resource/win.png", w, h, comp, 0); textureIDWIN = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDWIN); 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_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, w.get(0), h.get(0), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, image); image = STBImage.stbi_load("resource/lose.png", w, h, comp, 0); textureIDLOSE = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDLOSE); 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_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, w.get(0), h.get(0), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, image); image = STBImage.stbi_load("resource/draw.png", w, h, comp, 0); textureIDDRAW = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDDRAW); 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_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, w.get(0), h.get(0), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, image); GL30.glBindVertexArray(0);//unbind vao }
From source file:opengl.test.object.image.java
@Override protected void initVertex() { GL30.glBindVertexArray(vao);//bind vao // position color texCoord float[] data = new float[] { -x, -y, z, 1f, 1f, 1f, 0f, 0f, x, -y, z, 1f, 1f, 1f, 1f, 0f, -x, y, z, 1f, 1f, 1f, 0f, 1f, x, y, z, 1f, 1f, 1f, 1f, 1f }; dataBuffer = BufferUtils.createFloatBuffer(data.length); dataBuffer.put(data);//from www . ja v a 2s .co m dataBuffer.flip(); Logger.getGlobal().log(Level.SEVERE, "FloatBuffer capacity : " + dataBuffer.capacity()); this.vbo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, dataBuffer, GL15.GL_STATIC_DRAW); this.VertexAttribPointer(); int[] indices = { 0, 1, 2, 2, 1, 3 }; IntBuffer indicesBuffer = BufferUtils.createIntBuffer(indices.length); indicesBuffer.put(indices); indicesBuffer.flip(); this.ebo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_DYNAMIC_DRAW); IntBuffer w = BufferUtils.createIntBuffer(1); IntBuffer h = BufferUtils.createIntBuffer(1); IntBuffer comp = BufferUtils.createIntBuffer(1); STBImage.stbi_set_flip_vertically_on_load(1); ByteBuffer image = STBImage.stbi_load(this.link, w, h, comp, 0); int weight = w.get(0); int height = h.get(0); int compe = comp.get(0); Logger.getGlobal().log(Level.FINEST, "STBImage load status : " + weight + " " + height + " " + compe + " " + image); textureID = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); 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_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, weight, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, image); GL30.glBindVertexArray(0);//unbind vao }
From source file:opengl.test.object.table.table.java
@Override protected void initVertex() { GL30.glBindVertexArray(vao);//bind vao Object[] dataInput = objLoad.Wavefront( table.class.getClassLoader().getResourceAsStream("opengl/test/object/table/table.obj"), 1.0f, 1.0f, 1.0f);/* www.j a va 2 s . co m*/ super.dataBuffer = (FloatBuffer) dataInput[0]; this.size = (int) dataInput[1]; this.vbo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, super.dataBuffer, GL15.GL_STATIC_DRAW); this.VertexAttribPointer(); IntBuffer w = BufferUtils.createIntBuffer(1); IntBuffer h = BufferUtils.createIntBuffer(1); IntBuffer comp = BufferUtils.createIntBuffer(1); STBImage.stbi_set_flip_vertically_on_load(1); ByteBuffer image = STBImage.stbi_load("resource/wood2.png", w, h, comp, 0); int weight = w.get(0); int height = h.get(0); int compe = comp.get(0); Logger.getGlobal().log(Level.FINEST, "STBImage load status : " + weight + " " + height + " " + compe + " " + image); textureID = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); 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_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, weight, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, image); GL30.glBindVertexArray(0);//unbind vao }
From source file:opengl.test.object.tivi.tivi.java
@Override protected void initVertex() { GL30.glBindVertexArray(vao);//bind vao Object[] dataInput = objLoad.Wavefront( tivi.class.getClassLoader().getResourceAsStream("opengl/test/object/tivi/tivi.obj"), 1.0f, 1.0f, 1.0f);/*from w ww . ja v a 2s.c o m*/ super.dataBuffer = (FloatBuffer) dataInput[0]; this.size = (int) dataInput[1]; this.vbo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, super.dataBuffer, GL15.GL_STATIC_DRAW); this.VertexAttribPointer(); IntBuffer w = BufferUtils.createIntBuffer(1); IntBuffer h = BufferUtils.createIntBuffer(1); IntBuffer comp = BufferUtils.createIntBuffer(1); STBImage.stbi_set_flip_vertically_on_load(1); ByteBuffer image = STBImage.stbi_load("resource/success.png", w, h, comp, 0); textureID = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); 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_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, w.get(0), h.get(0), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, image); GL30.glBindVertexArray(0);//unbind vao }
From source file:org.agpu.oc.client.ClientProxy.java
@Override public int setup2DScreenTextureTarget(int w, int h) { //Generate Texture Space int texture = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); //Generate Blank Texture GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, w, h, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_INT, (IntBuffer) null);/* w w w . j a v a2s .c o m*/ //Poor filtering. Needed! 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); System.out.println("Generated AGPU output texture"); return texture; }
From source file:org.fusfoundation.kranion.ImageLabel.java
License:Open Source License
private void buildTexture(String resource) { BufferedImage img = null;// w ww. ja v a2 s . com try { InputStream rstm = this.getClass().getResourceAsStream(resource); img = ImageIO.read(rstm); } catch (IOException e) { return; } try { //Create the PNGDecoder object and decode the texture to a buffer int width = img.getWidth(), height = img.getHeight(); bounds.width = width; bounds.height = height; byte buf[] = (byte[]) img.getRaster().getDataElements(0, 0, width, height, null); ByteBuffer pixelData = ByteBuffer.allocateDirect(buf.length); pixelData.put(buf, 0, buf.length); pixelData.flip(); if (texName != 0) { deleteTexture(); } //Generate and bind the texture texName = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texName); //Upload the buffer's content to the VRAM GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixelData); //Apply filters 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_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); } catch (Exception e) { e.printStackTrace(); } }