Results 1 to 3 of 3

Thread: A llitle scaling with texturewm question : ROMBUST ROMBUST ROMBUST !

  1. #1

    Default A llitle scaling with texturewm question : ROMBUST ROMBUST ROMBUST !

    Hi everyone !

    To be able to adapt my application to different user's screen resolution, I choose at start between 4 working buffers (with fixed resolution and different ratios). I scale them before drawing in the render loop of the main window according to the working buffer / user resolution ratio. But I have A CL_Window declared on top of my main window: CL_GUIComponent. And this CL_Window does not scale its components (as they are not drawn during the on_render() function i hooked i guess)

    This is roughly how I do :
    Code:
     
          //app.cpp : declaration of both windows
          ...
          CL_GUIWindowManagerTexture win_manager_texture(display_window);
          gui_manager.set_window_manager ( win_manager_texture );
    
          GameWindow game_window(resolution, &gui_manager, ...);
          Chatbox chatbox(resolution, &game_window, ...); // GameWindow is the "desktop" that the toolbar sits on, as an owner
    
          gui_manager.exec();
          ...
    
    
    
          // GameWindow.cpp : main window doing the scaling
          GameWindow::GameWindow(...): CL_GUIComponent(gui_manager, CL_GUITopLevelDescription (CL_Rect(0,0,resolution)
          {
                  set_constant_repaint(true);
                  func_render().set(this, &GameWindow::on_render);
          ....
          }
    
    
         //render loop hooked
          void GameWindow::on_render(CL_GraphicContext &gc, const CL_Rect &clip_rect)
          {
          //Save previous scale matrix and set identity matrix, to render on the working buffer
          CL_Mat4f scale = gc.get_modelview();
          gc.set_modelview(  CL_Mat4f::identity() );
    
          /* Draw stuff ... */
    
          //Pops back scale matrix to rendering matrix (to scale the working buffer)
          gc.set_modelview( scale );
          }
    
    
    
    
          //Chatbox : window drawn on top of the main, not scaled ad I would like to
          Chatbox::Chatbox (...): CL_Window(...)
          {       
          //Stuff like pushbuttons, lineedit ...
          }
    Apparently calling window's drawing in on_render while the viewport is set is not the way to go, and "<qsr|Judas> the cleanest way is to apply the scale only once, when the texturewm renders the windows".
    But I am deeply unsure how to do and was told to ask Rombust, so: I INVOKE YOU ROMBUST ! APPEAR AND SOLVE ALL MY TROUBLES NOW I COMMAND YOU (please ) !

    ROMBUST ROMBUST ROMBUST !

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    It's not the simple and you should not use gui.exec() in this instance.

    See Examples/GUI3D... although a lot more complex for what you need, you should be able to simplify it.

    It uses: wm.process(); .... To process window messages
    It uses: wm.func_input_intercept().set(this, &class::wm_input_intercept); ... To reinterpret mouse messages
    It uses: wm.get_windows(); ... To obtain and draw the windows

    Instead of using wm.get_windows(), since you are not using 3D. Use wm.draw_windows(gc); instead.

    Set/Restore the scale matrix around the wm.draw_windows(gc).

    Remember to adjust the wm_input_intercept with the same scale.

    (See http://clanlib.org/wiki/ClanLib_2.2.4_Release_Notes "clanGUI" for another explanation)

    (Remember, you need CL_KeepAlive:rocess() in the main loop)

  3. #3

    Default

    Ok, I took a look at Examples/GUI3D and release notes example. I quickly removed the scaling from GameWindow's on_render() and changed my app.cpp to make it like that :

    Code:
    CL_DisplayWindow display_window(windesc);
    CL_GraphicContext gc = display_window.get_gc();
    
    //Screen resolution calculation
    if ( (float)gc.get_size().width / (float)gc.get_size().height < 1.3 )		//	5/4
    	resolution = CL_Size(1280, 1024);
    else if ( (float)gc.get_size().width / (float)gc.get_size().height < 1.4 )	//	4/3
    	resolution = CL_Size(1280, 960);
    else if ( (float)gc.get_size().width / (float)gc.get_size().height < 1.7 )	//	16/10
    	resolution = CL_Size(1440, 900);
    else
    	resolution = CL_Size(1440, 810);							//	16/9
    
    CL_Mat4f scale_matrix = CL_Mat4f::scale( (float) gc.get_width() / (float) resolution.width , (float) gc.get_height() / (float) resolution.height, 1.0f);
    gc.set_modelview( scale_matrix );
    
    /*...*/
    
    CL_GUIWindowManagerTexture win_manager_texture(display_window);
    gui_manager.set_window_manager ( win_manager_texture );
    
    GameWindow game_window(resolution, &gui_manager, networkclient, event_dispatcher);
    
    Chatbox chatbox(resolution, &game_window, networkclient);	// GameWindow is the "desktop" that the toolbar sits on, as an owner
    
    while (!quit)
    {
    win_manager_texture.process();
    
    //Save previous scale matrix and set identity matrix, to render on the working buffer
    CL_Mat4f scale = gc.get_modelview();
    gc.set_modelview(  CL_Mat4f::identity() );
    
    win_manager_texture.draw_windows(gc);
    
    //Pops back scale matrix to rendering matrix (to scale the working buffer)
    gc.set_modelview( scale );
    		 
    display_window.flip(1);
    CL_KeepAlive::process();
    }
    Still, GameWindows is scaled right, and Chatbox is not scaled.
    What do I do wrong ?

    Edit: I added to the code how I first set the modelview.

    What I intended to do is have a working buffer on which I draw my stuff. I can choose between 4 resolution to display on 4 different aspect ratios. So that would make it like that :

    1 Get users resolution and aspect ratio, choose buffer size accordingly.
    2 Calculate scale to transform my buffer resolution into users screen resolution.
    3 Set modelview with this scale.
    4 Unset modelview.
    5 Draw my sprites on buffer without scaling.
    6 Set scaling modelview again.
    7 Draw buffer on screen.

    And loop 4 to 7.
    Last edited by Pierro; 12-15-2010 at 05:59 PM.

Similar Threads

  1. Menu auto-scaling
    By BigBMan in forum Proton SDK
    Replies: 13
    Last Post: 02-07-2011, 02:10 AM
  2. Possible Bug? Scaling and clipped frames.
    By catch22 in forum Official ClanLib SDK Forums
    Replies: 14
    Last Post: 06-11-2009, 12:25 PM
  3. Scaling when some tile of parallaxed background selected.
    By Rrrichi in forum Novashell Game Creation System
    Replies: 4
    Last Post: 06-13-2007, 03:11 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •