Drawing 2d shape in 3d scene?

I need help, i want to draw a rectangle in 2d over the 3d screen, it’s for selecting stuff, basically the retangle shouls appear 2d at the front of the screen overlapping the whole part you select and then draw.

However, the 3d screen is rotated so it’s not as easy as i thought.

I have the drag to make the size etc working, but now i need the actual drawing, thanks for any help.

For this help you could just supply a basic drawing of the rectangle with any dimensions and any coordinates.

Thanks.

Seeing as you’re using JOGL, look into the overlay functions, I think they are exactly what you want.

Mike

Ok, i just spent about 15 minutes on google trying to find a good example of using a 2d overlay in JOGL but i couldn’t, the only site which looked promising you had to pay to see the answer lol.

Please could you try and put together a really really basic example, thanks for any help.

There’s no real need of an overlay, as you want a single rectangular shape to draw. OpenGL can render a quad (a GL_polygon) with no texture, you choose to fill it or the outline you want. GL_fill or GL_line
There’s no particular difficulty to doing this…

protected static void _GLdoPolygon(AWTGLCanvas gld, boolean fill, float lineWidth, Point.Float[] vertexes, float[][] vertexesColors, double z) {
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        if (fill) {
            GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
        } else {
            GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
        }
        GL11.glPushAttrib(GL11.GL_LINE_BIT);
        GL11.glLineWidth(lineWidth);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);
        float[] color = GLHandler._GLgetCurrentColor(gld);
        GL11.glBegin(GL11.GL_POLYGON);
        int i = 0;
        for (Point.Float pf : vertexes) {
            float[] c = vertexesColors[i++];
            GL11.glColor4f(c[0], c[1], c[2], c[3]);
            GL11.glVertex3f(pf.x, pf.y, (float) z);
        }
        GL11.glEnd();
        GL11.glColor3f(color[0], color[1], color[2]);
        GL11.glPopAttrib();
        GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
    }

This sample is part of the GLGeom class of JigaXtended API. I’m running LWJGL 2.1 but this could be easily ported to JOGL. :smiley: