明确了项目目录的结构,但是结构什么的也太"抽象"了。

本篇开始上代码!

 

模型的绘制-

前几天的学习中,live2d的绘制有了一些了解了,在Android端使用OpenGL ES绘制模型时需要Surface绘制和Renderer渲染,那么切入点就为GLSurfaceView和Renderer。

在SampleApp1中的sample包下LAppView和LAppRenderer就分别饰演的这两个角色

LAppRenderer implements GLSurfaceView.Renderer
LAppView extends GLSurfaceView 

 

渲染器类LAppRenderer -

LAppRenderer 类实现了Renderer接口,实现了onSurfaceCreated、onSurfaceChanged、onDrawFrame方法

【Android】用Cubism 2制作自己的Live2D——官方App样例源码学习(2)!

@Override
public void onSurfaceCreated(GL10 context, EGLConfig arg1) {
        setupBackground(context);
}

//设置背景图片
private void setupBackground(GL10 context) {
        try {
            InputStream in = FileManager.open(LAppDefine.BACK_IMAGE_NAME);
            bg=new SimpleImage(context,in);
            
            bg.setDrawRect(
                    LAppDefine.VIEW_LOGICAL_MAX_LEFT,
                    LAppDefine.VIEW_LOGICAL_MAX_RIGHT,
                    LAppDefine.VIEW_LOGICAL_MAX_BOTTOM,
                    LAppDefine.VIEW_LOGICAL_MAX_TOP);     
            bg.setUVRect(0.0f,1.0f,0.0f,1.0f);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
onSurfaceCreated()作为surface被创建后需要做的处理,但是这里只加载了背景图片
在onDrawFrame()方法中有很多的OpenGL绘制时的配置,由于LAppLive2DManager和Utils的存在很多操作都不在这里实现了,这里还是很明显的绘制出了background和models,方法还是熟悉的方法,只是藏了起来
if(bg!=null){
                gl.glPushMatrix() ;
                {
                    float SCALE_X = 0.25f ;
                    float SCALE_Y = 0.1f ;
                    gl.glTranslatef( -SCALE_X  * accelX , SCALE_Y * accelY , 0 ) ;

                    bg.draw(gl);
                }
                gl.glPopMatrix() ;
            }
            
            for(int i=0;i<delegate.getModelNum();i++)
            {
                LAppModel model = delegate.getModel(i);
                if(model.isInitialized() && ! model.isUpdating())
                {
                    model.update();
                    model.draw(gl);
                }
            }
绘制

相关文章:

  • 2021-12-11
  • 2021-11-04
  • 2022-12-23
  • 2021-05-13
  • 2021-08-03
  • 2022-02-27
  • 2021-06-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2022-12-23
相关资源
相似解决方案