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:net.smert.frameworkgl.opengl.helpers.TextureHelper.java
License:Apache License
public void setImage2DInt1010102PixelData(int internalFormat, int width, int height, int format, IntBuffer pixelData) {/*www .j a v a2 s. c o m*/ GL11.glTexImage2D(textureTarget, 0, internalFormat, width, height, 0, format, TextureTypes.UNSIGNED_INT_10_10_10_2, pixelData); }
From source file:net.smert.frameworkgl.opengl.helpers.TextureHelper.java
License:Apache License
public void setImage2DIntPixelData(int internalFormat, int width, int height, int format, IntBuffer pixelData) { GL11.glTexImage2D(textureTarget, 0, internalFormat, width, height, 0, format, TextureTypes.UNSIGNED_INT, pixelData);/*from w w w. j av a 2 s .co m*/ }
From source file:net.smert.frameworkgl.opengl.helpers.TextureHelper.java
License:Apache License
public void setImage2DShortPixelData(int internalFormat, int width, int height, int format, ShortBuffer pixelData) {//w w w .jav a 2 s .c o m GL11.glTexImage2D(textureTarget, 0, internalFormat, width, height, 0, format, TextureTypes.UNSIGNED_SHORT, pixelData); }
From source file:net.smert.frameworkgl.opengl.helpers.TextureHelper.java
License:Apache License
public void setImage2DStencilPixelData(int internalFormat, int width, int height, int format, IntBuffer pixelData) {//from w ww . ja v a 2 s . c om GL11.glTexImage2D(textureTarget, 0, internalFormat, width, height, 0, format, TextureTypes.UNSIGNED_INT_24_8, pixelData); }
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;//w w w. ja va2s .c om 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 ww . j a va2 s . 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("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// ww w. j ava2 s .c o 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 www . j a va 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/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);// w w w. j a v a 2 s.com 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);// ww w.j a v a2 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 }