Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  JOGL Overlays  (Read 1889 times)
0 Members and 1 Guest are viewing this topic.
Offline zaknixon

Senior Newbie




</bored>


« Posted 2005-03-15 11:38:17 »

Is there any tutorials/samples of producing overlays in OpenGL / JOGL that someone can point me too?

Regards,

Zak Nixon

----------------------------------
Zak Nixon
Software Engineer
Davidson Technologies
-----------------------------------
Offline ozak

Junior Devvie




Java demon has no respect for bad code!!!


« Reply #1 - Posted 2005-03-17 11:02:35 »

Do you mean drawing 2D on top of your 3D scene?

Want to do multiplayer? Why not try my free Socky socket server?
It's scriptable through JavaScript!
Check it out at http://www.furi.dk/socky
Offline zaknixon

Senior Newbie




</bored>


« Reply #2 - Posted 2005-03-17 18:34:19 »

Yes.
Like a dashboard, or scene information...

Something simple, just 2D text. No 3D.

Zak

----------------------------------
Zak Nixon
Software Engineer
Davidson Technologies
-----------------------------------
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ozak

Junior Devvie




Java demon has no respect for bad code!!!


« Reply #3 - Posted 2005-03-19 12:01:26 »

Ahh yes. First you need to turn 2D on/off like so:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
     /**
         * Begin 2D mode.
         */

        public void begin2D()
        {
            gl.glMatrixMode(GL.GL_PROJECTION);
            gl.glPushMatrix();
            gl.glLoadIdentity();
            gl.glOrtho(0.0f,viewPortWidth, viewPortHeight, 0.0f, -1.0f, 1.0f);
            gl.glMatrixMode(GL.GL_MODELVIEW);
            gl.glPushMatrix();
            gl.glLoadIdentity();    
            gl.glDisable(GL.GL_DEPTH_TEST);
        }
       
        /**
         * End 2D mode.
         */

        public void end2D()
        {
            gl.glEnable(GL.GL_DEPTH_TEST);
            gl.glMatrixMode(GL.GL_PROJECTION);
            gl.glPopMatrix();
            gl.glMatrixMode(GL.GL_MODELVIEW);
            gl.glPopMatrix();  
        }
       


Using GLUT for simple text you could do like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
/** 
     * Draw text.
     * @param x X position of text
     * @param y Y position of text
     * @param text Text string to print
     */

    public void drawText(int x, int y, String text)
    {
        gl.glRasterPos2i(x, y);
        glut.glutBitmapString(gl, glut.BITMAP_HELVETICA_12, text);
    }


Drawing a 2D box could be done like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
/**
     * Draw 2D box.
     */

    public void draw2DBox(int x, int y, int width, int height)
    {
        // Do some calcs
        float fPosX = x;
        float fPosY = y;
        float fPosX2 = x + width;
        float fPosY2 = y + height;
       
        // Draw it
      gl.glBegin(GL.GL_TRIANGLES);
           
            gl.glVertex3f(fPosX, fPosY2, 0);
           
            gl.glVertex3f(fPosX2, fPosY, 0);
               
            gl.glVertex3f(fPosX, fPosY, 0);
           
            gl.glVertex3f(fPosX, fPosY2, 0);
           
            gl.glVertex3f(fPosX2, fPosY2, 0);
           
            gl.glVertex3f(fPosX2, fPosY, 0);
      gl.glEnd();
    }


If you want to use the active texture as a sprite, you could exchange the contents of the previous function like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
// Do some calcs
        float fPosX = x;
        float fPosY = y;
        float fPosX2 = x + width;
        float fPosY2 = y + height;
       
        // Draw it
      gl.glBegin(GL.GL_TRIANGLES);
            gl.glTexCoord2f(uvs[0], uvs[1]);
            gl.glVertex3f(fPosX, fPosY2, 0);
   
            gl.glTexCoord2f(uvs[2], uvs[3]);
            gl.glVertex3f(fPosX2, fPosY, 0);
   
            gl.glTexCoord2f(uvs[0], uvs[3]);
            gl.glVertex3f(fPosX, fPosY, 0);

            gl.glTexCoord2f(uvs[0], uvs[1]);
            gl.glVertex3f(fPosX, fPosY2, 0);

            gl.glTexCoord2f(uvs[2], uvs[1]);
            gl.glVertex3f(fPosX2, fPosY2, 0);

            gl.glTexCoord2f(uvs[2], uvs[3]);
            gl.glVertex3f(fPosX2, fPosY, 0);
      gl.glEnd();


The uv list is defined as a float array:

