AWTGLCanvas scroll not work ??

Started by chin, June 23, 2008, 09:35:41

Previous topic - Next topic

chin

Hi
First, I'm glad to know lwjgl.
I'm using lwjgol on MacOsX platform and i draw a big image on AWTGLCanvas.
(imagefile is http://cfs4.tistory.com/upload_control/download.blog?fhandle=YmxvZzEyODI1MEBmczQudGlzdG9yeS5jb206L2F0dGFjaC8wLzA0MDAwMDAwMDAxOS5qcGc=
1920x1200 pixels)

It has a problem just only on MacOSX (not problem on Windows)
scrolling not work... what's wrong?  :'(
???



-------- code -----------
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.event.*;
import java.awt.geom.AffineTransform;
import java.awt.image.*;
import java.nio.ByteBuffer;


import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.glu.*;
//import org.lwjgl.util.glu.GLU;

//import javax.swing.JFrame;

public class scrollTest extends Frame {

   public scrollTest() {
      init();
   }
   ScrollPane sp;
   private ImageCanvas canvas;
   private Panel body = new Panel();

   public void init() {

      try {
         canvas = new ImageCanvas();
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      
      this.setTitle("scrollTest");
      this.setResizable(true);

      this.setSize(1500, 1300);

      sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
      sp.add(canvas, BorderLayout.CENTER);
      sp.setVisible(true);
      
      // sp.setWheelScrollingEnabled(false);
      // add(new ImageCanvas());
      body.setLayout(new BorderLayout());
      body.add(sp, BorderLayout.CENTER);
      
      
      this.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            
             System.exit(0);
          }
      });

      this.add(body);
      this.show();
   }

   /**
    * @param args
    */
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      new scrollTest();
   }

   class ImageCanvas extends AWTGLCanvas  {
        byte[] dukeRGBA;
          int dukeHeight;
          int dukeWidth;
      
          public void paintGL() {
             
            GL11.glViewport(0, 0, 1500, 1300);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluOrtho2D(0.0f, 450.0f, 0.0f, 375.0f);         
            
            
            GL11.glDisable(GL11.GL_ALPHA_TEST);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glDisable(GL11.GL_DEPTH_TEST);
            GL11.glDisable(GL11.GL_DITHER);
            GL11.glDisable(GL11.GL_FOG);
            GL11.glDisable(GL11.GL_LIGHTING);
            GL11.glDisable(GL11.GL_LOGIC_OP);
            GL11.glDisable(GL11.GL_STENCIL_TEST);
            GL11.glDisable(GL11.GL_TEXTURE_1D);
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glPixelTransferi(GL11.GL_MAP_COLOR, GL11.GL_FALSE);
            GL11.glPixelTransferi(GL11.GL_RED_SCALE, 1);
            GL11.glPixelTransferi(GL11.GL_RED_BIAS, 0);
            GL11.glPixelTransferi(GL11.GL_GREEN_SCALE, 1);
            GL11.glPixelTransferi(GL11.GL_GREEN_BIAS, 0);
            GL11.glPixelTransferi(GL11.GL_BLUE_SCALE, 1);
            GL11.glPixelTransferi(GL11.GL_BLUE_BIAS, 0);
            GL11.glPixelTransferi(GL11.GL_ALPHA_SCALE, 1);
            GL11.glPixelTransferi(GL11.GL_ALPHA_BIAS, 0);
            
            
             drawImage();
             
             try {
               swapBuffers();
               if (isVisible()) {
                  // Thread.yield(); // Helps input responsiveness on linux
                  repaint();
               }
            } catch (Exception e) {/*OK*/
            }
            
          }
         

       protected void drawImage () {

           if (dukeRGBA == null)
               loadDukeRGBA();
          
           ByteBuffer byBuf = ByteBuffer.wrap(dukeRGBA);
          
           GL11.glDrawPixels (dukeWidth, dukeHeight, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, byBuf);

          
       }
      
      
       protected void loadDukeRGBA () {
           Image i = Toolkit.getDefaultToolkit().createImage ("/Users/rsupport/Pictures/download.blog.jpeg");
           MediaTracker tracker = new MediaTracker(new Canvas());
           tracker.addImage (i, 0);
           try {
               tracker.waitForAll();
           } catch (InterruptedException ie) {}
           dukeHeight = i.getHeight(null);
           dukeWidth = i.getWidth(null);
          
           // turn it into a BufferedImage
           WritableRaster raster =
               Raster.createInterleavedRaster (DataBuffer.TYPE_BYTE,
                                               dukeWidth,
                                               dukeHeight,
                                               4,
                                               null);
           ComponentColorModel colorModel=
               new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,8},
                                        true,
                                        false,
                                        ComponentColorModel.TRANSLUCENT,
                                        DataBuffer.TYPE_BYTE);           
           BufferedImage dukeImg =
               new BufferedImage (colorModel, // color model
                                  raster,
                                  false, // isRasterPremultiplied
                                  null); // properties                               
           Graphics2D g = dukeImg.createGraphics();
           // use an AffineTransformation to draw upside-down in the java
           // sense, which will make it right-side-up in OpenGL
           AffineTransform gt = new AffineTransform();
           gt.translate (0, dukeHeight);
           gt.scale (1, -1d);
           g.transform (gt);
           g.drawImage (i, null, null);
           // now retrieve the underlying byte array from dukeImg
           DataBufferByte dukeBuf = (DataBufferByte)raster.getDataBuffer();
           dukeRGBA = dukeBuf.getData();
           g.dispose();
          
           this.setSize(i.getWidth(this), i.getHeight(this));
       }
      

      
      private Image image = null;

      public ImageCanvas() throws Exception {
      }   
   }
}


Evil-Devil

You have to scroll the image yourself with glTranslate. Not the GLCanvas!
That should do it ;)

BTW: 1920x1200 is no valid 2^n texture size ;)