V
Senior Member
Offline
Posts: 430
portugal
Re: 2D drawing on a 3D scene
Reply #1 - Sep 11th , 2008, 12:34pm
you can use ortho mode and define a different viewport where you draw your HUD here's a class i use to draw a fullscreen quad. it defines a space of the size of the screen and from there u just draw normally (in other words as you would normally when u using a processing sketch) i use direct opengl calls, but you could change it easily to use processing ones. class Overlay { Overlay( GL gl ) { _gl = gl; } void setOrtho() { // // save old MVP matrices and set ortho mode for screen size (pixels) // warning. after drawing you must call unsetOrtho() call // // Setting orthographic projection. _gl.glMatrixMode( GL.GL_PROJECTION ); _gl.glPushMatrix(); _gl.glLoadIdentity(); _gl.glOrtho( 0.0, width, 0.0, height, -1.0, 1.0 ); _gl.glMatrixMode( GL.GL_MODELVIEW ); _gl.glPushMatrix(); _gl.glLoadIdentity(); } void unsetOrtho() { // restore old matrices MVP _gl.glMatrixMode( GL.GL_PROJECTION ); _gl.glPopMatrix(); _gl.glMatrixMode( GL.GL_MODELVIEW ); _gl.glPopMatrix(); } void draw( int texID ) { // bind texture _gl.glBindTexture( GL.GL_TEXTURE_2D, texID ); gl._gl.glBegin( GL.GL_QUADS ); gl._gl.glNormal3f( 0.0f, 0.0f, 1.0f ); gl._gl.glColor4f( gl._r, gl._g, gl._b, gl._a ); gl._gl.glTexCoord2f( 0.0, 0.0 ); gl._gl.glVertex2f( 0.0, 0.0 ); gl._gl.glTexCoord2f( 1.0, 0.0 ); gl._gl.glVertex2f( width, 0.0 ); gl._gl.glTexCoord2f( 1.0, 1.0 ); gl._gl.glVertex2f( width, height ); gl._gl.glTexCoord2f( 0.0, 1.0 ); gl._gl.glVertex2f( 0.0, height ); gl._gl.glEnd(); // unbind texture //_gl.glBindTexture( GL.GL_TEXTURE_2D, 0 ); } // // Members // GL _gl; };