2003/09/13 05:08:58
[org.ibex.core.git] / src / org / xwt / plat / OpenGL.cc
index f23c179..9d2a3f1 100644 (file)
@@ -161,10 +161,14 @@ void OpenGL$RectGLPicture::natInit(JArray<jint> *data_) {
     glTexImage2D(GL_TEXTURE_RECTANGLE_EXT,0,4,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,buf);
     delete buf;
 
-    glTexParameteri(GL_TEXTURE_RECTANGLE_EXT,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+    // FIXME: enable linear filtering for opengl 1.2
+    glTexParameteri(GL_TEXTURE_RECTANGLE_EXT,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
+    glTexParameteri(GL_TEXTURE_RECTANGLE_EXT,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
+    
+    /*glTexParameteri(GL_TEXTURE_RECTANGLE_EXT,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
     glTexParameteri(GL_TEXTURE_RECTANGLE_EXT,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     glTexParameterf(GL_TEXTURE_RECTANGLE_EXT,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-    glTexParameterf(GL_TEXTURE_RECTANGLE_EXT,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+    glTexParameterf(GL_TEXTURE_RECTANGLE_EXT,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);*/
 
     glDisable(GL_TEXTURE_RECTANGLE_EXT);
     checkGLError();
@@ -173,11 +177,12 @@ void OpenGL$RectGLPicture::natInit(JArray<jint> *data_) {
 }
 
 void OpenGL$RectGLPicture::draw(jint dx1, jint dy1, jint dx2, jint dy2,jint sx1, jint sy1, jint sx2, jint sy2) { 
-    glColor4f(1.0f,1.0f,1.0f,1.0f);
-    glEnable(GL_TEXTURE_RECTANGLE_EXT);
-    glBindTexture(GL_TEXTURE_RECTANGLE_EXT, textureName);    
-    glBegin(GL_QUADS); 
-        glTexCoord2i (sx1, sy1   );
+    if (hasRectangularTextures()) {
+       glColor4f(1.0f,1.0f,1.0f,1.0f);
+       glEnable(GL_TEXTURE_RECTANGLE_EXT);
+       glBindTexture(GL_TEXTURE_RECTANGLE_EXT, textureName);    
+       glBegin(GL_QUADS); 
+       glTexCoord2i (sx1, sy1   );
         glVertex3i   (dx1, dy1, 0);   
         glTexCoord2i (sx2, sy1   ); 
         glVertex3i   (dx2, dy1, 0);
@@ -185,10 +190,33 @@ void OpenGL$RectGLPicture::draw(jint dx1, jint dy1, jint dx2, jint dy2,jint sx1,
         glVertex3i   (dx2, dy2, 0);
         glTexCoord2i (sx1, sy2   );
         glVertex3i   (dx1, dy2, 0);
-    glEnd();
-    glDisable(GL_TEXTURE_RECTANGLE_EXT);
-    checkGLError();
+       glEnd();
+       glDisable(GL_TEXTURE_RECTANGLE_EXT);
+       checkGLError();
+    } else {
+        float tx1,ty1,tx2,ty2; // normalized texture coords
+        tx1 = (float) sx1 / (float) width;
+        ty1 = (float) sy1 / (float) height;
+        tx2 = (float) sx2 / (float) width;
+        ty2 = (float) sy2 / (float) height;
 
+        glColor4f(1.0f,1.0f,1.0f,1.0f);
+        glEnable(GL_TEXTURE_2D);
+        glBindTexture(GL_TEXTURE_2D, textureName);    
+        checkGLError();
+        glBegin(GL_QUADS); 
+            glTexCoord2f (tx1, ty1   );
+            glVertex3i   (dx1, dy1, 0);
+            glTexCoord2f (tx2, ty1   ); 
+            glVertex3i   (dx2, dy1, 0);
+            glTexCoord2f (tx2, ty2   ); 
+            glVertex3i   (dx2, dy2, 0);
+            glTexCoord2f (tx1, ty2   );
+            glVertex3i   (dx1, dy2, 0);
+        glEnd();
+        glDisable(GL_TEXTURE_2D);
+        checkGLError();
+    }
 }
 
 void OpenGL::natDeleteTexture(jint tex_) {
@@ -230,10 +258,12 @@ void OpenGL$SquareGLPicture::natInit(JArray<jint> *data_) {
     checkGLError();    
     delete buf;
 
-    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
+    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
+    /*glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);*/
 
     glDisable(GL_TEXTURE_2D);
     checkGLError();