Slick Forums

Discuss the Slick 2D Library
It is currently Sun Dec 17, 2017 6:19 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Sep 01, 2014 1:08 pm 
Offline

Joined: Fri Mar 25, 2011 5:30 am
Posts: 8
Hi Forum
Im using scalegame to scale my game to any resoultion . But for some reason the clipping boxing are not in there correct position
Gone <a href="http://slick.ninjacave.com/forum/viewtopic.php?f=18&t=4717">here</a> and tried the setViewPort code there didnt really work.

but what did help was pausing the renderer though it only works for 2 of the 3 button on my main menu. looked at the source code for LWJGLRenderer, so i was wondering do i have to override this method setupGLState() for the menu to put the clipping boxes of my btn in the appropriate place. Does this mean i will have to learn OpenGL if i override this method i was hoping to avoid learning it.

any help will be much appreciated and thank you in advance.

Here my code
Code for GameMenuState
Code:
public class GameMenuState extends BasicTWLGameState
{
    private final int id = 1;
   
    private Button btn;
    private Button btn2;
    private Button btn3;
    private GameMenu gmGameMenuState;
   
    private StateBasedGame theStateBasedGame;

   @Override
    protected RootPane createRootPane()
    {
        RootPane rp = super.createRootPane();
        rp.setTheme("simplegamemenu");

        //createMenuButton();
       
        setGmGameMenuState(new GameMenu(getTheStateBasedGame()));
        getGmGameMenuState().setTheme("simplegamemenu");

        /*rp.add(getBtn());
        rp.add(getBtn2());
        rp.add(getBtn3());*/
        rp.add(getGmGameMenuState());
       
       
        return rp;
    }

   

   @Override
    protected void layoutRootPane() {
       
      getGmGameMenuState().adjustSize();
      
       //LWJGLRenderer renderer = (LWJGLRenderer) getGmGameMenuState().getRootWidget().getGUI().getRenderer();
      
      LWJGLRenderer renderer = (LWJGLRenderer) getRootPane().getGUI().getRenderer();
      // renderer.endRendering();
      
      renderer.pauseRendering();
       //renderer.endRendering();
    
      renderer.setViewport(0, 0, Display.getWidth(), Display.getHeight());
   
      renderer.syncViewportSize();
    //   renderer.setViewport(1368, 768, 1368,768 );
      // getRootPane().adjustSize();
     //  getGmGameMenuState().adjustSize();
     //  renderer.startRendering();
      
      
      
    
    }
   
   
    @Override
   public void init(GameContainer gc, StateBasedGame sb)
         throws SlickException {
       
       setTheStateBasedGame(sb);
       
       
   }

   @Override
   public void render(GameContainer gc, StateBasedGame sb, Graphics gr)
         throws SlickException {
      
      gr.drawString("In Game Menu", 500, 600);
      
      
      
   }

   @Override
   public void update(GameContainer gc, StateBasedGame sb, int delta)
         throws SlickException {
      
         }

   @Override
   public int getID() {
      
      return id;
   }
   
   

   /**
    * gets btn2
    * @return
    */
   private Button getBtn2()
   {
      return this.btn2;
   }

   
   /**
    * sets btn2
    * @param btn2
    */
   private void setBtn2(Button btn2)
   {
      this.btn2 = btn2;
   }
   
   /**
    * gets btn
    * @return
    */
    private Button getBtn()
    {
      return this.btn;
   }

    /**
     * sets btn
     * @param btn
     */
   private void setBtn(Button btn)
   {
      this.btn = btn;
   }

   /**
    * gets btn3
    * @return
    */
   private Button getBtn3()
   {
      return this.btn3;
   }

   /**
    * set btn3
    * @param btn3
    */
   private void setBtn3(Button btn3)
   {
      this.btn3 = btn3;
   }

   private StateBasedGame getTheStateBasedGame() {
      return this.theStateBasedGame;
   }

   private void setTheStateBasedGame(StateBasedGame theStateBasedGame) {
      this.theStateBasedGame = theStateBasedGame;
   }



   public GameMenu getGmGameMenuState() {
      return gmGameMenuState;
   }



   public void setGmGameMenuState(GameMenu gmGameMenuState) {
      this.gmGameMenuState = gmGameMenuState;
   }

   
   
   
   
   
}

Code for the GameMenu Widget
Code:
public class GameMenu extends Widget
{
   private Button [] buttons;
   
   private StateBasedGame sb;
   
   private boolean quit;
   
   /**
    *
    */
   public GameMenu(StateBasedGame sb)
   {
         setSb(sb);
          buttons = new Button[GameFields.GAME_MENU_ARRAY_SIZE];
      
      
         buttons[0] = new Button("Start Game");
         buttons[1] = new Button("Options");
         buttons[2] = new Button("Quit");
      
         for (int i = 0; i < buttons.length; ++i)
         {
            buttons[i].setTheme("button");
            add(buttons[i]);
         }
         
         setCallBacks();
         
         
         
   }
   
   
   
