Results 1 to 4 of 4

Thread: Trouble porting OpenGL code to iPhone's OpenGL ES

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Posts
    3

    Trouble porting OpenGL code to iPhone's OpenGL ES

    Hi friends,
    I am new to OpenGL..

    Here, is the sample code which I am using. This code is in OpenGL. I want to convert it to OpenGL ES. glArrayElement() is not supported in OpenGL ES. Instead, it was recommended to use glDrawElements(), glDrawArrays(). I am not able to convert this. Can you please help me out to convert the code.

    glTexCoordPointer(2,GL_FLOAT,sizeof(struct texcoord),tex);
    glColorPointer(4,GL_UNSIGNED_BYTE,4,col);
    glNormalPointer(GL_FLOAT,sizeof(vector),wet->n);
    glVertexPointer(2,GL_FLOAT,sizeof(struct vertexcoord),vert);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glLockArraysEXT(0,wet->w*wet->h);
    i=0;
    for(int y=0;y<wet->h-1;y++)
    {
    glBegin(GL_TRIANGLE_STRIP);
    for(int x=0;x<wet->w;x++)
    {
    glArrayElement(i);
    glArrayElement(i+wet->w);
    i++;
    }
    glEnd();
    }
    glUnlockArraysEXT();

    And one more question is do we have any replacement for glEnable(GL_TEXTURE_RECTANGLE_EXT) in OpenGL ES.

    Thanks in advance
    Vamshi

  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: Trouble porting OpenGL code to iPhone's OpenGL ES

    You simply need to create an index array which contains the index values you pass to glArrayElement, then pass that index array as a whole to glDrawElements. Of course as long as your vertex order stays constant you need to create this index array only once. In addition, you can stitch triangle strips together with degenerate triangles in order to reduce the number of draw calls since they have some overhead.

    Code :
    // Initialize index buffer only once
    int indexCount = 2 * (wet->w + 1) * (wet->h - 1) - 2;
    GLushort* indices = new GLushort[indexCount];
    GLushort* ptr = indices;
    for (int y=0; y<wet->h-1; y++)
    {
        for(int x=0;x<wet->w;x++)
        {
            *ptr++ = y * wet->w + x;
            *ptr++ = (y+1) * wet->w + x;
        }
        if (y != wet->h - 2)
        {
            // insert degenerate triangles to stitch strips together
            *ptr++ = (y+2) * wet->w - 1;
            *ptr++ = (y+1) * wet->w;
        }
    }
     
    // in your render loop: set up client arrays, then just call
    glDrawElements(GL_TRIANGLE_STRIP, indexCount, GL_UNSIGNED_SHORT, indices);

    And one more question is do we have any replacement for glEnable(GL_TEXTURE_RECTANGLE_EXT) in OpenGL ES.
    Textures need to have power-of-two dimensions and use normalized texture coordinates. You could pad your rectangle textures to the next higher power of two and scale the texture coordinates accordingly.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Posts
    3

    Re: Trouble porting OpenGL code to iPhone's OpenGL ES

    Thanks alot. The code which you have sent is working fine. Thank you very much...

    Can you please help me out in my other question. Iam still strucked with glEnable(GL_TEXTURE_RECTANGLE_EXT).
    I am using glEnable(GL_TEXTURE_2D) instead of glEnable(GL_TEXTURE_RECTANGLE_EXT) for texture image. Iam not getting the same image. I am not able to fix this...

    The OpenGL code is:
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_RECTANGLE_EXT);
    glBindTexture(GL_TEXTURE_RECTANGLE_EXT,backtex);
    glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MO DULATE);
    glMatrixMode(GL_TEXTURE);

    I have converted the above code to OpenGL ES in this way :
    glActiveTexture(GL_TEXTURE0);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,backtex);
    glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MO DULATE);
    glMatrixMode(GL_TEXTURE);

    Note: "backtex" contains the texture image.

    Can you please help me out.

    Thanks in advance,
    Vamshi

  4. #4

    Re: Trouble porting OpenGL code to iPhone's OpenGL ES

    Thank you guys for your help and patience. Are there any basic explanations about how to port certain OpenGL 1.3 code to OpenGL ES 1.0?

Similar Threads

  1. Trouble porting OpenGL code to iPhone's OpenGL ES
    By vamshivakul in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 04-16-2009, 07:39 AM
  2. Porting OpenGL sw to OpenGL-ES, help needed - take 2
    By yipton in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 11-06-2004, 11:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •