本文介绍了Android的 - 绘制三维二维然后用OpenGL ES的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

画一些三维的东西在OpenGL ES后,我怎么能画一个平视显示器(文本或位图)??

我尝试这样做:

有人知道如何从看不破坏现场?切换到邻

Bartinger

解决方案

我找到了解决办法,但我忘了张贴:)对不起

 包at.bartinger.opengl;

进口javax.microedition.khronos.egl.EGLConfig;
进口javax.microedition.khronos.opengles.GL10;

进口android.content.Context;
进口android.opengl.GLSurfaceView;
进口android.opengl.GLU;
进口android.util.AttributeSet;

公共类GLGameView扩展GLSurfaceView实现GLSurfaceView.Renderer {


公共GLGameView(上下文的背景下){
    超(上下文);
    setRenderer(本);
}

公共GLGameView(上下文的背景下,ATTRS的AttributeSet){
    超(背景下,ATTRS);
    // TODO自动生成构造函数存根
}

@覆盖
公共无效onSurfaceCreated(GL10 GL,EGLConfig配置){
    的init(GL);
}

@覆盖
公共无效onDrawFrame(GL10 GL){

    //标准
    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);

    //设置3D
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gluPerspective(GL);



    draw3D(GL);


    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_DEPTH_TEST);

    //设置2D
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gluOrtho2D(GL);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();


    那么Draw2D(GL);

}

@覆盖
公共无效onSurfaceChanged(GL10 GL,诠释的宽度,高度INT){

}

公共无效的init(GL10 GL){}

公共无效Draw2D的(GL10 GL){};

公共无效draw3D(GL10 GL){};

/ **
 *设置投影邻矩阵
 * /
公共无效gluOrtho2D(GL10 GL){
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    GLU.gluOrtho2D(GL,0,的getWidth(),0,的getHeight());
}

/ **
 *设置投影的投影矩阵
 * /
公共无效gluPerspective(GL10 GL){
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    浮动的aspectRatio =(浮动)的getWidth()/的getHeight();
    GLU.gluPerspective(GL,67,的aspectRatio,1,100);
}

/ **
 *设置投影的投影矩阵
 * /
公共无效gluPerspective(GL10 GL,浮附近,浮远){
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    浮动的aspectRatio =(浮动)的getWidth()/的getHeight();
    GLU.gluPerspective(GL,67的aspectRatio,近,远);
}

/ **
 *设置投影到模型视图矩阵
 * /
公共无效gluLookAt(GL10 GL,
        浮位X,浮positionY,浮positionZ,
        浮zentrumX,浮zentrumY,浮zentrumZ,
        浮UPX,浮upY,浮UPZ){

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(GL,位X,positionY,positionZ,zentrumX,zentrumY,zentrumZ,UPX,upY,UPZ);
    }
}
 

How can i draw a HUD (Text or Bitmaps) after drawing some 3d stuff in openGL ES ??

I tried this:

Someone know how to switch from Perspective to Ortho without destroying the scene??

Bartinger

解决方案

I found the solution but i forgot to post it :) Sorry

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
}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    init(gl);
}

@Override
public 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);

}

@Override
public 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 );
    }
}

这篇关于Android的 - 绘制三维二维然后用OpenGL ES的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 15:50