    private static final int TITLE_HEIGHT = 200;
       private static final int BUTTON_WIDTH = 300;
       private static final int BUTTON_HEIGHT = 50;
      
    @Override
   protected void layout() {
      int centerX = getInnerX() + getInnerWidth() / 2 ;
       //int centerX = 500;
      int distY = ((getInnerHeight() - TITLE_HEIGHT) / (buttons.length + 1));
      
      for (int i = 0; i < buttons.length; i++)
      {
         buttons[i].setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
         
         
         
         //System.out.printf("center x val : [%d] distY val [%d]\n"
            //   , centerX
               //, distY);
         
          buttons[i].setPosition(centerX - BUTTON_WIDTH /2,
                TITLE_HEIGHT + (i+1) * distY -BUTTON_HEIGHT/2);
      }   
      
      
      
      
      
   }
   
    private void setCallBacks()
    {
       for (int i = 0; i < buttons.length; i++)
         {
          if(i == 0){
            buttons[i].addCallback(new Runnable() {
               
               @Override
               public void run() {
                  System.out.printf("Start Game Work\n");
                  
                  //getSb().enterState(2);
                  System.out.printf("start game buttong x val [%d] y val [%d]\n",buttons[0].getX(),buttons[0].getY());
               }
            });
         }
          else if(i == 1)
          {
             buttons[i].addCallback(new Runnable() {
                  
                @Override
                  public void run() {
                     // TODO Auto-generated method stub
                     System.out.printf("Options work\n");
                     System.out.printf("options button x val [%d] y val [%d]\n",buttons[1].getX(),buttons[1].getY());
                     //getSb().enterState(4);
                  }
               });
          }
          else if(i == 2)
          {
             buttons[i].addCallback(new Runnable() {
                  
                  @Override
                  public void run() {
                     System.out.printf("Exit works \n");
                     System.out.printf("exit button x val [%d] y val [%d]\n",buttons[2].getX(),buttons[2].getY());
                  //   System.exit(0);
                  }
               });
          }
         }
      
    }

   public StateBasedGame getSb() {
      return sb;
   }

   public void setSb(StateBasedGame sb) {
      this.sb = sb;
   }


   
      
}



Top
 Profile  
 
PostPosted: Mon Sep 15, 2014 1:03 pm 
Offline

Joined: Fri Mar 25, 2011 5:30 am
Posts: 8
Update
The file ive attached details the problem im having
. As you can see on the image the click boxes do not line up with the images the a way off.

here 's my attempt at creating my own custom LWJGLRenderer class.

Code:
public class CustomLWJGLRenderer extends LWJGLRenderer
{
   
   public CustomLWJGLRenderer() throws LWJGLException
   {
      super();
   }
   
   @Override
   protected void setupGLState() {
      // TODO Auto-generated method stub
   //   super.setupGLState();
   //   revertGLState();
      //setViewport(0, 0, Display.getWidth(), Display.getHeight());
      GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_TRANSFORM_BIT
            | GL11.GL_HINT_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_SCISSOR_BIT
            | GL11.GL_LINE_BIT | GL11.GL_TEXTURE_BIT);
      
      //GL11.glPushAttrib( GL11.GL_LINE_BIT | GL11.GL_SCISSOR_BIT  );
      
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glPushMatrix();
      GL11.glLoadIdentity();
      System.out.printf("in setup gl state\n");
      System.out.printf("width [%d] height [%d]\n",Display.getWidth(),Display.getHeight());
      
      
   
        GL11.glOrtho(0, Display.getWidth(), Display.getHeight() , 0, -1.0, 1.0);
      
   
      
      
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      //GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glPushMatrix();
      GL11.glLoadIdentity();
      
      //GL11.glPopMatrix();
      
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glEnable(GL11.GL_BLEND);
      GL11.glEnable(GL11.GL_LINE_SMOOTH);
      
      GL11.glDisable(GL11.GL_DEPTH_TEST);
      GL11.glDisable(GL11.GL_LIGHTING);
      GL11.glDisable(GL11.GL_SCISSOR_TEST);
      GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
      GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
      
      
      
   }
   
   
   
   

}


does any one have any answers?


Attachments:
File comment: picture of bug
gameresobug2.jpg
gameresobug2.jpg [ 86.39 KiB | Viewed 3326 times ]
Top
 Profile  
 
PostPosted: Mon Sep 22, 2014 9:17 pm 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 290
Hi,

I've seen this before and it seems to happen if the resolution is changed during use. I have resorted to forcing a restart on the changing of resolution in my game since it was completely messing up buttons/gfx, even after calling the sync viewport.

Maybe try calling sync viewport?

Edit: I see you're already doing that.

Don't know of anything else to try ATM.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group