I’m having trouble using glDrawPixels.
Is it possible to pass it an int[] that acts as the buffer? Do I have to create a new Buffer class that extends IntBuffer, a pixelbuffer or something? Any help is appreciated.
I’m having trouble using glDrawPixels.
Is it possible to pass it an int[] that acts as the buffer? Do I have to create a new Buffer class that extends IntBuffer, a pixelbuffer or something? Any help is appreciated.
You can use BufferUtil.newIntBuffer(size) to make an IntBuffer of the appropriate size. Then, you call buffer.put(index, int_value) and buffer.get(index) if you want to access the buffer. Make sure that you call buffer.rewind() before calling your glDrawPixels method.
Here is an example:
IntBuffer buffer = BufferUtil.newIntBuffer(4 * 64 * 64); // 64 for width and height, 4 since this will be fore RGBA
for (int y = 0; y < 64; y++)
for (int x = 0; x < 64; x++)
buffer.put(y * 64 + x + [0,1,2,3], color); // here would actually be multiple lines, one for each number in the []'s
buffer.rewind();
gl.glDrawPixels(64, 64, GL.GL_RGBA, GL.GL_INT, buffer);
If you wanted a different type of data, you could use FloatBuffer or ShortBuffer and then switch GL.GL_INT to GL.GL_FLOAT or whatever. If you change GL.GL_RGBA, make sure that your buffer has the right size, for example: GL.GL_RGB would require 3 * width * height
Also, you don’t have to use power-of-two dimensions.