Back to index

supertuxkart  0.5+dfsg1
RenderTexture.cpp
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #include "RenderTexture.h"
00017 #include <memory.h>
00018 #include "BMF_FontData.h"
00019 
00020 renderTexture::renderTexture(int width,int height)
00021 :m_height(height),m_width(width)
00022 {
00023        m_buffer = new unsigned char[m_width*m_height*4];
00024        
00025        //clear screen
00026        memset(m_buffer,0,m_width*m_height*4);
00027 
00028        //clear screen version 2
00029        for (int x=0;x<m_width;x++)
00030        {
00031               for (int y=0;y<m_height;y++)
00032               {
00033                      setPixel(x,y,btVector4(float(x),float(y),0.f,1.f));
00034               }
00035 
00036        }
00037 
00038 }
00039 
00040 void renderTexture::grapicalPrintf(char* str,    BMF_FontData* fontData, int startx,int starty)
00041 {
00042        unsigned char c;
00043        int rasterposx = startx;
00044        int rasterposy = starty;
00045        while ((c = (unsigned char) *str++)) {
00046               BMF_CharData & cd = fontData->chars[c];
00047               
00048               if (cd.data_offset!=-1) {
00049                      unsigned char* bitmap = &fontData->bitmap_data[cd.data_offset];
00050                      for (int y=0;y<cd.height;y++)
00051                      {
00052                             int bit = 128;
00053                             for (int x=0;x<cd.width;x++)
00054                             {
00055                                    char packedColor = bitmap[y];
00056                                    float colorf = packedColor & bit ? 0.f : 1.f;
00057                                    btVector4 rgba(colorf,colorf,colorf,1.f);
00058                                    setPixel(rasterposx+x,rasterposy+8-y-1,rgba);
00059                                    bit >>=1;
00060                             }
00061                      }
00062               }
00063               rasterposx+= cd.advance;
00064        }
00065 }
00066 
00067 renderTexture::~renderTexture()
00068 {
00069        delete [] m_buffer;
00070 }
00071 
00072 
00073