Blitting a texture

This is a discussion on Blitting a texture within the Game Programming forums, part of the General Programming Boards category; Wana use blitting to copy a texture (source) to the screen (destination). Got a class (Crect) which has functionality to ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    13

    Blitting a texture

    Wana use blitting to copy a texture (source) to the screen (destination).
    Got a class (Crect) which has functionality to clip texture.
    The aim being to show the texture moving about screen and to show it partially off the screen.

    blitting function
    Code:
    void BlitFn ( BYTE *destination, int destWidth, BYTE *source, int sourceWidth, const CRect &sourceRect, int posX, int posY )
    {
    int sourceHeight;
    BYTE alpha;
    BYTE *destPnter = destination + ( posX+posY*destWidth)*4;
    BYTE *sourcePnter = source;
    		 
    int EndOfLineDestIncrement = ( destWidth - sourceWidth )*4;
    		 
    for ( int posY = 0; posY < sourceHeight; posY++ )
      {
           for ( posX = 0; posX < sourceWidth; posX++ )
               {
    	 if ( alpha = 255 )
    	   {
    	          memcpy ( destPnter, sourcePnter, 4 );
    	    }
    					
    	 else
    	    {
    	          BYTE blue = sourcePnter [0];
    	          BYTE green = sourcePnter [1];
                              BYTE red = sourcePnter [2];
    	          BYTE alpha = sourcePnter [3];
    							         destPnter[0] = destPnter[0] + ( (alpha*(blue-destPnter[0])) >> 8);
    	         destPnter[1] = destPnter[1] + ( (alpha*(green-destPnter[1])) >> 8);
    	          destPnter[2] = destPnter[2] + ( (alpha*(red-destPnter[2])) >> 8);
    	  }
               }
    
                sourcePnter += 4;
                destPnter += 4;
    		 
          }
    
             destPnter = EndOfLineDestIncrement;
    }

    PROBLEMS:

    [1] in the final line of code: 'cant convert type 'int' from type 'BYTE *'
    [2] Anybody got any good sites for downloading FREE spaceship textures that could be used for 2D vertical shooter games?

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Is this Win32, MFC, DX, OpenGL?
    What platform?
    What compiler/IDE?

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    [1] destPnter wants a pointer to a BYTE but you are giving it an int
    [2] no

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. d3d9 c++ texture wrapper... again...
    By yaya in forum Game Programming
    Replies: 0
    Last Post: 04-01-2009, 01:08 PM
  2. D3d Texture Wrapper == ARRRGGGGHHH
    By yaya in forum Game Programming
    Replies: 1
    Last Post: 03-25-2009, 06:41 PM
  3. Replies: 4
    Last Post: 02-27-2008, 02:10 PM
  4. OpenGL - look trough surface -nehe lesson
    By GanglyLamb in forum Game Programming
    Replies: 8
    Last Post: 08-24-2006, 11:06 PM
  5. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21