示例#1
0
TEST(RTMaterial, shouldSupportAddition) {

  RTMaterial m1;
  m1.setKTransparency(0.1);
  m1.setShininess(0.2);
  m1.setDiffColor(RTColor(0,0.1,0.2));
  m1.setSpecColor(RTColor(0,0.1,0.2));
  m1.setAmbColor(RTColor(0,0.1,0.2));
  m1.setEmissColor(RTColor(0,0.1,0.2));

  RTMaterial m2;
  m2.setKTransparency(0.3);
  m2.setShininess(0.2);
  m2.setDiffColor(RTColor(0,0.1,0.2));
  m2.setSpecColor(RTColor(0,0.1,0.2));
  m2.setAmbColor(RTColor(0,0.1,0.2));
  m2.setEmissColor(RTColor(0,0.1,0.2));

  m1 += m2;

  DOUBLES_EQUAL( 0.4, m1.getKTransparency(), 0.00001 );
  DOUBLES_EQUAL( 0.4, m1.getShininess(), 0.00001 );
  COLOR_EQUAL(0, 51, 102, m1.getDiffColor() );
  COLOR_EQUAL(0, 51, 102, m1.getSpecColor() );
  COLOR_EQUAL(0, 51, 102, m1.getAmbColor() );
  COLOR_EQUAL(0, 51, 102, m1.getEmissColor() );
}
示例#2
0
TEST(RTMaterial, shouldSupportMultiplication) {

  RTMaterial m1;
  m1.setKTransparency(0.1);
  m1.setShininess(0.2);
  m1.setDiffColor(RTColor(0,0.1,0.2));
  m1.setSpecColor(RTColor(0,0.1,0.2));
  m1.setAmbColor(RTColor(0,0.1,0.2));
  m1.setEmissColor(RTColor(0,0.1,0.2));

  m1 *= 0.5;

  DOUBLES_EQUAL( 0.05, m1.getKTransparency(), 0.00001 );
  DOUBLES_EQUAL( 0.1, m1.getShininess(), 0.00001 );
  COLOR_EQUAL(0, 12, 25, m1.getDiffColor() );
  COLOR_EQUAL(0, 12, 25, m1.getSpecColor() );
  COLOR_EQUAL(0, 12, 25, m1.getAmbColor() );
  COLOR_EQUAL(0, 12, 25, m1.getEmissColor() );
}
示例#3
0
static void
out_splines (SWFMovie m, spline_list_array_type shape, int height)
{
  unsigned this_list;
  color_type last_color = {0,0,0};

  for (this_list = 0; this_list < SPLINE_LIST_ARRAY_LENGTH (shape);
    this_list++)
      {
        SWFShape k;

        unsigned this_spline;
        spline_list_type list = SPLINE_LIST_ARRAY_ELT (shape, this_list);
        spline_type first = SPLINE_LIST_ELT (list, 0);

        if (this_list == 0 || !COLOR_EQUAL(list.color, last_color))
		  {
            k = newSWFShape();
            SWFShape_setRightFill(k, SWFShape_addSolidFill(k, list.color.r, list.color.g, list.color.b, 0xff));
	        last_color = list.color;
		  }
        SWFShape_movePenTo(k, SWFSCALE*START_POINT(first).x,
			     SWFSCALE*height - SWFSCALE*START_POINT(first).y);

        for (this_spline = 0; this_spline < SPLINE_LIST_LENGTH (list);
          this_spline++)
          {
            spline_type s = SPLINE_LIST_ELT (list, this_spline);

            if (SPLINE_DEGREE(s) == LINEARTYPE)
              {
                SWFShape_drawLineTo(k, SWFSCALE*END_POINT(s).x,
                  SWFSCALE*height - SWFSCALE*END_POINT(s).y);
              }
            else
              {
                SWFShape_drawCubicTo (k, SWFSCALE*CONTROL1(s).x,
                  SWFSCALE*height - SWFSCALE*CONTROL1(s).y,
                  SWFSCALE*CONTROL2(s).x,
                  SWFSCALE*height - SWFSCALE*CONTROL2(s).y,
                  SWFSCALE*END_POINT(s).x,
                  SWFSCALE*height - SWFSCALE*END_POINT(s).y);
              }
          }
        SWFMovie_add(m,k);
    }
}
示例#4
0
// Load an Image font file (XNA style)
static SpriteFont LoadImageFont(Image image, Color key, int firstChar)
{
    #define COLOR_EQUAL(col1, col2) ((col1.r == col2.r)&&(col1.g == col2.g)&&(col1.b == col2.b)&&(col1.a == col2.a))

    int charSpacing = 0;
    int lineSpacing = 0;

    int x = 0;
    int y = 0;

    // Default number of characters supported
    #define MAX_FONTCHARS          256

    // We allocate a temporal arrays for chars data measures,
    // once we get the actual number of chars, we copy data to a sized arrays
    int tempCharValues[MAX_FONTCHARS];
    Rectangle tempCharRecs[MAX_FONTCHARS];

    Color *pixels = GetImageData(image);

    // Parse image data to get charSpacing and lineSpacing
    for (y = 0; y < image.height; y++)
    {
        for (x = 0; x < image.width; x++)
        {
            if (!COLOR_EQUAL(pixels[y*image.width + x], key)) break;
        }
        if (!COLOR_EQUAL(pixels[y*image.width + x], key)) break;
    }

    charSpacing = x;
    lineSpacing = y;

    int charHeight = 0;
    int j = 0;

    while (!COLOR_EQUAL(pixels[(lineSpacing + j)*image.width + charSpacing], key)) j++;

    charHeight = j;

    // Check array values to get characters: value, x, y, w, h
    int index = 0;
    int lineToRead = 0;
    int xPosToRead = charSpacing;

    // Parse image data to get rectangle sizes
    while ((lineSpacing + lineToRead*(charHeight + lineSpacing)) < image.height)
    {
        while ((xPosToRead < image.width) &&
              !COLOR_EQUAL((pixels[(lineSpacing + (charHeight+lineSpacing)*lineToRead)*image.width + xPosToRead]), key))
        {
            tempCharValues[index] = firstChar + index;

            tempCharRecs[index].x = xPosToRead;
            tempCharRecs[index].y = lineSpacing + lineToRead*(charHeight + lineSpacing);
            tempCharRecs[index].height = charHeight;

            int charWidth = 0;

            while (!COLOR_EQUAL(pixels[(lineSpacing + (charHeight+lineSpacing)*lineToRead)*image.width + xPosToRead + charWidth], key)) charWidth++;

            tempCharRecs[index].width = charWidth;

            index++;

            xPosToRead += (charWidth + charSpacing);
        }

        lineToRead++;
        xPosToRead = charSpacing;
    }

    TraceLog(DEBUG, "SpriteFont data parsed correctly from image");
    
    // NOTE: We need to remove key color borders from image to avoid weird 
    // artifacts on texture scaling when using FILTER_BILINEAR or FILTER_TRILINEAR
    for (int i = 0; i < image.height*image.width; i++) if (COLOR_EQUAL(pixels[i], key)) pixels[i] = BLANK;

    // Create a new image with the processed color data (key color replaced by BLANK)
    Image fontClear = LoadImageEx(pixels, image.width, image.height);
    
    free(pixels);    // Free pixels array memory

    // Create spritefont with all data parsed from image
    SpriteFont spriteFont = { 0 };

    spriteFont.texture = LoadTextureFromImage(fontClear); // Convert processed image to OpenGL texture
    spriteFont.numChars = index;
    
    UnloadImage(fontClear);     // Unload processed image once converted to texture

    // We got tempCharValues and tempCharsRecs populated with chars data
    // Now we move temp data to sized charValues and charRecs arrays
    spriteFont.charRecs = (Rectangle *)malloc(spriteFont.numChars*sizeof(Rectangle));
    spriteFont.charValues = (int *)malloc(spriteFont.numChars*sizeof(int));
    spriteFont.charOffsets = (Vector2 *)malloc(spriteFont.numChars*sizeof(Vector2));
    spriteFont.charAdvanceX = (int *)malloc(spriteFont.numChars*sizeof(int));

    for (int i = 0; i < spriteFont.numChars; i++)
    {
        spriteFont.charValues[i] = tempCharValues[i];
        spriteFont.charRecs[i] = tempCharRecs[i];

        // NOTE: On image based fonts (XNA style), character offsets and xAdvance are not required (set to 0)
        spriteFont.charOffsets[i] = (Vector2){ 0.0f, 0.0f };
        spriteFont.charAdvanceX[i] = 0;
    }

    spriteFont.size = spriteFont.charRecs[0].height;
    
    TraceLog(INFO, "Image file loaded correctly as SpriteFont");

    return spriteFont;
}