예제 #1
0
/*-----------------------------------------------------------------------------
    Name        : liLayerColorAverage
    Description : Returns the average color of a layer
    Inputs      : layer - layer to find average color of
    Outputs     :
    Return      : average color
----------------------------------------------------------------------------*/
color liLayerColorAverage(lilayer *layer)
{
    udword red = 0, green = 0, blue = 0, alpha = 0, count, totalPixels;
    color *pColor;

    dbgAssert(layer->decompressed != NULL);
    dbgAssert(!bitTest(layer->flags, LFF_Channeled));
    totalPixels = count = (layer->bounds.x1 - layer->bounds.x0) *
        (layer->bounds.y1 - layer->bounds.y0);
    pColor = layer->decompressed;
    while (count > 0)
    {
        red += colRed(*pColor);
        green += colGreen(*pColor);
        blue += colBlue(*pColor);
        alpha += colAlpha(*pColor);
        count--;
        pColor++;
    }
    red /= totalPixels;
    green /= totalPixels;
    blue /= totalPixels;
    alpha /= totalPixels;

    return(colRGBA(red, green, blue, alpha));
}
예제 #2
0
/*-----------------------------------------------------------------------------
    Name        : liBlendBufferPrepare
    Description : Prepare a buffer, in the appropriate image size, for blending.
    Inputs      : image - image we are preparing to blend.
                  newTeamColor0,1 - out parameters for the team color effect buffer.
    Outputs     : Allocates and clears out a buffer in the same size as the image.
    Return      : This new buffer
----------------------------------------------------------------------------*/
color *liBlendBufferPrepare(layerimage *image, ubyte **newTeamColor0, ubyte **newTeamColor1)
{
    color *newBuffer;

    newBuffer = memAlloc(image->width * image->height * sizeof(color),
                         "RGBA blend buffer", 0);           //allocate the buffer
    memClearDword(newBuffer, colRGBA(0, 0, 0, 255),
                   image->width * image->height);           //clear to opaque black
    if (newTeamColor0 != NULL)
    {
        *newTeamColor0 = memAlloc(image->width * image->height, //allocate team color buffer
                                      "TeamColor0EffectBuffer", 0);
        *newTeamColor1 = memAlloc(image->width * image->height, //allocate team color buffer
                                      "TeamColor1EffectBuffer", 0);
        memset(*newTeamColor0, 0, image->width * image->height);//clear the memory
        memset(*newTeamColor1, 0, image->width * image->height);//in both buffers
    }
    return(newBuffer);                                      //return the buffer
}
예제 #3
0
void hrDrawPlayersProgress(featom *atom, regionhandle region)
{
    sdword     index;
    rectangle pos;
    rectangle outline;
    real32 percent;
    fonthandle currentfont;
    bool droppedOut;

    hrProgressRegion = region;

    pos = region->rect;

//  primRectSolid2(&pos, colRGBA(0, 0, 0, 64));

    pos.y0+=fontHeight(" ");
    pos.y1=pos.y0+8;

    currentfont = fontMakeCurrent(playernamefont);

    if (multiPlayerGame)
    {
        dbgAssertOrIgnore(sigsNumPlayers == tpGameCreated.numPlayers);
        for (index=0;index<sigsNumPlayers;index++)
        {
            droppedOut = playerHasDroppedOutOrQuit(index);

            outline = pos;
            outline.x0 -= 5;
            outline.x1 += 10;
            outline.y0 -= 3;
            outline.y1 = outline.y0 + fontHeight(" ")*2 - 2;

            if ((hrBackgroundDirty) || (!PlayersAlreadyDrawnDropped[index]))
            {
                PlayersAlreadyDrawnDropped[index] = droppedOut;

                primRectSolid2(&outline, colBlack);

                if (droppedOut)
                {
                    fontPrintf(pos.x0,pos.y0,colBlack,"%s",tpGameCreated.playerInfo[index].PersonalName);
                    fontPrintf(pos.x0,pos.y0,HorseRaceDropoutColor,"%s",
                               (playersReadyToGo[index] == PLAYER_QUIT) ? strGetString(strQuit) : strGetString(strDroppedOut));
                }
                else
                {
                    fontPrintf(pos.x0,pos.y0,tpGameCreated.playerInfo[index].baseColor,"%s",tpGameCreated.playerInfo[index].PersonalName);

                    if (horseracestatus.hrstatusstr[index][0])
                    {
                        fontPrintf(pos.x0+150,pos.y0,tpGameCreated.playerInfo[index].baseColor,"%s",horseracestatus.hrstatusstr[index]);
                    }
                }
            }

            primRectOutline2(&outline, 1, (droppedOut) ? HorseRaceDropoutColor : tpGameCreated.playerInfo[index].stripeColor);

            pos.y0+=fontHeight(" ");
            pos.y1=pos.y0+4;

            percent = horseracestatus.percent[index];

            hrBarDraw(&pos,hrBackBarColor,(droppedOut) ? HorseRaceDropoutColor : tpGameCreated.playerInfo[index].baseColor,percent);

            pos.y0+=fontHeight(" ");
        }
    }
    else if (singlePlayerGame)
    {
        pos = hrSinglePlayerPos;

        // progress bar
        if (pos.x0 != 0)
        {
            percent = horseracestatus.percent[0];

            //dbgMessagef("percent %f",percent);

            hrBarDraw(&pos, colBlack, hrSinglePlayerLoadingBarColor/*teColorSchemes[0].textureColor.base*/, percent);
        }

        // blinking hyperspace destination (render every other call)
        if (++hrProgressCounter % 2 == 0)
        {
            hrBackgroundDirty = 3;  // 1 - nothing happens as decremented before rendered
                                    // 2 - background is cleared but not redrawn
                                    // 3 - 3's the charm
            
            // hyperspace destination circled in first-person view  
            #define SP_LOADING_HYPERSPACE_DEST_CIRCLE_X  115
            #define SP_LOADING_HYPERSPACE_DEST_CIRCLE_Y  342
            
            // hyperspace destination arrowed in "as the bird flies" view 
            #define SP_LOADING_HYPERSPACE_DEST_ARROWS_X  195
            #define SP_LOADING_HYPERSPACE_DEST_ARROWS_Y  134

            // NB: hrDrawFile deals with coordinate mapping

#ifdef _WIN32
            hrDrawFile("feman\\loadscreen\\ring.lif",
                SP_LOADING_HYPERSPACE_DEST_CIRCLE_X, SP_LOADING_HYPERSPACE_DEST_CIRCLE_Y
            );
            hrDrawFile("feman\\loadscreen\\arrows.lif",
                SP_LOADING_HYPERSPACE_DEST_ARROWS_X, SP_LOADING_HYPERSPACE_DEST_ARROWS_Y
            );
#else
            hrDrawFile("feman/loadscreen/ring.lif",
                SP_LOADING_HYPERSPACE_DEST_CIRCLE_X, SP_LOADING_HYPERSPACE_DEST_CIRCLE_Y
            );
            hrDrawFile("feman/loadscreen/arrows.lif",
                SP_LOADING_HYPERSPACE_DEST_ARROWS_X, SP_LOADING_HYPERSPACE_DEST_ARROWS_Y
            );
#endif
        }
    }
    else
    {
        if (hrBackgroundDirty)
        {
            outline = pos;
            outline.x0 -= 5;
            outline.x1 += 10;
            outline.y0 -= 3;
            outline.y1 = outline.y0 + fontHeight(" ")*2 - 2;

            primRectTranslucent2(&outline, colRGBA(0,0,0,64));
            primRectOutline2(&outline, 1, teColorSchemes[0].textureColor.detail);

            fontPrintf(pos.x0,pos.y0,teColorSchemes[0].textureColor.base,"%s",playerNames[0]);
        }

        pos.y0+=fontHeight(" ");
        pos.y1=pos.y0+4;

        percent = horseracestatus.percent[0];

        hrBarDraw(&pos,hrBackBarColor,teColorSchemes[0].textureColor.base,percent);
    }
    fontMakeCurrent(currentfont);
}
예제 #4
0
/*-----------------------------------------------------------------------------
    Name        : btgReset
    Description : reset the btg subsystem
    Inputs      :
    Outputs     :
    Return      :
----------------------------------------------------------------------------*/
void btgReset()
{
    sdword numStars;

    lastbg[0] = 255;
    lastbg[1] = 255;
    lastbg[2] = 255;
    lastbg[3] = 0;

    btgFade = 255;

    btgThetaOffset = 0.0f;
    btgPhiOffset = 0.0f;

    universe.backgroundColor = 0;
    rndSetClearColor(colRGBA(0,0,0,255));

    if (texList != NULL)
    {
        starTex* ptex = texList;
        starTex* temptex;

        while (ptex != NULL)
        {
            if (ptex->glhandle != 0)
            {
                glDeleteTextures(1, &ptex->glhandle);
            }
            temptex = ptex;
            ptex = ptex->next;
            memFree(temptex);
        }

        texList = NULL;
    }

    if (btgHead != NULL)
    {
        numStars = btgHead->numStars;
        memFree(btgHead);
        btgHead = NULL;
    }
    else
    {
        numStars = 0;
    }
    if (btgVerts != NULL)
    {
        memFree(btgVerts);
        btgVerts = NULL;
    }
    if (btgStars != NULL)
    {
        memFree(btgStars);
        btgStars = NULL;
    }
    if (btgPolys != NULL)
    {
        memFree(btgPolys);
        btgPolys = NULL;
    }
    if (btgTransVerts != NULL)
    {
        if (useVBO) glDeleteBuffers(1, &vboTransVerts);
        memFree(btgTransVerts);
        btgTransVerts = NULL;
    }
    if (btgTransStars != NULL)
    {
        if (useVBO) glDeleteBuffers(1, &vboTransStars);
        memFree(btgTransStars);
        btgTransStars = NULL;
    }
    if (btgIndices != NULL)
    {
        if (useVBO) glDeleteBuffers(1, &vboIndices);
        memFree(btgIndices);
        btgIndices = NULL;
    }
}
예제 #5
0
void tutExecute(regionhandle reg)
{
    fonthandle currentfont;
    sdword texty, bitmap;

    rectangle rect;                         // used for translucent boxes behind text
    rectangle *buttonrect = &reg->rect;     // used for "next" button
    bool modeset = FALSE;
    sdword bitmap_x, bitmap_vel;

	if(tutorial == 3)
		return;

    if(tutRegion->previous)
        regSiblingMoveToFront(tutRegion);

    if(tutTransition == 0 && tutLesson != TUT_LESSON_ENTER_BUILD_MANAGER && tutLesson != TUT_LESSON_BUILD_SHIP) // don't draw button on build manager lessons
    {
        if(mouseInRect(buttonrect))
        {
            if(mouseLeftButton())
            {
                tutSkip = TRUE;
                trRGBTextureMakeCurrent(tutButtonTexture[NEXT_ON]);
            }
            else
                trRGBTextureMakeCurrent(tutButtonTexture[NEXT_MOUSE]);
        }
        else
            trRGBTextureMakeCurrent(tutButtonTexture[NEXT_OFF]);
        rndPerspectiveCorrection(FALSE);
//      glEnable(GL_BLEND);         // needs to be enabled once Keith fixes alpha blending intel compiler optimization bug
        primRectSolidTextured2(buttonrect);
//      glDisable(GL_BLEND);        // needs to be enabled once Keith fixes alpha blending intel compiler optimization bug
    }

    if(tutTransition == 0)
    {
        switch(PassedTutorial(tutLesson))
        {
        case 0:     // Didn't pass
            break;

        case 1:     // Perform transition
            tutTransition = 1;
            break;

        case -1:    // No Transition
            tutLesson++;
            InitTutorial(tutLesson);
            break;
        }
    }
    else if(tutTransition == 1)
    {
        tutTransitionCount++;
        if(tutTransitionCount == TUT_TransitionFramesOut)
        {
            tutTransition = 2;
            tutTransitionCount = TUT_TransitionFramesIn;
            tutLesson++;
            InitTutorial(tutLesson);
            if((tutLesson >= TUT_ADVANCED_INTRO && tutorial == 1) || (tutLesson >= TUT_TOTAL_LESSONS && tutorial == 2))
            {
                tutorialdone = TRUE;
                return;
            }
        }
    }
    else if(tutTransition == 2)
    {
        tutTransitionCount--;
        if(tutTransitionCount == 0)
            tutTransition = 0;
    }

    if(tutBitmapList[tutLesson][2] != -1)
    {
        bitmap_x = TUT_BITMAP_X;
        bitmap_vel = 210;
    }
    else if(tutBitmapList[tutLesson][1] != -1)
    {
        bitmap_x = TUT_BITMAP_X + (TUT_BITMAP_WIDTH + 8);
        bitmap_vel = 150;
    }
    else
    {
        bitmap_x = TUT_BITMAP_X + ((2 * TUT_BITMAP_WIDTH) + 8);
        bitmap_vel = 90;
    }

    if(tutTransition == 0)
        bitmap_vel = 0;
    else if(tutTransition == 1)
        bitmap_vel = (long) (((float)bitmap_vel/(float)TUT_TransitionFramesOut) * (float)tutTransitionCount);
    else if(tutTransition == 2)
        bitmap_vel = (long) (((float)bitmap_vel/(float)TUT_TransitionFramesIn) * (float)tutTransitionCount);

//  glEnable(GL_BLEND);
    for(bitmap = 0; bitmap < 3; bitmap++)
    {
        if(tutBitmapList[tutLesson][bitmap] != -1)
        {
            trRGBTextureMakeCurrent(tutButtonTexture[tutBitmapList[tutLesson][bitmap]]);
            rndPerspectiveCorrection(FALSE);
            rect.x0 = bitmap_x + ((TUT_BITMAP_WIDTH + 8) * bitmap) + bitmap_vel;
            rect.y0 = TUT_BITMAP_Y;
            rect.x1 = bitmap_x + ((TUT_BITMAP_WIDTH + 8) * bitmap) + TUT_BITMAP_WIDTH + bitmap_vel;
            rect.y1 = TUT_BITMAP_Y + TUT_BITMAP_HEIGHT;
            primRectSolidTextured2(&rect);
        }
    }
//  glDisable(GL_BLEND);

    if (!primModeEnabled)   // draw translucent polys before text
    {
        primModeSet2();
        modeset = TRUE;
    }

    if(tutLesson != TUT_LESSON_BUILD_SHIP)      // default behaviour for lessons
    {
    long    TitlePos = (long)(TUT_TitleTransMult[tutTransition] * (float)tutTransitionCount);
    long    TextPos = (long)(TUT_TextTransMult[tutTransition] * (float)tutTransitionCount);

        rect.x0 = 0;
        rect.y0 = TUT_Title_Y - TitlePos - 7;
        rect.x1 = 640;
        rect.y1 = TUT_Title_Y - TitlePos + 22;
        primRectTranslucent2(&rect, colRGBA(0, 0, 0, 128));

        rect.x0 = TUT_Main_X - TextPos - 12;
        rect.y0 = TUT_Main_Y - 6;
        rect.x1 = TUT_Main_X - TextPos + TUT_MainTextWidth + 4;
        rect.y1 = tutLastMainY;
        primRectTranslucent2(&rect, colRGBA(0, 0, 0, 128));

        currentfont = fontMakeCurrent(tutTitleFont);    // draw text
        fontPrintf(TUT_Title_X, TUT_Title_Y - TitlePos, TUT_TitleColor, "%s", strGetString(strTutorial00Title + (tutLesson * 7)));
        currentfont = fontMakeCurrent(tutMainFont);
        texty = DrawTextBlock(strGetString(strTutorial00Line01 + (tutLesson * 7)), TUT_Main_X - TextPos, TUT_Main_Y, TUT_MainTextWidth, TUT_MainTextHeight, TUT_MainColor);
        texty = DrawTextBlock(strGetString(strTutorial00Line02 + (tutLesson * 7)), TUT_Main_X - TextPos, texty, TUT_MainTextWidth, TUT_MainTextHeight, TUT_MainColor);
        texty = DrawTextBlock(strGetString(strTutorial00Line03 + (tutLesson * 7)), TUT_Main_X - TextPos, texty, TUT_MainTextWidth, TUT_MainTextHeight, TUT_MainColor);
        texty = DrawTextBlock(strGetString(strTutorial00Line04 + (tutLesson * 7)), TUT_Main_X - TextPos, texty, TUT_MainTextWidth, TUT_MainTextHeight, TUT_MainColor);
        tutLastMainY = DrawTextBlock(strGetString(strTutorial00Line05 + (tutLesson * 7)), TUT_Main_X - TextPos, texty, TUT_MainTextWidth, TUT_MainTextHeight, TUT_MainColor);
        fontMakeCurrent(currentfont);
    }
    else                                    // special case for build ship lesson
    {
        currentfont = fontMakeCurrent(tutMainFont);
        texty = DrawTextBlock(strGetString(strTutorial17Line01 + tutVar.count), TUT_Build_X, TUT_Build_Y, TUT_BuildTextWidth, TUT_BuildTextHeight, TUT_BuildColor);
        fontMakeCurrent(currentfont);

        rect.x0 = TUT_Build_X - 8;          // draw outline box around text
        rect.y0 = TUT_Build_Y - 6;
        rect.x1 = TUT_Build_X + TUT_BuildTextWidth + 8;
        rect.y1 = texty;
        primRectOutline2(&rect, 2, colRGB(tutPulseValue, tutPulseValue, tutPulseValue));

        if(tutVar.count == 0)               // point to appropriate place on screen
            tutDrawLinePulse(TUT_Build_X - 8, texty, 160, 100, tutPulseValue, 8);
        else if(tutVar.count == 1)
            tutDrawLinePulse(TUT_Build_X - 8, texty, 180, 410, tutPulseValue, 8);
        else if(tutVar.count == 2)
            tutDrawLinePulse(TUT_Build_X - 8, texty, 550, 410, tutPulseValue, 8);

        tutPulseValue -= 8;
    }

    if(!FirstWordNULL(strGetString(strTutorial00Tip + (tutLesson * 7))))
    {
    long    TipPos = (long)(TUT_TipTransMult[tutTransition] * (float)tutTransitionCount);
    long    TextPos = (long)(TUT_TextTransMult[tutTransition] * (float)tutTransitionCount);

        if (!primModeEnabled)   // draw translucent polys before tip text
        {
            primModeSet2();
            modeset = TRUE;
        }

        rect.x0 = TUT_TipTitle_X - 8;
        rect.y0 = TUT_TipTitle_Y - TipPos - 6;
        rect.x1 = TUT_Tip_X - 8;
        rect.y1 = TUT_TipTitle_Y - TipPos + 18;
        primRectTranslucent2(&rect, colRGBA(0, 0, 0, 128));

        rect.x0 = TUT_Tip_X + TextPos - 8;
        rect.y0 = TUT_Tip_Y - 6;
        rect.x1 = TUT_Tip_X + TextPos + TUT_TipTextWidth + 8;
        rect.y1 = tutLastTipY;
        primRectTranslucent2(&rect, colRGBA(0, 0, 0, 128));

        if(modeset)
            primModeClear2();

        currentfont = fontMakeCurrent(tutTipTitleFont);
        fontPrintf(TUT_TipTitle_X, TUT_TipTitle_Y - TipPos, TUT_TipTitleColor, "%s", strGetString(strTutorialTip));
        currentfont = fontMakeCurrent(tutTipFont);
        tutLastTipY = DrawTextBlock(strGetString(strTutorial00Tip + (tutLesson * 7)), TUT_Tip_X + TextPos, TUT_Tip_Y, TUT_TipTextWidth, TUT_TipTextHeight, TUT_TipColor);
    }

    fontMakeCurrent(currentfont);
}