2003/10/28 23:54:18
authorxwt <xwt@xwt.org>
Fri, 30 Jan 2004 07:40:20 +0000 (07:40 +0000)
committerxwt <xwt@xwt.org>
Fri, 30 Jan 2004 07:40:20 +0000 (07:40 +0000)
darcs-hash:20040130074020-3ac31-456f565e273cde4854fffddac550aab5e9e748fe.gz

src/org/xwt/plat/OpenGL.cc

index 7edc17d..14884ef 100644 (file)
@@ -25,6 +25,8 @@
 
 #include <stdio.h>
 
+#define min(a,b) (a<b?a:b) 
+
 namespace org { namespace xwt { namespace plat {
 
 #define checkGLError() checkGLError2(__FILE__,__LINE__)
@@ -177,6 +179,9 @@ void OpenGL$RectGLPicture::natInit(Object *data_, jboolean alphaOnly) {
 }
 
 void OpenGL$RectGLPicture::draw(jint dx, jint dy, jint cx1, jint cy1, jint cx2, jint cy2) { 
+    cx2 = min(cx2, dx + width);
+    cy2 = min(cx2, dy + height);
+    if (cy2 <= cy1 || cx2 <= cx1) return;
     glEnable(GL_TEXTURE_RECTANGLE_EXT);
     glBindTexture(GL_TEXTURE_RECTANGLE_EXT, textureName);    
     glBegin(GL_QUADS); {
@@ -268,17 +273,24 @@ void OpenGL$SquareGLPicture::natInit(Object *data_, jboolean alphaOnly) {
 }
 
 void OpenGL$SquareGLPicture::draw(jint dx, jint dy, jint cx1, jint cy1, jint cx2, jint cy2) {
+    cx2 = min(cx2, dx + width);
+    cy2 = min(cx2, 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); {
-        glTexCoord2i (cx1 - dx, cy1 - dy   );
+       glTexCoord2f (tx1,      ty1        );    
         glVertex3i   (cx1,      cy1,      0);
-        glTexCoord2i (cx2 - dx, cy1 - dy   );
+       glTexCoord2f (tx2,      ty1        );    
         glVertex3i   (cx2,      cy1,      0);
-        glTexCoord2i (cx2 - dx, cy2 - dy   );
+       glTexCoord2f (tx2,      ty2        );    
         glVertex3i   (cx2,      cy2,      0);
-        glTexCoord2i (cx1 - dx, cy2 - dy   );
+       glTexCoord2f (tx1,      ty2        );    
         glVertex3i   (cx1,      cy2,      0);
     } glEnd();
     glDisable(GL_TEXTURE_2D);