X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FOpenGL.cc;h=3c8cf6ad73369948d141fa4a302e4238de40a998;hb=de378041d5ca2aca1a2b5a31ef15ae90a86c977f;hp=93b1b4f694f5ce36d33bd1e8f5dd4e48dab6c248;hpb=e022c4c066655b34453013d75e020f40c36d8926;p=org.ibex.core.git diff --git a/src/org/xwt/plat/OpenGL.cc b/src/org/xwt/plat/OpenGL.cc index 93b1b4f..3c8cf6a 100644 --- a/src/org/xwt/plat/OpenGL.cc +++ b/src/org/xwt/plat/OpenGL.cc @@ -25,6 +25,9 @@ #include +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) + namespace org { namespace xwt { namespace plat { #define checkGLError() checkGLError2(__FILE__,__LINE__) @@ -177,6 +180,11 @@ void OpenGL$RectGLPicture::natInit(Object *data_, jboolean alphaOnly) { } void OpenGL$RectGLPicture::draw(jint dx, jint dy, jint cx1, jint cy1, jint cx2, jint cy2) { + cx1 = max(dx, cx1); + cy1 = max(dy, cy1); + cx2 = min(cx2, dx + width); + cy2 = min(cy2, dy + height); + if (cy2 <= cy1 || cx2 <= cx1) return; glEnable(GL_TEXTURE_RECTANGLE_EXT); glBindTexture(GL_TEXTURE_RECTANGLE_EXT, textureName); glBegin(GL_QUADS); { @@ -268,17 +276,26 @@ void OpenGL$SquareGLPicture::natInit(Object *data_, jboolean alphaOnly) { } void OpenGL$SquareGLPicture::draw(jint dx, jint dy, jint cx1, jint cy1, jint cx2, jint cy2) { + cx1 = max(dx, cx1); + cy1 = max(dy, cy1); + cx2 = min(cx2, dx + width); + cy2 = min(cy2, dy + height); + if (cy2 <= cy1 || cx2 <= cx1) return; + float tx1 = (float) (cx1 - dx) / (float) texWidth; + float ty1 = (float) (cy1 - dy) / (float) texHeight; + float tx2 = (float) (cx2 - dx) / (float) texWidth; + float ty2 = (float) (cy2 - dy) / (float) texHeight; glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, textureName); checkGLError(); glBegin(GL_QUADS); { - glTexCoord2f (cx1 - dx, cy1 - dy ); + glTexCoord2f (tx1, ty1 ); glVertex3i (cx1, cy1, 0); - glTexCoord2f (cx2 - dx, cy1 - dy ); + glTexCoord2f (tx2, ty1 ); glVertex3i (cx2, cy1, 0); - glTexCoord2f (cx2 - dx, cy2 - dy ); + glTexCoord2f (tx2, ty2 ); glVertex3i (cx2, cy2, 0); - glTexCoord2f (cx1 - dx, cy2 - dy ); + glTexCoord2f (tx1, ty2 ); glVertex3i (cx1, cy2, 0); } glEnd(); glDisable(GL_TEXTURE_2D);