Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Drawing 2d shape in 3d scene?  (Read 837 times)
0 Members and 1 Guest are viewing this topic.
Offline imsoepic

JGO n00b
*

Posts: 13



« on: 2009-11-12 14:57:26 »

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.
Offline Mickelukas

JGO Ninja
***

Posts: 731
Medals: 25


Java guru wanabee


« Reply #1 on: 2009-11-12 15:02:04 »

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

Mike

Offline imsoepic

JGO n00b
*

Posts: 13



« Reply #2 on: 2009-11-12 15:25:02 »

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.
Games published by our own members! Go get 'em!
Offline broumbroum

Sr. Member
**

Posts: 384



« Reply #3 on: 2009-11-13 17:01:56 »

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...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
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. Cheesy

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.134 seconds with 21 queries.