1  
2  
3  
4  
5  
// Setup standard UVs
        uvs[0] = 0.0f;
      uvs[1] = 0.0f;
        uvs[2] = 1.0f;
      uvs[3] = 1.0f;


You can adjust these for clipping, UV scroll etc.


Want to do multiplayer? Why not try my free Socky socket server?
It's scriptable through JavaScript!
Check it out at http://www.furi.dk/socky
Offline zaknixon

Senior Newbie




</bored>


« Reply #4 - Posted 2005-03-22 15:52:59 »

Thanks for the code, works beautifully.

Quick question. Once I draw a 2D box, and I put 3D objects in the scene, the 2D should always be "on top" of the 3D objects in the depth buffer. For some reason, this effect is not doing it.
Is there anyway to acheive this effect?

Thanks

Zak

----------------------------------
Zak Nixon
Software Engineer
Davidson Technologies
-----------------------------------
Offline Daire Quinlan

Junior Devvie





« Reply #5 - Posted 2005-03-22 16:24:30 »

Theres a couple of different ways you can do this. The way I do it is to use glOrtho with the near/far values set to 0/1 and then just draw everything at z=0. Another way you could do it is draw your 3D scene, clear the z-buffer then draw your 2D components.

D.
Offline ozak

Junior Devvie




Java demon has no respect for bad code!!!


« Reply #6 - Posted 2005-03-23 09:41:12 »

Draw your 3D as usual.
Call
begin2D()

Do 2D

end2D()

And it will always stay on top.
My code just disables the z-buffer, but any of the above suggestions would do the trick too.. Anyhow. The order is 3D then 2D (my code above) and it will work. Does for me that is Smiley

Want to do multiplayer? Why not try my free Socky socket server?
It's scriptable through JavaScript!
Check it out at http://www.furi.dk/socky
Offline zaknixon

Senior Newbie




</bored>


« Reply #7 - Posted 2005-03-23 10:44:35 »

Thanks, I figured out my problem. I was setting the
alpha value of my overlays, which produced the illusion of the 3D being placed on top of my 2D lines (only where they intersected).

Thanks for all the help.  Roll Eyes Grin

Zak

----------------------------------
Zak Nixon
Software Engineer
Davidson Technologies
-----------------------------------
Offline zaknixon

Senior Newbie




</bored>


« Reply #8 - Posted 2005-03-23 11:23:32 »

Another question:
Using 2D, you have specified the 2D box in 3D space. If I perform transformations upon that geometry, how would you specify it, in 2D or 3D? I have tried rotations and scales on the box, yet I get very strange results.

Thanks

Zak

----------------------------------
Zak Nixon
Software Engineer
Davidson Technologies
-----------------------------------
Offline Deadcow

Senior Newbie




Back from beyond ... Moo!


« Reply #9 - Posted 2005-03-23 11:40:23 »

There is no 2D in OpenGL, only 3D. glOrtho sets your projection matrix to a special case of perspective projection called "orthographic projection" where parallel lines remain parallel once projected. So your "2d box" is in fact a quad facing the camera in a 3d space. Now if you can think of your "2d box" as a quad, you should understand why rotating it along x or z axis appears to scale it and why translating it along the y axis has no effect.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Deadcow

Senior Newbie




Back from beyond ... Moo!


« Reply #10 - Posted 2005-03-23 11:51:59 »

About drawing something on the top of your scene, you can call glDepthRange( 1f, 1f ); before drawing and restore it to glDepthRange( 0f, 1f ). I've never tried that but it may work.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 10:26:44

Mr.CodeIt (31 views)
2014-12-14 20:50:38

BurntPizza (62 views)
2014-12-09 23:41:13

BurntPizza (99 views)
2014-12-08 05:46:31

JscottyBieshaar (60 views)
2014-12-05 13:39:02

SHC (74 views)
2014-12-03 17:27:13

CopyableCougar4 (77 views)
2014-11-29 22:32:03

toopeicgaming1999 (138 views)
2014-11-26 16:22:04

toopeicgaming1999 (127 views)
2014-11-26 16:20:36

toopeicgaming1999 (38 views)
2014-11-26 16:20:08
Resources for WIP games
by kpars
2014-12-18 11:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 23:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 23:36:02

List of Learning Resources
by Longor1996
2014-08-16 11:40:00

List of Learning Resources
by SilverTiger
2014-08-05 20:33:27

Resources for WIP games
by CogWheelz
2014-08-01 17:20:17

Resources for WIP games
by CogWheelz
2014-08-01 17:19:50

List of Learning Resources
by SilverTiger
2014-07-31 17:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!