Hi, everyone,
I've been looking for several days for a solution to my problem.
I'm currently trying to draw a simple rectangle on a GLCanvas.
It works pretty well but as soon as I try to add polygon stippling the rectangle doesn't get drawn at all.
Here's the code I use for it:
1. initialize a ByteBuffer instance as a stipple mask of
32x32 bits = 128 bytes
private void initByteBuffer(){
//to avoid IllegalArgumentException the buffer capacity must
//be 1024 + 128 bytes
fly = ByteBuffer.allocateDirect(1024+128);
fly.put(new byte[]{
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x03, (byte)0x80, (byte)0x01, (byte)0xC0,
(byte)0x06, (byte)0xC0, (byte)0x03, (byte)0x60,
(byte)0x04, (byte)0x60, (byte)0x06, (byte)0x20,
(byte)0x04, (byte)0x30, (byte)0x0C, (byte)0x20,
(byte)0x04, (byte)0x18, (byte)0x18, (byte)0x20,
(byte)0x04, (byte)0x0C, (byte)0x30, (byte)0x20,
(byte)0x04, (byte)0x06, (byte)0x60, (byte)0x20,
(byte)0x44, (byte)0x03, (byte)0xC0, (byte)0x22,
(byte)0x44, (byte)0x01, (byte)0x80, (byte)0x22,
(byte)0x44, (byte)0x01, (byte)0x80, (byte)0x22,
(byte)0x44, (byte)0x01, (byte)0x80, (byte)0x22,
(byte)0x44, (byte)0x01, (byte)0x80, (byte)0x22,
(byte)0x44, (byte)0x01, (byte)0x80, (byte)0x22,
(byte)0x44, (byte)0x01, (byte)0x80, (byte)0x22,
(byte)0x66, (byte)0x01, (byte)0x80, (byte)0x66,
(byte)0x33, (byte)0x01, (byte)0x80, (byte)0xCC,
(byte)0x19, (byte)0x81, (byte)0x81, (byte)0x98,
(byte)0x0C, (byte)0xC1, (byte)0x83, (byte)0x30,
(byte)0x07, (byte)0xe1, (byte)0x87, (byte)0xe0,
(byte)0x03, (byte)0x3f, (byte)0xfc, (byte)0xc0,
(byte)0x03, (byte)0x31, (byte)0x8c, (byte)0xc0,
(byte)0x03, (byte)0x33, (byte)0xcc, (byte)0xc0,
(byte)0x06, (byte)0x64, (byte)0x26, (byte)0x60,
(byte)0x0c, (byte)0xcc, (byte)0x33, (byte)0x30,
(byte)0x18, (byte)0xcc, (byte)0x33, (byte)0x18,
(byte)0x10, (byte)0xc4, (byte)0x23, (byte)0x08,
(byte)0x10, (byte)0x63, (byte)0xC6, (byte)0x08,
(byte)0x10, (byte)0x30, (byte)0x0c, (byte)0x08,
(byte)0x10, (byte)0x18, (byte)0x18, (byte)0x08,
(byte)0x10, (byte)0x00, (byte)0x00, (byte)0x08
});
}
2. Try to draw a rectangle using polygon stipple:
public void draw() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glEnable(GL11.GL_POLYGON_STIPPLE);
GL11.glPolygonStipple(fly);
GL11.glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
GL11.glFlush();
}
The result of this is black
There should be a white/stippled rectangle right in the middle of the viewport but there is none.
I'm new to this OpenGL stuff in Java (but not to Java itself).
There must be something wrong with the ByteBuffer (especially the size of it) which I just don't understand. The rectangle is drawn the way I want it to be drawn when I GL11.glDisable(GL_POLYGON_STIPPLE)...
Why does the buffer has to be at least 1024 in size plus the actual bitmask?
And why doesn't it work (the ultimate question
)?
I hope there's someone who can help me.
Thanks in advance.
Signed: TalanOFF