Thread: Bitmasking Problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218

    Bitmasking Problem

    I'm making a set of functions to produce console-like output for SDL. The font is made from a binary mask but I am having problems getting it to display properly. Heres an example of it printing the string"0123456789ABCDE" :
    http://i92.photobucket.com/albums/l1...l/deleteme.png

    Its partly readable but somethings definitely wrong. The constructor for the class takes a character map, and the data. This is run here in my prog:
    Code:
    BitText txt(	"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 
    				"mprtxpmckccccmmp`acg~mp`e`pmaeiq~aa~oom`pmego}ppm~``acgomppmppmmppn`ak"
    				"cipp~pp}pp}pp}mpooopm}ppppp}~oo}oo~~oo}ooompoorpnppp~pppmcccccm~aaaqqk"
    				"pqswsqpoooooo~pztppppppxtrppmpppppm}pp}ooomppptrn}pp}sqpmpom`pm~cccccc"
    				"ppppppmpppppicppppttippicipppppiccc~`acgo~" );
    Heres what the constructor does with it:
    Code:
    BitText::BitText(const char* char_map, const char* char_data)
    {
    	int len = (int)strlen(char_map);
    	map = new char[len];
    	strcpy(map, char_map);
    	len = (int)strlen(char_data);
    	data = new char[len];
    	strcpy(data, char_data); 
    	col = 0xFFFFFFFF;
    }
    And heres the function to print text to the screen:
    Code:
    void BitText::Print(Uint16 x_pos, Uint16 y_pos, const char* text)
    {
    	int x, y, bit, pos;
    	char* ptr;
    
    	for(int i=0; i<(int)strlen(text); i++)
    	{
    		//Get the coresponding character in the character map
    		for(ptr=map, pos=0; *ptr; ptr++, pos++)
    			if(*ptr == text[i]) break;
    
    		//Get the characters data start point
    		ptr = data +(pos*7);
    		
    		//Draw character
    		for(y=0; y<7; y++)
    		{		
    			bit=16;
    			for(x=0; x<5; x++, bit >>= 1)
    				if(*ptr & bit) 
    					WritePixel(x_pos+x, y_pos+y, this->col);	 
    			ptr++; //Move to data byte holding next scanline of the character	
    		}
    
    		x_pos+=6;
    	}
    }
    I'm pretty sure the mistake is in this last function. Can someone see whats going wrong here? I can't Hopefully thats all the relevant code here.
    Last edited by mike_g; 11-07-2007 at 01:58 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM