我尝试通过GLSurfaceView将我的Activity中的值发送到Renderer,但是SurfaceView类中的对象存在一些问题。我想我无法通过我的活动直接访问渲染器,我已经尝试过了。 当我尝试设置值时,我在GLView类中得到一个null-Exception。
public class Activity extends Activity implements SeekBar.OnSeekBarChangeListener{
GLSurfaceView mGLView;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_1d);
mGLView = (GLView)findViewById(R.id.surfaceView1D);
mGLView = new GLView(this,10);
// mGLView.mRenderer.var_in_Renderer=10; //Test, but not Working!
}
...
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
mGLView.var_in_Renderer=progress; //Not working
mGLView.setProgress(progress);
}
...
}
class GLView extends GLSurfaceView {
MyGLRenderer mRenderer;
void setProgress(int progress){
mRenderer.var_in_Renderer=progress; //Error!!!!!!!!!!!!!!!!
}
//Empty Constructor don't go, so I filled
public GLView(Context context,int progress){
super(context);
}
public GLView(Context context, AttributeSet attrs) {
super(context,attrs);
// Set the Renderer for drawing on the GLSurfaceView
mRenderer = new MyGLRenderer();
setRenderer(mRenderer);
mRenderer.var_in_Renderer=10; //That would work, but is not what I need
}
}
如何在渲染器中为变量设置值?