I have an 3D openGL app that renders a vanilla scene, spheres, cylinders,
etc, and can be rotated using the mouse.
I would like to put a 2D graphic on the "window" and not have it be a part
of the 3D world. For example, I would like to draw a square or a circle
inset from the window edges. When the scene is rotated, the 2D elements are
not affected.
I want the 2D elements to always be "in front" of anything in the 3D scene.
I've sort-of accomplished this using gluUnProject to unproject window-based
coords back to world space, turning off the depth test, and drawing the
circle. However, this seems like too much work to make the 2D object part
of the 3D scene.
Here's what I currently do....
glDisable(GL_DEPTH_TEST);
gluUnProject(windowCentX, windowCentY, 0, mvmatrix, projmatrix, viewport,
&worldCentX, &worldCentY, &worldCentZ);
draw some stuff using worldCentX, worldCentY, worldCentZ......
glEnable(GL_DEPTH_TEST);
Is there any snappier way to just do a 2D rendering to a window without all
the back-transforms, etc.?
Any ideas or suggestions would be welcome.
Thanks in advance,
Mark
|
|
0
|
|
|
|
Reply
|
Mark
|
2/10/2004 9:21:22 PM |
|
Mark,
I'm new to OpenGL as well, but what I think you are looking for is an
orthographic projection. Take a look at a tutorial for projections, and
look at the man pages for gluOrtho2d. I think this will help you do what
you are looking for.
http://www.cprogramming.com/tutorial/gl7.html
Justin
"Mark" <markt158_REMOVE_@comcast.net> wrote in message
news:mXbWb.142268$U%5.646527@attbi_s03...
>
> I have an 3D openGL app that renders a vanilla scene, spheres, cylinders,
> etc, and can be rotated using the mouse.
>
> I would like to put a 2D graphic on the "window" and not have it be a part
> of the 3D world. For example, I would like to draw a square or a circle
> inset from the window edges. When the scene is rotated, the 2D elements
are
> not affected.
>
> I want the 2D elements to always be "in front" of anything in the 3D
scene.
>
> I've sort-of accomplished this using gluUnProject to unproject
window-based
> coords back to world space, turning off the depth test, and drawing the
> circle. However, this seems like too much work to make the 2D object part
> of the 3D scene.
>
> Here's what I currently do....
> glDisable(GL_DEPTH_TEST);
> gluUnProject(windowCentX, windowCentY, 0, mvmatrix, projmatrix, viewport,
> &worldCentX, &worldCentY, &worldCentZ);
> draw some stuff using worldCentX, worldCentY, worldCentZ......
> glEnable(GL_DEPTH_TEST);
>
>
> Is there any snappier way to just do a 2D rendering to a window without
all
> the back-transforms, etc.?
>
> Any ideas or suggestions would be welcome.
>
> Thanks in advance,
> Mark
>
>
|
|
0
|
|
|
|
Reply
|
Justin
|
2/10/2004 10:07:55 PM
|
|
Mark wrote:
> I have an 3D openGL app that renders a vanilla scene, spheres, cylinders,
> etc, and can be rotated using the mouse.
>
> I would like to put a 2D graphic on the "window" and not have it be a part
> of the 3D world. For example, I would like to draw a square or a circle
> inset from the window edges. When the scene is rotated, the 2D elements are
> not affected.
>
> I want the 2D elements to always be "in front" of anything in the 3D scene.
>
> I've sort-of accomplished this using gluUnProject to unproject window-based
> coords back to world space, turning off the depth test, and drawing the
> circle. However, this seems like too much work to make the 2D object part
> of the 3D scene.
>
> Here's what I currently do....
> glDisable(GL_DEPTH_TEST);
> gluUnProject(windowCentX, windowCentY, 0, mvmatrix, projmatrix, viewport,
> &worldCentX, &worldCentY, &worldCentZ);
> draw some stuff using worldCentX, worldCentY, worldCentZ......
> glEnable(GL_DEPTH_TEST);
>
>
> Is there any snappier way to just do a 2D rendering to a window without all
> the back-transforms, etc.?
>
> Any ideas or suggestions would be welcome.
>
> Thanks in advance,
> Mark
>
>
You don't need to perform back-transforms.
A very simple way to perform this is to define a 2d projection over
your 3d projection
After the code for drawing your 3d scene and before sending all to
your window :
add for example :
glMatrixMode(GL_PROJECTION); /* enter projection mode */
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0,100, 0, 100); /* defines a 2d projection */
glDisable(GL_DEPTH_TEST); /* disable depth test to enable overlay */
glDisable(GL_LIGHTING);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* add blending */
glEnable(GL_BLEND);
glColor4f(0.8, 0.8, 0.8, 0.5); /* color for blending */
glRecti(20, 20, 80, 80); /* draw a rectangle */
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
As a result this draw a fixed blended grey rectangle over your 3d scene
Hope this helps.
--
Alexis GOURDON | mailto:Alexis.Gourdon@sophia.inria.fr
INRIA Projet PLANETE | Phone: +33 (0)4 92 38 50 21
2004 route des Lucioles BP 93 | Fax : +33 (0)4 92 38 79 78
06902 Sophia-Antipolis FRANCE | http://www.inria.fr/planete/agourdon
|
|
0
|
|
|
|
Reply
|
Alexis
|
2/11/2004 9:03:10 AM
|
|
Do everything on your own.
Draw 3d objects first then disable depth test and change the matrices
// draw 3d stuff
// SWITCH to 2D MODE
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// this will allow you to use pixel coordinates
glOrtho(0, m_nSizeX, m_nSizeY, 0, 1, -1);
glDisable(GL_DEPTH_TEST);
// draw objects in 2D
// go back to 3D mode
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
Dmitri
"Mark" <markt158_REMOVE_@comcast.net> �������/�������� � �������� ���������:
news:mXbWb.142268$U%5.646527@attbi_s03...
>
> I have an 3D openGL app that renders a vanilla scene, spheres, cylinders,
> etc, and can be rotated using the mouse.
>
> I would like to put a 2D graphic on the "window" and not have it be a part
> of the 3D world. For example, I would like to draw a square or a circle
> inset from the window edges. When the scene is rotated, the 2D elements
are
> not affected.
>
> I want the 2D elements to always be "in front" of anything in the 3D
scene.
>
> I've sort-of accomplished this using gluUnProject to unproject
window-based
> coords back to world space, turning off the depth test, and drawing the
> circle. However, this seems like too much work to make the 2D object part
> of the 3D scene.
>
> Here's what I currently do....
> glDisable(GL_DEPTH_TEST);
> gluUnProject(windowCentX, windowCentY, 0, mvmatrix, projmatrix, viewport,
> &worldCentX, &worldCentY, &worldCentZ);
> draw some stuff using worldCentX, worldCentY, worldCentZ......
> glEnable(GL_DEPTH_TEST);
>
>
> Is there any snappier way to just do a 2D rendering to a window without
all
> the back-transforms, etc.?
>
> Any ideas or suggestions would be welcome.
>
> Thanks in advance,
> Mark
>
>
|
|
0
|
|
|
|
Reply
|
Dmitri
|
2/11/2004 12:22:10 PM
|
|
|
3 Replies
435 Views
(page loaded in 0.288 seconds)
Similiar Articles: Display 2D circle on "screen" over 3D scene - comp.graphics.api ...I have an 3D openGL app that renders a vanilla scene, spheres, cylinders, etc, and can be rotated using the mouse. I would like to put a 2D graphic ... Epilog with 3 dimensional graphics primitives - comp.soft-sys.math ...Display 2D circle on "screen" over 3D scene - comp.graphics.api ... Epilog with 3 dimensional graphics primitives - comp.soft-sys.math ... It seems that only 2D graphics ... Display 2D font and bitmap over perspective result - comp.graphics ...... display fonts and bitmaps on my opengl screen over the final result. I mean, I want to render my 3d ... scene with mouse - comp.graphics ... Display 2D font and bitmap over ... World to screen coordinates - comp.graphics.api.openglDisplay 2D circle on "screen" over 3D scene - comp.graphics.api ..... to put a 2D graphic on the "window" and not have it be a part of the 3D world. ... Blending useing glColor4f(....) - comp.graphics.api.opengl ...Display 2D circle on "screen" over 3D scene - comp.graphics.api ..... scene, spheres, cylinders, etc, and can be rotated using the ... glBlendFunc(GL_SRC_ALPHA, GL_ONE ... text in OpenGL - comp.graphics.api.opengl... related to scene) but X ... Display 2D font and bitmap over perspective ... on my opengl screen over the final result. I mean, I want to render my 3d object and display text ... Drawing Text Using OpenGL - comp.graphics.api.openglDisplay 2D circle on "screen" over 3D scene - comp.graphics.api ... Drawing Text Using OpenGL - comp.graphics.api.opengl Hello, I'm using GLUT to draw 2D text to screen ... opengl + zoom - comp.graphics.api.openglOn this 3D shape there are a ... Display 2D font and bitmap over perspective result - comp ... Hi, Im trying to display fonts and bitmaps on my opengl screen over the final ... Displaying 10-bit image data using OpenGL - comp.graphics.api ...Display 2D circle on "screen" over 3D scene - comp.graphics.api ... Displaying 10-bit image data using OpenGL - comp.graphics.api ... screen coordinates and mouse event ... OpenGL + drawing text - comp.graphics.api.openglHow to draw circle (round) text using iTextSharp ... I'm using FTGL to draw text within my OGL scene ... Display 2D font and bitmap over perspective result - comp.graphics ... Display 2D circle on "screen" over 3D scene - comp.graphics.api ...I have an 3D openGL app that renders a vanilla scene, spheres, cylinders, etc, and can be rotated using the mouse. I would like to put a 2D graphic ... Draw some 2D as overlay on a 3D scene - opengl - Mofeel GroupsHow to find if 3D->2D transform is out of the scene. 6. Display 2D circle on "screen" over 3D scene I have an 3D openGL app that renders a vanilla scene, spheres, cylinders ... 7/24/2012 7:12:09 AM
|