1

I'm working on a 2D game which uses native code to draw into a single OpenGL 2D texture. The texture is then drawn on the screen unchanged. The code works fine except when the display is rotated. The game continues to play correctly, but the texture is truncated and off-center on the screen. The game plays correctly if started in any orientation, but if the orientation is changed, the paint problem occurs. I am handling the orientation change properly so that the GL context is not destroyed and my drawing parameters for each orientation are being calculated correctly. The only thing I can think of is that I'm possibly missing some step in my handling of the onSurfaceChanged() event. Here is the native code which is called by onSurfaceChanged():

if (pTexture)
       free(pTexture);
pTexture = malloc(iTexturePitch * iTextureHeight);

rect[0] = 0;
rect[1] =  iHeight; // w,h fit within the texture size
rect[2] =  iWidth;
rect[3] = -iHeight;

glDeleteTextures(1, &s_texture);
while (*start)
   glDisable(*start++); // disable unused options
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &s_texture);
glBindTexture(GL_TEXTURE_2D, s_texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glShadeModel(GL_FLAT);
glColor4x(0x10000, 0x10000, 0x10000, 0x10000);
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, rect);

The code for displaying the texture:

    glClear(GL_COLOR_BUFFER_BIT);
    glTexImage2D(GL_TEXTURE_2D,     /* target */
        0,          /* level */
        GL_RGB,         /* internal format */
        iTextureWidth,      /* width */
        iTextureHeight,     /* height */
        0,          /* border */
        GL_RGB,         /* format */
        GL_UNSIGNED_SHORT_5_6_5,/* type */
        pTexture);      /* pixels */
    // border x/y for centering; stretched x/y is the destination size on the display
    glDrawTexiOES(iBorderX, iBorderY, 0, iStretchedWidth, iStretchedHeight);
Tim
  • 35,413
  • 11
  • 95
  • 121
BitBank
  • 8,500
  • 3
  • 28
  • 46

0 Answers0