standard button to interact with glsurfaceview.. possible?

Problems with Canvas, OpenGL, etc...

standard button to interact with glsurfaceview.. possible?

Postby nmesisca » Wed Oct 27, 2010 3:42 pm

hi all,
i m starting with OpenGL and have a question I cant seem to find any resource on..

my glSurfaceView is in an activity with 2 buttons.
i would like the buttons to interact with the glSurfaceView (for example zoom in/zoom out).
I implemented a couple of methods in the glSurfaceView, that raise a queueevent (which changes a value in the renderer). I have then bound the button's onClick events to those methods.
I have not used touch event (because the glSurfaceView is not meant to be touch sensitive)..
This does not work, though it does not generate any error, the perspective is simply not changed.
..
If i use touch event in the glSurfaceView then everything works fine.
Could someone please help me shed some light if what im asking is possible?

thanks for your help,
N
nmesisca
Freshman
Freshman
 
Posts: 8
Joined: Thu Apr 09, 2009 12:30 pm
Location: Dublin

Top

Re: standard button to interact with glsurfaceview.. possibl

Postby seed » Thu Oct 28, 2010 4:01 pm

Sure it is possible. Curious. Did you debug it? Seems like a quick problem to find with a little debugging.

If the action is as simple as changing an atomic variable for something like zoom, then just setting a member variable for zoom in the renderer class will work fine rather than queing events. Some people write whole games without any queued events between threads. Not recommending this. Just saying. Maybe just do this as a test if you are resistant to bad coding practices that idiots like me on the forum recommend. ;)
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Re: standard button to interact with glsurfaceview.. possibl

Postby nmesisca » Thu Oct 28, 2010 5:35 pm

Hello seed,
thanks very much for trying to help..
the action is really simple, and I am surprised I still couldnt get it to work the way I wanted.
Let me give you a few details of the code.
The activity has 2 buttons, and 1 view that extends glsurfaceview.
Button zoomin calls this method defined in the extended glsurfaceview:

public void zoomIn() {
queueEvent(new Runnable() {
@Override
public void run() {
renderer.zoomIn(1.0f);
}
});
}

And in the renderer class this is the called method:

public void zoomIn(float forw) {
eye+=forw;
}

which updates

private float eye ;

..and :

@Override
public void onDrawFrame(GL10 gl) {
// Clear the screen to blue
gl.glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
// Position model so we can see it
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, eye-4.0f);
cube.draw(gl);
}

As I said, the only way i got this to work was detecting the ontouchevent on the glsurfaceview, and binding the rest of my code there.
I know this will sound trivial to most of you reading this.. but I have only started with openGL a few days ago..
I guess Im just missing something really obvious..?

again, thanks very much for any help you could give...

thanks
N




seed wrote:Sure it is possible. Curious. Did you debug it? Seems like a quick problem to find with a little debugging.

If the action is as simple as changing an atomic variable for something like zoom, then just setting a member variable for zoom in the renderer class will work fine rather than queing events. Some people write whole games without any queued events between threads. Not recommending this. Just saying. Maybe just do this as a test if you are resistant to bad coding practices that idiots like me on the forum recommend. ;)
nmesisca
Freshman
Freshman
 
Posts: 8
Joined: Thu Apr 09, 2009 12:30 pm
Location: Dublin

Re: standard button to interact with glsurfaceview.. possibl

Postby seed » Thu Oct 28, 2010 6:48 pm

Sorry, I probably shouldn't have spoken so soon. I don't really know what I am talking about. I haven't done anything like this. I suppose you probably want two views, one is your glSurface and one that has your buttons and do the onTouch in the other view - or something like that, but again I probably shouldn't have spoken.

I am curious about something. You said, "because the glSurfaceView is not meant to be touch sensitive". Really? I hadn't heard that. Why is that?

Thanks,
Charlie
Visit Exit 4 Gaming - http://www.exit4games.com/
Home of LavaBall - http://exit4games.com/?page_id=3
Home of Rebound - http://exit4games.com/?page_id=138
Home of Tap Crazy - http://exit4games.com/?page_id=219
Download "Caveman Pool" From the Market Today!
seed
Senior Developer
Senior Developer
 
Posts: 103
Joined: Mon Mar 15, 2010 3:22 pm

Re: standard button to interact with glsurfaceview.. possibl

Postby nmesisca » Thu Oct 28, 2010 6:58 pm

oh i see :)
I had my hopes raised already :(
..
no what I meant was that in the scope of my project the glsurface is not meant to trap any touch event itself. I wanted the user to click on the buttons in the normal view to do that..
but I just cant seem to understand how to achieve that..

hope someone else chimes in, if possible..

but thanks for your input seed,

N


seed wrote:Sorry, I probably shouldn't have spoken so soon. I don't really know what I am talking about. I haven't done anything like this. I suppose you probably want two views, one is your glSurface and one that has your buttons and do the onTouch in the other view - or something like that, but again I probably shouldn't have spoken.

I am curious about something. You said, "because the glSurfaceView is not meant to be touch sensitive". Really? I hadn't heard that. Why is that?

Thanks,
Charlie
nmesisca
Freshman
Freshman
 
Posts: 8
Joined: Thu Apr 09, 2009 12:30 pm
Location: Dublin

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 10 guests