android - Trying to use Ortho for drawing 2D -


i'm having trouble setting ortho view drawing 2d ontop of 3d scene.

i set view this:

public void onsurfacechanged( gl10 gl, int width, int height ) {     gl.glviewport( 0, 0, width, height );     gl.glmatrixmode( gl10.gl_projection );     gl.glloadidentity();     glu.gluperspective( gl, 45.0f, ( ( float )width / ( float )height ), 0.1f, 100.0f );     gl.glmatrixmode( gl10.gl_modelview );     gl.glloadidentity(); } 

and set ortho view this:

public void onsurfaceortho( gl10 gl ) {     gl.glorthof( 0.0f, 100.0f, 100.0f, 0.0f, -0.1f, 0.1f );     gl.glmatrixmode( gl10.gl_projection );     gl.glloadidentity(); } 

then draw frame this:

public void ondrawframe( gl10 gl ) {     gl.glclear( gl10.gl_color_buffer_bit | gl10.gl_depth_buffer_bit );     gl.glloadidentity();     scene.ondrawframe( gl );     gl.glpushmatrix();     onsurfaceortho( gl );     screen.ondrawframe( gl );     gl.glpopmatrix(); } 

the scene , screen objects drawing objects 3d , 2d. screen object doesn't draw yet i'm starting 2d ortho views. scene objects draw cube. works ok until add new code 2d ortho drawing - glpushmatrix() glpopmatrix(). don't see clear color.

so code in function onsurfaceortho() clears screen?

i expect has been drawn view before call set ortho view, left alone. don't call explicit clear bits, still seems clears view - , code in onsurfaceortho() function.

how can set 2d ortho view correctly can draw 2d ontop of 3d view?

so figured out little martinho fernandes.

i set 2 functions:

public void onsurfaceortho( gl10 gl ) {     gl.glmatrixmode( gl10.gl_projection );     gl.glloadidentity();     gl.glorthof( 0.0f, 100.0f, 0.0f, 100.0f, -0.1f, 0.1f );     gl.glmatrixmode( gl10.gl_modelview );     gl.glloadidentity(); }  public void onsurfaceperspective( gl10 gl ) {     gl.glmatrixmode( gl10.gl_projection );     gl.glloadidentity();     glu.gluperspective( gl, 45.0f, aspect, 0.1f, 100.0f );     gl.glmatrixmode( gl10.gl_modelview );     gl.glloadidentity(); } 

then when frame draw:

public void ondrawframe( gl10 gl ) {     gl.glclear( gl10.gl_color_buffer_bit | gl10.gl_depth_buffer_bit );     gl.glloadidentity();     onsurfaceperspective( gl );     scene.ondrawframe( gl );     onsurfaceortho( gl );     screen.ondrawframe( gl ); } 

so each frame have call function setting perspective before drawing 3d, , call function ortho before drawing 2d.

i'm not sure if have performance issues, or if there can it. know "full" opengl have lists can bit here...


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -