java - How to redraw opengl renderer after clicking button? -
i'm trying update glulookat() main ui thread of opengl renderer i've tryed requestrenderer() methode @ end of code button eclipes gives me sme errors wondering best possible way main ui thread?
heres mainactivity class:
public class mainactivity extends activity implements onclicklistener { glsurfaceview oursurface; glrenderer call; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); oursurface = new surfaceview(this); setcontentview(r.layout.activity_main); framelayout v = (framelayout) findviewbyid(r.id.canvas); v.addview(oursurface); } @override public void onclick(view v) { // todo auto-generated method stub switch (v.getid()){ case r.id.pluseyex: break; case r.id.minuseyex: break; case r.id.pluseyey: break; case r.id.minuseyey: break; case r.id.pluseyez: float z =call.geteyez()+1; call.seteyez(z); break; case r.id.minuseyez: break; } }
here renderer:
public class surfaceview extends glsurfaceview { private final glrenderer mrenderer; public surfaceview(context context) { super(context); // todo auto-generated constructor stub mrenderer = new glrenderer(); setrenderer(mrenderer); setrendermode(glsurfaceview.rendermode_when_dirty); } public class glrenderer implements renderer { public volatile float eyez =-5; public float geteyez() { return eyez; } public void seteyez(float eyez) { this.eyez = eyez; } private gltriex tri; //private glcubeex cube; public glrenderer(){ tri = new gltriex(); //cube = new glcubeex(); } @override public void onsurfacecreated(gl10 gl, eglconfig eglconfig) { // todo auto-generated method stub gl.gldisable(gl10.gl_dither); gl.glhint(gl10.gl_perspective_correction_hint, gl10.gl_fastest); gl.glclearcolor(.8f, 0f, .2f, 1f); gl.glcleardepthf(1f); } @override public void ondrawframe(gl10 gl) { // todo auto-generated method stub gl.gldisable(gl10.gl_dither); gl.glclear(gl10.gl_color_buffer_bit | gl10.gl_depth_buffer_bit); gl.glmatrixmode(gl10.gl_modelview); gl.glloadidentity(); glu.glulookat(gl, 0, 0, -5, 0, 0, 0, 0, 2, 0); //long time = systemclock.uptimemillis()% 4000l; //float angle =.090f * ((int)time); //gl.glrotatef(angle, 1, 0, 2); tri.draw(gl); //cube.draw(gl); } @override public void onsurfacechanged(gl10 gl, int width, int height) { // todo auto-generated method stub gl.glviewport(0, 0, width, height);//bottom left corrnor float ratio = (float) width/height; gl.glmatrixmode(gl10.gl_projection); gl.glloadidentity(); gl.glfrustumf(-ratio, ratio, -1, 1, 1, 25); //gl.glfrustumf(left, right, bottom, top, znear, zfar) } } }
you're not using eyez
value anywhere in renderer
.
i think want replace
glu.glulookat(gl, 0, 0, -5, 0, 0, 0, 0, 2, 0);
by
glu.glulookat(gl, 0, 0, eyez, 0, 0, 0, 0, 2, 0);
to see effect pressing button.
Comments
Post a Comment