Click here to Skip to main content
11,935,361 members (62,424 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ OpenGL
Hi there,

It's about OpenGLES 2 again. Now I got something nasty in my mind -_-.
How to rotate my draw (triangle and rectangle) with keyboard input? Such as, (w,a,s,d) for (up,down,right,left) and so on.

Thanks in advance

Ps : I found something interesting in OpenGLES 2, that every command which seems not exist from OpenGL like glTranslate and so on was being overwritten as esTranslate, esPerspective and so on. Is it obvious?
Posted 24-Apr-12 17:42pm
Amar Tivari 25-Apr-12 2:17am
Which application you are trying to write is it android application,Iphone app etc.
satrio_budidharmawan 27-Apr-12 2:35am
Oh it's android.
But i've solved it

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Implements this
    public boolean onKeyDown(int keyCode, KeyEvent msg) {
        if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
            renderer.mY -= 1;
            return (true);
        if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
            renderer.mY += 1;
            return (true);
        if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
            renderer.mX -= 1;
            return (true);
        if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
			renderer.mX += 1;
            return (true);
        return true;

and this
public void onDrawFrame(GL10 gl) 
    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	//gl.glTranslatef(0, 0, -3.0f);
	gl.glTranslatef(mX, 0, -3.0f);
	gl.glTranslatef(0, mY, -3.0f);
	gl.glRotatef(mAngleX, 0, 1, 0);
	gl.glRotatef(mAngleY, 1, 0, 0);
    drawTriangle(gl, 160.0f, 100.0f, 110.0f, 200.0f, 210.0f, 200.0f, 1.0f, 1.0f, 1.0f);
    drawTriangle(gl, 110.0f, 200.0f, 60.0f, 300.0f, 160.0f, 300.0f, 1.0f, 1.0f, 1.0f);
    drawTriangle(gl, 210.0f, 200.0f, 160.0f, 300.0f, 260.0f, 300.0f, 1.0f, 1.0f, 1.0f);

It works. And should be works!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 27 Apr 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100