Image offset problem

I am having a problem drawing an image. When I draw the image at raster position (0,0) the final screen display is ok. When I draw the image at raster position (0,10) I can seen on the screen that the image is 14 pixels above the origin. Setting (0,20) draws 29 pixels above and setting raster position (0,30) draws at 43 pixels above the offset. This all suggests a scaling factor is being used (about 1.4).

This is (part of) my code:


public class Renderer implements GLEventListener {
  private int pixelWidth,pixelHeight;
  private byte[] pixels;
    
  ...

  public void display(GLDrawable drawable) {
        GL gl = drawable.getGL();
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
        gl.glRasterPos2i(0,30);
        gl.glDrawPixels(pixelWidth, pixelHeight-30, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixels);
  }

  public void init(GLDrawable drawable) {
  }

  public void reshape(GLDrawable drawable, int x, int y, int width, int height) {
        GL gl = drawable.getGL();
        GLU glu = drawable.getGLU();
        gl.glViewport(0, 0, height, width);
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluOrtho2D(0.0, width, 0.0, height);
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();
  }

  public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {
  }
}

What am I missing here? ???

OpenGL coordinates DO NOT have to map directly to screen.There are transformations applied to them.These are described in detail in the RedBook.If you don’t fear the math , just print the matrixes , do the calculations by hand and compare.That would be my suggestion.

Ivan Yosifov.

Your code seems fine expect the width and height are in wrong order in glViewport call :slight_smile:

Cheers