Results 1 to 9 of 9

Thread: Changing Novashell source - Linear Filter

  1. #1
    Peasant
    Join Date
    Oct 2010
    Posts
    7

    Default Changing Novashell source - Linear Filter

    Hello everybody,

    I am changing the Novashell source code so it can use the linear filter when scaling tiles.

    I have created a checkbox in the entity/tile properties page so the user can enable the linear filter if necessary.

    I think I've changed everything correctly, but something is not working.

    In Tile.cpp - RenderTilePic(...) there is the following code

    Code:
    	rectDest.bottom = RoundNearest(rectDest.bottom, 1.0f);
    	rectDest.right = RoundNearest(rectDest.right, 1.0f);
    	rectDest.top = RoundNearest(rectDest.top, 1.0f);
    	rectDest.left = RoundNearest(rectDest.left, 1.0f);
    	
    	clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MAG_FILTER, CL_NEAREST);
    	clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MIN_FILTER, CL_NEAREST);
    
    	pSurf->set_color(pTile->GetColor());
    	pSurf->draw_subpixel(pTile->m_rectSrc, rectDest, pGC);
    I've changed it to
    Code:
    	rectDest.bottom = RoundNearest(rectDest.bottom, 1.0f);
    	rectDest.right = RoundNearest(rectDest.right, 1.0f);
    	rectDest.top = RoundNearest(rectDest.top, 1.0f);
    	rectDest.left = RoundNearest(rectDest.left, 1.0f);
    
    	if (pTile->GetBit(Tile::e_linearFilter)) // flag created for the linear filter
    	{
    		clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MAG_FILTER, CL_LINEAR);
    		clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MIN_FILTER, CL_LINEAR);
    	}
    	else
    	{
    		clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MAG_FILTER, CL_NEAREST);
    		clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MIN_FILTER, CL_NEAREST);
    	}
    	pSurf->set_color(pTile->GetColor());
    	pSurf->draw_subpixel(pTile->m_rectSrc, rectDest, pGC);
    When I check the Linear Filter checkbox the if condition is satisfied and the correct code is executed

    Code:
    		clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MAG_FILTER, CL_LINEAR);
    		clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MIN_FILTER, CL_LINEAR);
    But the filtering is not applied to the tile.

    If I just change the CL_NEAREST param to CL_LINEAR with no IF, then the filtering is applied, but it is applied to all tiles.

    It seems like the clTexParameteri call with CL_NEAREST is cancelling any previous calls with CL_LINEAR.

    Thank you for any help.

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    Hmm, before the clTexParameteri statements try adding this:

    Code:
    clBindTexture(CL_TEXTURE_2D, pSurf->get_handle());

    Without binding it first, the parameter changes could be happening to the wrong texture. I don't think I really understood that when I wrote that code.
    Seth A. Robinson
    Robinson Technologies

  3. #3
    Peasant
    Join Date
    Oct 2010
    Posts
    7

    Default

    Seth,
    the clBindTexture didn't work. When I added it, all the TilePics started to show the same image.

    Code:
    	clEnable(CL_TEXTURE_2D); // I tested with and without this line.
    	clBindTexture(CL_TEXTURE_2D, pSurf->get_handle());
    
    	if (pTile->GetBit(Tile::e_linearFilter))
    	{
    		clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MAG_FILTER, CL_LINEAR);
    		clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MIN_FILTER, CL_LINEAR);
    	}
    	else
    	{
    		clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MAG_FILTER, CL_NEAREST);
    		clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MIN_FILTER, CL_NEAREST);
    	}
    Unfortunately the CL_Surface does not have the set_min_filter(...) and set_mag_filter(...) methods as the CL_Texture has.

    I saw some opengl examples and all of them set the min and mag filter just before the creation of the texture. Maybe I should recreate the Surface if the linear filter is set, but I guess it would generate a big code change.

    What do you think Seth?

  4. #4
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    Oops, I forgot about Clanlib's batching stuff.

    Try replacing clBindTexture(CL_TEXTURE_2D, pSurf->get_handle()); with:

    Code:
    CL_OpenGLState state(pGC);
    state.set_active();
    clBindTexture(CL_TEXTURE_2D, pSurf->get_handle());
    And you will probably need to add this at the top of Tile.cpp:

    Code:
    #include "ClanLib/GL/opengl_state.h"
    Seth A. Robinson
    Robinson Technologies

  5. #5
    Peasant
    Join Date
    Oct 2010
    Posts
    7

    Default

    It works! But I had to do another little change in order to really work.

    I had to comment out the clTexParameteri(...) from HashedResource::LoadImage()


    Code:
    bool HashedResource::LoadImage()
    {
    	GetGameLogic()->ShowLoadingMessage();
    
    	SAFE_DELETE(m_pImage);
    
    	CL_PixelBuffer p = CL_ProviderFactory::load(m_strFilename);
    	//use this method gives us a chance to twiddle with the bits a bit
    	if (m_bColorKeyActive)
    	{
    		p.set_colorkey(true, m_colorKey);
    	}
    
    	m_pImage = new CL_Surface(p);
    //	clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MAG_FILTER, CL_NEAREST);
    //	clTexParameteri(CL_TEXTURE_2D, CL_TEXTURE_MIN_FILTER, CL_NEAREST);
    	return m_pImage != NULL;
    }
    I am going to test it during the development of my game. If everything is ok, I will create a patch for the repository. Should I use the Create Patch of Tortoise and post it in the forums?

    Thanks Seth for your help.

  6. #6
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    I am going to test it during the development of my game. If everything is ok, I will create a patch for the repository. Should I use the Create Patch of Tortoise and post it in the forums?
    Sure, that would be great.
    Seth A. Robinson
    Robinson Technologies

  7. #7
    Peasant
    Join Date
    Oct 2010
    Posts
    7

    Default

    Hi Seth,

    I've been using the engine since I made the Linear Filter change and it seems to be working normally. So, I made a patch in case you want to apply to the repository.

    MarcioGarcia_LinearFilter_20101114.patch

    Please, when you apply the patch, inform me so I can update my copy.

    Thanks,
    Marcio.

  8. #8
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    Thanks, committed! I tried setting the new linear filtering checkbox on a few sprites in the treeworld example and zoomed in but I didn't see the filtering turn on. Might want to double check that I added the patch right, code looks right.. hmm.
    Seth A. Robinson
    Robinson Technologies

  9. #9
    Peasant
    Join Date
    Oct 2010
    Posts
    7

    Default

    Seth,
    try to change the scale of the sprites. I don't know whether it would be applied by zooming.

Similar Threads

  1. Linear Particle for Clanlib 2.0
    By huntercool in forum Official ClanLib SDK Forums
    Replies: 16
    Last Post: 07-16-2010, 12:05 PM
  2. Source Code
    By NinjaNumberNine in forum Novashell Game Creation System
    Replies: 1
    Last Post: 01-02-2010, 01:44 AM
  3. changing the size of CL_Font_Sprite
    By xrubio in forum Official ClanLib SDK Forums
    Replies: 8
    Last Post: 07-27-2009, 09:49 AM
  4. Anyone have Linear Particles for CL 2.0.x?
    By NovaLaw in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 05-20-2009, 03:22 PM
  5. linear filtering
    By logixoul in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 07-01-2008, 01:28 PM

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
  •