Problem with multiple viewports

Started by amoeba, August 11, 2004, 14:22:58

Previous topic - Next topic

amoeba

I am writing a little program which will have the main 3d game area in the top left, and the score+message box on the right hand side and bottom of the screen.

So I create a viewport, draw the 3d, but when doing my gui bits the text placement is screwed up. Is this pseudo code correct?

public								int 		VIEWPORT_X				= 75;
	public								int 		VIEWPORT_Y				= 150;
	public								int 		VIEWPORT_WIDTH		= 650;
	public								int 		VIEWPORT_HEIGHT		= 450;
	public								int 		SCREEN_WIDTH			= 800;
	public								int 		SCREEN_HEIGHT			= 600;
	public								int 		SCREEN_BPP				= 32;

  public void glPrint(int x, int y, int set, String msg)
  {
    int offset = base - 32 + (128 * set);

    GL11.glEnable(GL11.GL_TEXTURE_2D);                          // Enable Texture Mapping
    GL11.glLoadIdentity();                                      // Reset The Modelview Matrix
    GL11.glTranslatef(x, y, 0);                                 // Position The Text (0,0 - Bottom Left)
    if(msg != null)
    {
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textures[0]);

        for(int i=0;i<msg.length();i++)
        {
            GL11.glCallList(offset + msg.charAt(i));
            GL11.glTranslatef(0.05f, 0.0f, 0.0f);
        }
    }
  }


		GL11.glMatrixMode(GL11.GL_MODELVIEW);
		GL11.glLoadIdentity();
		GLU.gluPerspective( 45.0f,VIEWPORT_WIDTH/VIEWPORT_HEIGHT,0.1f,100 );
		GL11.glViewport(VIEWPORT_X, VIEWPORT_Y, VIEWPORT_WIDTH, VIEWPORT_HEIGHT);

		//clear background
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

		GL11.glLoadIdentity(); // reset the matrix

                   -- draw 3d
                   -- glprint works here

		GL11.glMatrixMode(GL11.GL_MODELVIEW);
		GL11.glLoadIdentity();
		GLU.gluPerspective( 45.0f, SCREEN_WIDTH/SCREEN_HEIGHT,0.1f,100 );
		GL11.glViewport( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
		GL11.glLoadIdentity(); // reset the matrix

                  -- draw 2d gui stuff
                  -- glprint does not position correctly here

amoeba

Problem fixed by adding

      // set projection matrix
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
      GLU.gluOrtho2D(0, VIEWPORT_WIDTH, 0, VIEWPORT_HEIGHT);

      // set projection matrix
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
      GLU.gluOrtho2D( 0, SCREEN_WIDTH, 0, SCREEN_HEIGHT);

before the 2 viewports.

Thanks!