2003/09/19 05:26:47
[org.ibex.core.git] / src / org / xwt / plat / OpenGL.cc
index e307b45..c7a1002 100644 (file)
@@ -4,7 +4,7 @@
 // IMPROVMENT: use alpha testing? might be faster
 
 #include <org/xwt/plat/OpenGL.h>
-#include <org/xwt/plat/OpenGL$GLDoubleBuffer.h>
+#include <org/xwt/plat/OpenGL$GLPixelBuffer.h>
 #include <org/xwt/plat/OpenGL$GLPicture.h>
 #include <org/xwt/plat/OpenGL$RectGLPicture.h>
 #include <org/xwt/plat/OpenGL$SquareGLPicture.h>
@@ -56,7 +56,7 @@ void OpenGL::natInit() {
     version = JvNewStringLatin1(s==0 ? "" : (char*)s);
 }
 
-void OpenGL$GLDoubleBuffer::drawableInit(jint width, jint height) {
+void OpenGL$GLPixelBuffer::drawableInit(jint width, jint height) {
     glClearColor (0.3f, 0.7f, 1.0f, 1.0f);
     glClearDepth( 0.0f );
     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
@@ -77,7 +77,7 @@ void OpenGL$GLDoubleBuffer::drawableInit(jint width, jint height) {
     checkGLError();
 }
 
-void OpenGL$GLDoubleBuffer::setColor(jint argb) {
+void OpenGL$GLPixelBuffer::setColor(jint argb) {
     float alpha = ((argb >> 24) & 0xff) / 255.0;
     float red   = ((argb >> 16) & 0xff) / 255.0;
     float green = ((argb >>  8) & 0xff) / 255.0;
@@ -85,7 +85,7 @@ void OpenGL$GLDoubleBuffer::setColor(jint argb) {
     glColor4f(red,green,blue,alpha);
 }
 
-void OpenGL$GLDoubleBuffer::fillTrapezoid(jint x1, jint x2, jint y1, jint x3, jint x4, jint y2, jint color) {
+void OpenGL$GLPixelBuffer::fillTrapezoid(jint x1, jint x2, jint y1, jint x3, jint x4, jint y2, jint color) {
     activateContext();
     setColor(color);
     glBegin(GL_QUADS); 
@@ -96,7 +96,7 @@ void OpenGL$GLDoubleBuffer::fillTrapezoid(jint x1, jint x2, jint y1, jint x3, ji
     glEnd();
 }
 
-void OpenGL$GLDoubleBuffer::fillRect(jint x1, jint y1, jint x2, jint y2,jint color) {
+void OpenGL$GLPixelBuffer::fillRect(jint x1, jint y1, jint x2, jint y2,jint color) {
     activateContext();
     setColor(color);
     glBegin(GL_QUADS); 
@@ -107,7 +107,7 @@ void OpenGL$GLDoubleBuffer::fillRect(jint x1, jint y1, jint x2, jint y2,jint col
     glEnd();
 }
 
-void OpenGL$GLDoubleBuffer::setClip(jint x1, jint y1, jint x2, jint y2) {
+void OpenGL$GLPixelBuffer::setClip(jint x1, jint y1, jint x2, jint y2) {
     //fprintf(stderr,"setClip: %d %d %d %d\n",x1,y1,x2,y2);
     if(x1==0 && y1==0 && x2==width && y2==height) {
         if(glScissorEnabled) {
@@ -129,7 +129,7 @@ void OpenGL$GLDoubleBuffer::setClip(jint x1, jint y1, jint x2, jint y2) {
     checkGLError();
 }
 
-void OpenGL$GLDoubleBuffer::resetClip() {
+void OpenGL$GLPixelBuffer::resetClip() {
     activateContext();
     if(glScissorEnabled) {
         glDisable(GL_SCISSOR_TEST);
@@ -177,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 (gl->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);
@@ -189,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_) {