0

I am having a bit of a problem I have noticed within the first 10 mins of working with OpenGLES that really the function calls are mostly the same however how you set up your methods is completely different.

I understand the basics of animating a polygon in OpenGL. The idea of changing the modelmatrix and then re-drawing the scene and using double buffering to cut down on the lag that you see when moving things quickly or updating things quickly and alot.

So here my question. How would I accomplish the same. In OpenGl in C or C++ I could have my own method that calls the display() function that will re-draw the scene.

I have looked around and had to re-learn how to draw a simple polygon. I assume that it is completely different. I have looked around on here and I have found some tutorials for things but nothing seems to really drive home what the methodology is behind the change. I am interested in understanding it vs copying.

Thanks

New Material:

Here is what I am trying to achieve in android. This code is in C. From my reading the way that I understand OpenGL is deprecated but I feel like I should still be able to achieve the same thing.

This code reflects that you have a listener that waits for a button to be pressed and once it is then it does the associated code and re-draws the display. This from my understanding if different in OpenGL ES.

    void main(int argc, char** argv)
    {

         /* Standard GLUT initialization */

        glutInit(&argc,argv);

        /* default, not needed */
        glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);    

        glutInitWindowSize(500,500); /* 500 x 500 pixel window */

        /* place window top left on display */
        glutInitWindowPosition(0,0);    

        glutCreateWindow("COMP-5/6400 Assignment 2"); /* window title */

        /* display callback invoked when window opened */
        glutDisplayFunc(display); 
        glutSpecialFunc (processSpecialKeys);
        myinit(); /* set attributes */

        glutMainLoop(); /* enter event loop */
    }

    void processSpecialKeys(int key, int x, int y)
    {
         switch(key){
             case GLUT_KEY_UP:
                moveUp();
            break;
            case GLUT_KEY_DOWN:
                    moveDown();
            break;
            case GLUT_KEY_LEFT:
                moveLeft();
            break;
            case GLUT_KEY_RIGHT:
                moveRight();
            break;
        }
    }

    void moveUp(){
    personX= (5.0*cosf(personRota))+personX;
    personY= (5.0*sinf(personRota))+personY;
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    display();
    }
Elliott
  • 539
  • 4
  • 14
  • You mean, there's no `glVertexXY` anymore? And -- _since you didn't mention it_ -- you've found the [`GLSurfaceView`](http://developer.android.com/reference/android/opengl/GLSurfaceView.html)? – Stefan Hanke Apr 06 '12 at 05:19
  • Ya they did away with glVertexXY for what reason I am not sure. From what I have read people have said that it is inefficient... its the internet so I take that with a HUGE grain of salt. I haven't looked into glsurfaceview when I get home tonight I will thanks! – Elliott Apr 06 '12 at 16:11

1 Answers1

0

Please have a look here, which nicely explains the difference between immediate mode and retained mode APIs. I didn't find something decent in the OpenGL wiki (no mention of immediate anywhere at all). Kurt Akelay and Pat Hanrahan have some good slides; search for "Interface Choices". These are to be trusted, just trust me ;)

Community
  • 1
  • 1
Stefan Hanke
  • 3,458
  • 2
  • 30
  • 34
  • I see what you mean. But my question still comes back to how do you do a re-draw. I want to be able to have a button listener and move a character across the screen. – Elliott Apr 10 '12 at 13:13
  • Hmm, this hasn't changed -- you need to `glClear` all buffers before drawing, and then draw. The `GLSurfaceView` takes care of double buffering for you. Perhaps, to eliminate misunderstandings, you could post some code? – Stefan Hanke Apr 10 '12 at 13:59
  • Stefan, Thanks I have added some code for you to see what I am trying to accomplish in OpenGL ES I have omitted the display(); function but basically I want to in android have someone be able to press a button on the screen update a sprite's location and then re-display the canvas. Thanks again – Elliott Apr 10 '12 at 16:20
  • This question gets too broad (I did expect some Java code, no C/GLUT code). Please lookup some examples of using the `GLSurfaceView` (e.g. [here using OpenGL ES 1](http://ruibm.com/?p=263)). This also demonstrates how to react on touch events. Hope that helps you get started. – Stefan Hanke Apr 10 '12 at 17:05