Skip to content

Commit

Permalink
IPHONE: Clean up mouse texture coordinate handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Schickel committed Feb 24, 2012
1 parent d93e155 commit d691ef2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 2 additions & 0 deletions backends/platform/iphone/iphone_video.h
Expand Up @@ -60,6 +60,8 @@
GLfloat _overlayTexCoords[4 * 2];
CGRect _overlayRect;

GLfloat _mouseTexCoords[4 * 2];

int _scaledShakeOffsetY;
}

Expand Down
24 changes: 9 additions & 15 deletions backends/platform/iphone/iphone_video.mm
Expand Up @@ -217,6 +217,11 @@ - (id)initWithFrame:(struct CGRect)frame {
_overlayTexCoords[4] = _overlayTexCoords[5] =
_overlayTexCoords[6] = _overlayTexCoords[7] = 0;

_mouseTexCoords[0] = _mouseTexCoords[1] =
_mouseTexCoords[2] = _mouseTexCoords[3] =
_mouseTexCoords[4] = _mouseTexCoords[5] =
_mouseTexCoords[6] = _mouseTexCoords[7] = 0;

// Initialize the OpenGL ES context
[self createContext];

Expand Down Expand Up @@ -305,6 +310,9 @@ - (void)updateMouseCursor {
[self setFilterModeForTexture:_mouseCursorTexture];
}

_mouseTexCoords[2] = _mouseTexCoords[6] = _videoContext.mouseWidth / (GLfloat)_videoContext.mouseTexture.w;
_mouseTexCoords[5] = _mouseTexCoords[7] = _videoContext.mouseHeight / (GLfloat)_videoContext.mouseTexture.h;

glBindTexture(GL_TEXTURE_2D, _mouseCursorTexture); printOpenGLError();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _videoContext.mouseTexture.w, _videoContext.mouseTexture.h, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, _videoContext.mouseTexture.pixels); printOpenGLError();
}
Expand Down Expand Up @@ -383,22 +391,8 @@ - (void)updateMouseSurface {

//printf("Cursor: width %u height %u\n", _videoContext.mouseWidth, _videoContext.mouseHeight);

float texWidth = _videoContext.mouseWidth / (float)_videoContext.mouseTexture.w;
float texHeight = _videoContext.mouseHeight / (float)_videoContext.mouseTexture.h;

const GLfloat texCoords[] = {
// Top left
0 , 0,
// Top right
texWidth, 0,
// Bottom left
0 , texHeight,
// Bottom right
texWidth, texHeight
};

glVertexPointer(2, GL_FLOAT, 0, vertices); printOpenGLError();
glTexCoordPointer(2, GL_FLOAT, 0, texCoords); printOpenGLError();
glTexCoordPointer(2, GL_FLOAT, 0, _mouseTexCoords); printOpenGLError();

glBindTexture(GL_TEXTURE_2D, _mouseCursorTexture); printOpenGLError();
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); printOpenGLError();
Expand Down

0 comments on commit d691ef2

Please sign in to comment.