Java-Android-使用openGL ES绘制3D然后绘制2D

Java-Android-使用openGL ES绘制3D然后绘制2D,第1张

概述在openGLES中绘制一些3d内容后,如何绘制HUD(文本或位图)?我尝试了这个:privatevoidswitchTo2D(GL10gl){gl.glDisable(GL10.GL_DEPTH_TEST);gl.glMatrixMode(GL10.GL_PROJECTION);gl.glPushMatrix();gl.glLoadIdentity();gl.glMatrixMode(GL10.GL_P

在openGL ES中绘制一些3d内容后,如何绘制HUD(文本或位图)?

我尝试了这个:

private voID switchTo2D(GL10 gl){    gl.gldisable(GL10.GL_DEPTH_TEST);    gl.glMatrixMode(GL10.GL_PROJECTION);    gl.glPushmatrix();    gl.glLoadIDentity();    gl.glMatrixMode( GL10.GL_PROJECTION );    gl.glLoadIDentity();    glu.gluOrtho2D( gl, 0, getVIEwportWIDth(), 0, getVIEwportHeight() );  gl.glMatrixMode(GL10.GL_MODELVIEW);    gl.glLoadIDentity();  }

有人知道如何在不破坏场景的情况下从“透视”切换到“正交”吗?

解决方法:

我找到了解决方案,但我忘了发布了:)对不起

package at.bartinger.opengl;import javax.microedition.khronos.egl.EGLConfig;import javax.microedition.khronos.opengles.GL10;import androID.content.Context;import androID.opengl.GLSurfaceVIEw;import androID.opengl.glu;import androID.util.AttributeSet;public class GLGameVIEw extends GLSurfaceVIEw implements GLSurfaceVIEw.Renderer{public GLGameVIEw(Context context) {    super(context);    setRenderer(this);}public GLGameVIEw(Context context, AttributeSet attrs) {    super(context, attrs);    // Todo auto-generated constructor stub}@OverrIDepublic voID onSurfaceCreated(GL10 gl, EGLConfig config) {    init(gl);}@OverrIDepublic voID onDrawFrame(GL10 gl) {    //Standard    gl.glClear( GL10.GL_color_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT );    gl.glVIEwport( 0, 0, getWIDth(), getHeight() );    gl.gldisable( GL10.GL_DITHER );    gl.glEnable( GL10.GL_DEPTH_TEST );    gl.glEnable( GL10.GL_CulL_FACE );    //Set 3D    gl.glMatrixMode( GL10.GL_PROJECTION );    gl.glLoadIDentity();    gluPerspective( gl);        draw3D(gl);    gl.gldisable( GL10.GL_CulL_FACE );    gl.gldisable( GL10.GL_DEPTH_TEST );    //Set 2D    gl.glMatrixMode( GL10.GL_PROJECTION );    gl.glLoadIDentity();    gluOrtho2D(gl);    gl.glMatrixMode( GL10.GL_MODELVIEW );    gl.glLoadIDentity();    draw2D(gl);}@OverrIDepublic voID onSurfaceChanged(GL10 gl, int wIDth, int height) {}public voID init(GL10 gl){}public voID draw2D(GL10 gl){};public voID draw3D(GL10 gl){};/** * Sets the projection to the ortho matrix */public voID gluOrtho2D(GL10 gl){    gl.glMatrixMode( GL10.GL_PROJECTION );    gl.glLoadIDentity();    glu.gluOrtho2D( gl, 0, getWIDth(), 0, getHeight() );}/** * Sets the projection to the perspective matrix */public voID gluPerspective(GL10 gl){    gl.glMatrixMode( GL10.GL_PROJECTION );    gl.glLoadIDentity();    float aspectRatio = (float)getWIDth() / getHeight();    glu.gluPerspective( gl, 67, aspectRatio, 1, 100 );}/** * Sets the projection to the perspective matrix */public voID gluPerspective(GL10 gl, float near, float far){    gl.glMatrixMode( GL10.GL_PROJECTION );    gl.glLoadIDentity();    float aspectRatio = (float)getWIDth() / getHeight();    glu.gluPerspective( gl, 67, aspectRatio, near, far );}/** * Sets the projection to the model vIEw matrix */public voID gluLookAt(GL10 gl,         float positionX, float positionY, float positionZ,        float ZentrumX, float ZentrumY, float ZentrumZ,        float upX, float upY, float upZ ){    gl.glMatrixMode( GL10.GL_MODELVIEW );    gl.glLoadIDentity();    glu.gluLookAt( gl,positionX, positionY, positionZ, ZentrumX, ZentrumY, ZentrumZ, upX, upY, upZ );    }}
总结

以上是内存溢出为你收集整理的Java-Android-使用openGL ES绘制3D然后绘制2D全部内容,希望文章能够帮你解决Java-Android-使用openGL ES绘制3D然后绘制2D所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1083200.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存