当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_BlitSurface函数代码示例

本文整理汇总了C++中SDL_BlitSurface函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_BlitSurface函数的具体用法?C++ SDL_BlitSurface怎么用?C++ SDL_BlitSurface使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_BlitSurface函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: world2zoomedWorld

void Tile::blitDeadUnits(int xPos, int yPos) {
    if(!isFogged(pLocalHouse->getHouseID())) {
        for(std::vector<DEADUNITTYPE>::const_iterator iter = deadUnits.begin(); iter != deadUnits.end(); ++iter) {
            SDL_Rect source = { 0, 0, world2zoomedWorld(TILESIZE), world2zoomedWorld(TILESIZE)};
            SDL_Surface** pSurface = NULL;
            switch(iter->type) {
            case DeadUnit_Infantry: {
                pSurface = pGFXManager->getObjPic(ObjPic_DeadInfantry, iter->house);
                source.x = (iter->timer < 1000 && iter->onSand) ? world2zoomedWorld(TILESIZE) : 0;
            }
            break;

            case DeadUnit_Infantry_Squashed1: {
                pSurface = pGFXManager->getObjPic(ObjPic_DeadInfantry, iter->house);
                source.x = 4 * world2zoomedWorld(TILESIZE);
            }
            break;

            case DeadUnit_Infantry_Squashed2: {
                pSurface = pGFXManager->getObjPic(ObjPic_DeadInfantry, iter->house);
                source.x = 5 * world2zoomedWorld(TILESIZE);
            }
            break;

            case DeadUnit_Carrall: {
                pSurface = pGFXManager->getObjPic(ObjPic_DeadAirUnit, iter->house);
                if(iter->onSand) {
                    source.x = (iter->timer < 1000) ? 5*world2zoomedWorld(TILESIZE) : 4*world2zoomedWorld(TILESIZE);
                } else {
                    source.x = 3*world2zoomedWorld(TILESIZE);
                }
            }
            break;

            case DeadUnit_Ornithopter: {
                pSurface = pGFXManager->getObjPic(ObjPic_DeadAirUnit, iter->house);
                if(iter->onSand) {
                    source.x = (iter->timer < 1000) ? 2*world2zoomedWorld(TILESIZE) : world2zoomedWorld(TILESIZE);
                } else {
                    source.x = 0;
                }
            }
            break;

            default: {
                pSurface = NULL;
            }
            break;
            }

            if(pSurface != NULL) {
                SDL_Rect dest = {   screenborder->world2screenX(iter->realPos.x) - world2zoomedWorld(TILESIZE)/2,
                                    screenborder->world2screenY(iter->realPos.y) - world2zoomedWorld(TILESIZE)/2,
                                    pSurface[currentZoomlevel]->w,
                                    pSurface[currentZoomlevel]->h
                                };
                SDL_BlitSurface(pSurface[currentZoomlevel], &source, screen, &dest);
            }
        }
    }
}
开发者ID:binarycrusader,项目名称:dunelegacy,代码行数:61,代码来源:Tile.cpp

示例2: LoadBackground

CFighterStatsDemo::CFighterStatsDemo( FighterEnum a_iFighter )
{
	m_iTimeLeft = 500;
	m_poStaff = NULL;
	
	m_poBackground = LoadBackground( "FighterStats.jpg", 64 );
	DrawGradientText( "Fighter Stats", titleFont, 10, m_poBackground );

	SDL_BlitSurface( m_poBackground, NULL, gamescreen, NULL );
	SDL_Flip( gamescreen );
	
	if ( mg_iLastFighter < 0 )
	{
		// First run; create shuffled array of fighters.
		mg_iLastFighter = 0;
		
		int i, j;
		FighterEnum k;
		for ( i=0; i<LASTFIGHTER-1; ++i )
		{
			mg_aenFighterOrder[i] = (FighterEnum)(i+1);
		}
		for ( i=0; i<LASTFIGHTER-1; ++i )
		{
			j = rand() % (LASTFIGHTER-1);
			k = mg_aenFighterOrder[i]; 
			mg_aenFighterOrder[i] = mg_aenFighterOrder[j]; 
			mg_aenFighterOrder[j] = k;
		}
	}
	
	if ( a_iFighter <= UNKNOWN )
	{
		mg_iLastFighter = (mg_iLastFighter+1) % (LASTFIGHTER-1);
		m_enFighter = mg_aenFighterOrder[mg_iLastFighter];
	}
	else
	{
		m_enFighter = a_iFighter;
	}

	if ( g_oPlayerSelect.IsFighterAvailable( m_enFighter ) )
	{
		g_oPlayerSelect.SetPlayer( 0, m_enFighter );
		g_oBackend.PerlEvalF( "SelectStart(%d);", 2 );
	}
	else
	{
		std::string sStaffFilename = DATADIR;
		sStaffFilename += "/characters/STAFF.DAT";
		m_poStaff = new CRlePack( sStaffFilename.c_str(), 255 );
	}

	g_oBackend.PerlEvalF("GetFighterStats(%d);", m_enFighter );
	_sge_TTFont* font = impactFont;
	int y = TOPMARGIN;


	AV *StatTags = get_av( "StatTags", FALSE );

	char *s, *sTag;

	s = SvPV_nolen(get_sv("Name", FALSE));
	DrawTextMSZ( s, inkFont, (LEFTMARGIN + RIGHTMARGIN)/2, y, AlignHCenter, C_WHITE, m_poBackground );
	y+= 10;

	s = SvPV_nolen(get_sv("Team", FALSE ));
	sTag = SvPV_nolen( *av_fetch( StatTags, 1, false ) );
	int i = DrawTextMSZ( sTag, font, LEFTMARGIN, y+=LINEHEIGHT, 0, C_YELLOW, m_poBackground );
	DrawTextMSZ( s, font, LEFTMARGIN+i, y, 0, C_ORANGE, m_poBackground, false );

	s = SvPV_nolen(get_sv("Style", FALSE ));
	sTag = SvPV_nolen( *av_fetch( StatTags, 2, false ) );
	i = DrawTextMSZ( sTag, font, LEFTMARGIN2, y, 0, C_YELLOW, m_poBackground );
	DrawTextMSZ( s, font, LEFTMARGIN2+i, y, 0, C_ORANGE, m_poBackground, false );

	s = SvPV_nolen(get_sv("Age", FALSE ));
	sTag = SvPV_nolen( *av_fetch( StatTags, 3, false ) );
	i = DrawTextMSZ( sTag, font, LEFTMARGIN, y+=LINEHEIGHT, 0, C_YELLOW, m_poBackground );
	DrawTextMSZ( s, font, LEFTMARGIN+i, y, 0, C_ORANGE, m_poBackground, false );

	s = SvPV_nolen(get_sv("Weight", FALSE ));
	sTag = SvPV_nolen( *av_fetch( StatTags, 4, false ) );
	i = DrawTextMSZ( sTag, font, LEFTMARGIN2, y, 0, C_YELLOW, m_poBackground );
	DrawTextMSZ( s, font, LEFTMARGIN2+i, y, 0, C_ORANGE, m_poBackground, false );

	s = SvPV_nolen(get_sv("Height", FALSE ));
	sTag = SvPV_nolen( *av_fetch( StatTags, 5, false ) );
	i = DrawTextMSZ( sTag, font, LEFTMARGIN, y+=LINEHEIGHT, 0, C_YELLOW, m_poBackground );
	DrawTextMSZ( s, font, LEFTMARGIN+i, y, 0, C_ORANGE, m_poBackground, false );

	s = SvPV_nolen(get_sv("Shoe", FALSE ));
	sTag = SvPV_nolen( *av_fetch( StatTags, 6, false ) );
	i = DrawTextMSZ( sTag, font, LEFTMARGIN2, y, 0, C_YELLOW, m_poBackground );
	DrawTextMSZ( s, font, LEFTMARGIN2+i, y, 0, C_ORANGE, m_poBackground, false );

	m_sStory = SvPV_nolen(get_sv("Story", FALSE ));
	SDL_Rect oFlyingRect;
	oFlyingRect.x = LEFTMARGIN; 
	oFlyingRect.y = y+DESCMARGIN;
//.........这里部分代码省略.........
开发者ID:KAMI911,项目名称:openmortal,代码行数:101,代码来源:FighterStats.cpp

示例3: DrawLogoBlit

/* This code is deprecated, but available for speed comparisons */
void DrawLogoBlit(void)
{
    static int x = 0;
    static int y = 0;
    static int w, h;
    static int delta_x = 1;
    static int delta_y = 1;

    SDL_Rect dst;
    SDL_Surface *screen = SDL_GetVideoSurface();

    if ( global_image == NULL ) {
        SDL_Surface *temp;

        /* Load the image (could use SDL_image library here) */
        temp = SDL_LoadBMP(LOGO_FILE);
        if ( temp == NULL ) {
            return;
        }
        w = temp->w;
        h = temp->h;

        /* Convert the image into the screen format */
        global_image = SDL_CreateRGBSurface(
                           SDL_SWSURFACE,
                           w, h,
                           screen->format->BitsPerPixel,
                           screen->format->Rmask,
                           screen->format->Gmask,
                           screen->format->Bmask,
                           screen->format->Amask);
        if ( global_image ) {
            SDL_BlitSurface(temp, NULL, global_image, NULL);
        }
        SDL_FreeSurface(temp);

        /* Make sure that the texture conversion is okay */
        if ( ! global_image ) {
            return;
        }
    }

    /* Move the image around
           Note that we do not clear the old position.  This is because we
           perform a glClear() which clears the framebuffer and then only
           update the new area.
           Note that you can also achieve interesting effects by modifying
           the screen surface alpha channel.  It's set to 255 by default..
         */
    x += delta_x;
    if ( x < 0 ) {
        x = 0;
        delta_x = -delta_x;
    } else if ( (x+w) > screen->w ) {
        x = screen->w-w;
        delta_x = -delta_x;
    }
    y += delta_y;
    if ( y < 0 ) {
        y = 0;
        delta_y = -delta_y;
    } else if ( (y+h) > screen->h ) {
        y = screen->h-h;
        delta_y = -delta_y;
    }
    dst.x = x;
    dst.y = y;
    dst.w = w;
    dst.h = h;
    SDL_BlitSurface(global_image, NULL, screen, &dst);

    /* Show the image on the screen */
    SDL_UpdateRects(screen, 1, &dst);
}
开发者ID:luislasonbra,项目名称:bennugd-wii,代码行数:75,代码来源:testgl.c

示例4: move_cell

void move_cell(int place_x, int place_y, SDL_Surface * screen, SDL_Surface * sprite, t_tab tab, int theplacecursor, SDL_Rect totalplace[100], SDL_Surface * cell[100], int current_cell) {
    SDL_Event event;
    int keep = 1;
    int i;
    SDL_Rect place;
    place.x = place_x;
    place.y = place_y;
    while (keep) {
        SDL_WaitEvent(&event);
        switch (event.type) {
            case SDL_QUIT:
                SDL_Quit();
                break;
            case SDL_KEYDOWN:
                switch (event.key.keysym.sym) {

                    case SDLK_RIGHT:
                        if (place.x < 11 * SIZE_BLOC) {
                            //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
                            screen_editor(screen, theplacecursor);
                            place.x = place.x + SIZE_BLOC;

                            SDL_BlitSurface(sprite, NULL, screen, &place);
                            if (current_cell != 1) {
                                for (i = 1; i <= current_cell - 1; i++) {

                                    SDL_BlitSurface(cell[i], NULL, screen, &totalplace[i]);

                                }
                            }
                            SDL_Flip(screen);
                        }


                        break;
                    case SDLK_LEFT:
                        if (place.x > 0) {
                            //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
                            screen_editor(screen, theplacecursor);
                            place.x = place.x - SIZE_BLOC;
                            SDL_BlitSurface(sprite, NULL, screen, &place);
                            for (i = 1; i <= current_cell - 1; i++) {

                                SDL_BlitSurface(cell[i], NULL, screen, &totalplace[i]);

                            }
                            SDL_Flip(screen);
                        }

                        break;
                    case SDLK_UP:
                        if (place.y > 0) {
                            //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
                            screen_editor(screen, theplacecursor);
                            place.y = place.y - SIZE_BLOC;
                            SDL_BlitSurface(sprite, NULL, screen, &place);
                            for (i = 1; i <= current_cell - 1; i++) {

                                SDL_BlitSurface(cell[i], NULL, screen, &totalplace[i]);

                            }
                            SDL_Flip(screen);
                        }

                        break;
                    case SDLK_DOWN:
                        if (place.y < 10 * SIZE_BLOC) {
                            //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
                            screen_editor(screen, theplacecursor);
                            place.y = place.y + SIZE_BLOC;
                            SDL_BlitSurface(sprite, NULL, screen, &place);
                            for (i = 1; i <= current_cell - 1; i++) {

                                SDL_BlitSurface(cell[i], NULL, screen, &totalplace[i]);

                            }
                            SDL_Flip(screen);
                        }

                        break;
                    case SDLK_RETURN:

                        keep = 0;
                        break;
                    default:
                        break;
                }
        }
    }
    tab->x = place.x;
    tab->y = place.y;
}
开发者ID:floflowian,项目名称:Bomberman,代码行数:92,代码来源:map.c

示例5: bliterArrierePlan

void bliterArrierePlan(SDL_Surface *ecran, Camera camera, int largeurFenetre, int hauteurFenetre, Portion_Map world[][PROFONDEUR_MONDE], int tempsJour)
{
    int chunkX(0), chunkY(0), blocX(0), blocY(0);

    SDL_Rect positionBloc;
    SDL_Rect positionSoleil;
    SDL_Surface *soleil(IMG_Load("textures/ciel/soleil.png"));
    SDL_Surface *lune(IMG_Load("textures/ciel/lune.png"));
    SDL_Surface *pierreBackGround(IMG_Load("textures/ciel/backGroundPierre.png"));
    SDL_Surface *terreBackGround(IMG_Load("textures/ciel/backGroundTerre.png"));

    positionSoleil.x = largeurFenetre / 4;
    positionSoleil.y = hauteurFenetre / 4;

    if (tempsJour >= 32400 && tempsJour <= 75600)
    {
        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 119, 181, 254));
        SDL_BlitSurface(soleil, NULL, ecran, &positionSoleil);

        for (int x(0); x < LARGEUR_MONDE; x++)
        {
            for (int y(0); y < PROFONDEUR_MONDE; y++)
            {
                for (int a(0); a < LARGEUR_PARTIE_MAP; a++)
                {
                    for (int b(0); b < PROFONDEUR_PARTIE_MAP; b++)
                    {
                        world[x][y].blocs[a][b].luminosite = 15;
                    }
                }
            }
        }
    }
    else
    {
        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 4, 7, 10));
        SDL_BlitSurface(lune, NULL, ecran, &positionSoleil);

        for (int x(0); x < LARGEUR_MONDE; x++)
        {
            for (int y(0); y < PROFONDEUR_MONDE; y++)
            {
                for (int a(0); a < LARGEUR_PARTIE_MAP; a++)
                {
                    for (int b(0); b < PROFONDEUR_PARTIE_MAP; b++)
                    {
                        world[x][y].blocs[a][b].luminosite = 3;
                    }
                }
            }
        }
    }

    for (int x(0); x < LARGEUR_MONDE * LARGEUR_PARTIE_MAP * TAILLE_BLOCK; x += TAILLE_BLOCK)
    {
        for (int y(0); y < LARGEUR_MONDE * LARGEUR_PARTIE_MAP * TAILLE_BLOCK; y += TAILLE_BLOCK)
        {
            positionBloc.x = x - camera.posCamX;
            positionBloc.y = y - camera.posCamY;

            chunkX = (x / TAILLE_BLOCK) / LARGEUR_PARTIE_MAP;
            chunkY = (y / TAILLE_BLOCK) / PROFONDEUR_PARTIE_MAP;
            blocX = (x / TAILLE_BLOCK) - (chunkX * LARGEUR_PARTIE_MAP);
            blocY = (y / TAILLE_BLOCK) - (chunkY * PROFONDEUR_PARTIE_MAP);

            if ((chunkY * PROFONDEUR_PARTIE_MAP) + blocY > 54 && (chunkY * PROFONDEUR_PARTIE_MAP) + blocY <= 64 && world[chunkX][chunkY].blocs[blocX][blocY].type == AIR)
            {
                if (x > camera.posCamX - TAILLE_BLOCK && x < (camera.posCamX + largeurFenetre) + TAILLE_BLOCK)
                {
                    if (y > camera.posCamY - TAILLE_BLOCK && y < (camera.posCamY + hauteurFenetre) + TAILLE_BLOCK)
                    {
                        SDL_BlitSurface(terreBackGround, NULL, ecran, &positionBloc);
                    }
                }
            }
            else if ((chunkY * PROFONDEUR_PARTIE_MAP) + blocY > 64 && world[chunkX][chunkY].blocs[blocX][blocY].type == AIR)
            {
                SDL_BlitSurface(pierreBackGround, NULL, ecran, &positionBloc);
            }
        }
    }

    SDL_FreeSurface(soleil);
    SDL_FreeSurface(lune);
    SDL_FreeSurface(pierreBackGround);
    SDL_FreeSurface(terreBackGround);
}
开发者ID:SteriCraft,项目名称:TerraForma,代码行数:87,代码来源:environnement.cpp

示例6: runEditor


//.........这里部分代码省略.........


  txtWriteCenter(screen, FONTSMALL,STR_EDIT_STATUS, HSCREENW-115,HSCREENH+80);
  txtWriteCenter(screen, FONTSMALL, (changed)?STR_EDIT_UNSAVED:STR_EDIT_SAVED, HSCREENW-115,HSCREENH+89);

  txtWriteCenter(screen, FONTSMALL,fileName, HSCREENW,HSCREENH+110);

  txtWriteCenter(screen, FONTSMALL,STR_EDIT_CONTROLS, HSCREENW,HSCREENH-120);


  //Write which keys are used to cycle selected brick.
  txtWriteCenter(screen, FONTSMALL,STR_EDIT_PREVBRICK_KEY,HSCREENW-142,HSCREENH-80);
  txtWriteCenter(screen, FONTSMALL,STR_EDIT_NEXTBRICK_KEY,HSCREENW-88,HSCREENH-80);


  //Draw the currently selected brick.
  drawBrick(screen, selBrick,HSCREENW-125,HSCREENH-85);

  //Write brick name.
  txtWriteCenter(screen, FONTSMALL, str_brick_names[selBrick], HSCREENW-116,HSCREENH-56 );

  //Tell if we're placing teleport source or destination
  if(selBrick==TELESRC && teleState==0)
  {
    txtWriteCenter(screen, FONTSMALL, "(From)", HSCREENW-115,HSCREENH-41);
  } else if(teleState)
  {
    if(selBrick==TELESRC)
    {
      txtWriteCenter(screen, FONTSMALL, "(To)", HSCREENW-115,HSCREENH-41);
    } else {
      txtWriteCenter(screen, FONTSMALL, "(Target)", HSCREENW-115,HSCREENH-41);
    }
    drawPath(screen, teleSrcPos[0], teleSrcPos[1], cur.x, cur.y, 1);
  }

  //Draw all the telepaths.
  drawAllTelePaths(screen, pf.levelInfo->teleList);


  //Draw switchpath we hover above
  listItem* t = &pf.levelInfo->switchList->begin;
  while( LISTFWD(pf.levelInfo->switchList, t) )
  {
    telePort_t* tp=(telePort_t*)t->data;
    if(cur.x == tp->sx && cur.y == tp->sy)
    {
      drawTelePath( screen, tp, 1 );
    }
  }
  //Draw all switchpaths
  drawAllTelePaths(screen, pf.levelInfo->switchList);

  if( (getInpPointerState()->timeSinceMoved < POINTER_SHOW_TIMEOUT) && (changed > 0) )
  {
    drawSprite(screen, saveBtnSprite, HSCREENW-145, HSCREENH+42 );
  }

  //Draw brick-selection
  if( editorState == EDITOR_BRICKS_SELECTION )
  {
    SDL_BlitSurface(selBrickBG , NULL, screen, &(setting()->bgPos) );

    //Draw bricks in a 6*4 grid
    int px,py,bnum=BRICKSBEGIN;
    static int brickSelOfX = HSCREENW - 78 + 8;
    static int brickSelOfY = HSCREENH - 54 + 8;
    for(py=0;py < 4; py++)
    {
      for(px=0; px < 6; px++)
      {
        if( bnum > NUMTILES )
          break;
        selBrickRect.x = brickSelOfX+(24*px);
        selBrickRect.y = brickSelOfY+(24*py);
        selBrickRect.w = selBrickRect.x+20;
        selBrickRect.h = selBrickRect.y+20;


        //We set bricks on mouseover, this way we get the description too (maybe punch a hole in the dots where the text is?)
        if( isPointerInBox(&selBrickRect) )
        {
          selBrick=bnum;
        }

        //We continue back to the main editor
        if( isPointerClicked() )
        {
          resetMouseBtn();
          editorState=EDITOR_MAIN;
        }

        drawBrick(screen, bnum, selBrickRect.x, selBrickRect.y );
        bnum++;
      }
    }
  }

  return(STATEEDIT);
}
开发者ID:revcozmo,项目名称:Wizznic,代码行数:101,代码来源:leveleditor.c

示例7: map_editor

int map_editor(SDL_Surface *screen) {
    int i, j;

    FILE* fichier = NULL;
    fichier = fopen("map/map_default.txt", "w+"); //opens the target file that will contain the custom map
    fprintf(fichier, "12:12\n");
    int placecursor = 5;
    int valuecursor = 1;
    int current_cell = 1;
    screen_editor(screen, placecursor);
    SDL_Event event;
    int keep = 1;
    t_tab tab = malloc(sizeof (struct s_tab));
    SDL_Rect place[100];
    SDL_Surface * cell[144] = {CELL_EMPTY}; //creates as much surfaces as possible
    t_cell_type grid[12][12];   //the grid will be used to write the cell types in the file
    for (i = 0; i <= 11; i++) {
        for (j = 0; j <= 11; j++) {
            grid[i][j] = 0;
        }
    }
    for (i = 0; i <= 100; i++) { //each surface will be firstly located in (0,0)
        place[i].x = 0;
        place[i].y = 0;
    }
    tab->x = 0;
    tab->y = 0;
    tab->sprite_type = NULL;
    tab->empty = 0;
    tab->player_set=0;

    int white_bloc = ((12 * SIZE_BLOC) - 6 * SIZE_BLOC) / 4;
    while (keep != 0) {
        tab->empty = 0;
        SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
        screen_editor(screen, placecursor);

        if (current_cell > 1) { //Sticks all the cells the user has defined
            for (i = 1; i <= current_cell - 1; i++) {

                SDL_BlitSurface(cell[i], NULL, screen, &place[i]);

            }
        }
        SDL_Flip(screen);
        SDL_WaitEvent(&event);

        switch (event.type) {


            case SDL_QUIT:
                return 2;
                break;

            case SDL_KEYDOWN:

                switch (event.key.keysym.sym) {

                    case SDLK_RIGHT: //move the cursor that chooses which cell type to stick
                        if (placecursor < 10 * SIZE_BLOC) {
                            placecursor = placecursor + 0.25 * white_bloc + SIZE_BLOC;
                            valuecursor++;
                        }

                        break;
                    case SDLK_LEFT:
                        if (placecursor > 5) {
                            valuecursor--;
                            placecursor = placecursor - 0.25 * white_bloc - SIZE_BLOC;
                        }

                        break;
                    case SDLK_RETURN: //validates the choice of a cell type

                        if (valuecursor == 1) {
                            tab->sprite_type = IMG_Load(IMG_MAP_STONE);
                            tab->value_sprite = 21;
                        } else if (valuecursor == 2) {
                            tab->sprite_type = IMG_Load(IMG_MAP_TREE);
                            tab->value_sprite = 22;
                        } else if (valuecursor == 3) {
                            tab->sprite_type = IMG_Load(IMG_MAP_KEY);
                            tab->value_sprite = 8;
                        } else if (valuecursor == 4) {
                            tab->sprite_type = IMG_Load(IMG_MAP_CASE);
                            tab->value_sprite = 4;
                        } else if (valuecursor == 5) {
                            tab->sprite_type = IMG_Load(IMG_MAP_CLOSED_DOOR);
                            tab->value_sprite = 10;
                        } else if (valuecursor == 6) {
                            tab->sprite_type = IMG_Load(IMG_MONSTER_DOWN);
                            tab->value_sprite = 6;
                        } else if (valuecursor == 7) {
                            tab->sprite_type = IMG_Load(IMG_PLAYER_DOWN);
                            tab->value_sprite = 3;
                            if(tab->player_set==1){break;} //check if a player is already placed
                            tab->player_set=1;
                        } else if (valuecursor == 7) {
                            tab->sprite_type = IMG_Load(IMG_PLAYER_DOWN);
                            tab->value_sprite = 3;
//.........这里部分代码省略.........
开发者ID:floflowian,项目名称:Bomberman,代码行数:101,代码来源:map.c

示例8: main

int main()
{
    SDL_Surface *temp;
    SDL_Surface *background;
    SDL_Rect src, dest;
    int frames;

    /* Initialize SDL's video system and check for errors. */
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
	printf("Unable to initialize SDL: %s\n", SDL_GetError());
	return 1;
    }

    /* Make sure SDL_Quit gets called when the program exits! */
    atexit(SDL_Quit);

    /* Attempt to set a 640x480 hicolor (16-bit) video mode with
       a double buffer. Note that on some display targets you're actually
       better off without these options. */
    screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF | SDL_HWSURFACE);
    if (screen == NULL) {
	printf("Unable to set video mode: %s\n", SDL_GetError());
	return 1;
    }

    /* Load the background image and convert it to the display's
       pixel format. This conversion will drastically improve the
       performance of SDL_BlitSurface, as it will not have to
       convert the surface on the fly. */
    temp = SDL_LoadBMP("background.bmp");
    background = SDL_DisplayFormat(temp);
    if (background == NULL) {
	printf("Unable to load bitmap.\n");
	return 1;
    }
    SDL_FreeSurface(temp);

    /* Load the penguin image. */
    temp = SDL_LoadBMP("smallpenguin.bmp");
    if (temp == NULL) {
	printf("Unable to load bitmap.\n");
	return 1;
    }

    /* Set the penguin's colorkey. Ask for RLE acceleration,
       a technique which can significantly speed up colorkey
       blits. */
    SDL_SetColorKey(temp,
		    SDL_SRCCOLORKEY | SDL_RLEACCEL,
		    (Uint16) SDL_MapRGB(temp->format, 0, 0, 255));

    /* Convert the penguin to the display's format. We do this after
       we set the colorkey, since colorkey blits can sometimes be
       optimized for a particular display. */
    penguin = SDL_DisplayFormat(temp);
    if (penguin == NULL) {
	printf("Unable to convert bitmap.\n");
	return 1;
    }
    SDL_FreeSurface(temp);

    /* Initialize the penguin position data. */
    init_penguins();

    /* Animate 300 frames (approximately 10 seconds). */
    for (frames = 0; frames < 300; frames++) {

	/* Draw the background image. */
	src.x = 0;
	src.y = 0;
	src.w = background->w;
	src.h = background->h;
	dest = src;

	SDL_BlitSurface(background, &src, screen, &dest);

	/* Put the penguins on the screen. */
	draw_penguins();

	/* Ask SDL to swap the back buffer to the screen. */
	SDL_Flip(screen);

	/* Move the penguins for the next frame. */
	move_penguins();
    }

    /* Free the memory that was allocated to the bitmap. */
    SDL_FreeSurface(background);
    SDL_FreeSurface(penguin);

    return 0;
}
开发者ID:jackmanlabs,项目名称:sdl-sparks,代码行数:92,代码来源:sdl-anim2.c

示例9: fprintf

/******************************************************************************
Description.: this is the main worker thread
              it loops forever, grabs a fresh frame, decompressed the JPEG
              and displays the decoded data using SDL
Input Value.:
Return Value:
******************************************************************************/
void *worker_thread(void *arg)
{
    int frame_size = 0, firstrun = 1;

    SDL_Surface *screen = NULL, *image = NULL;
    decompressed_image rgbimage;

    /* initialze the buffer for the decompressed image */
    rgbimage.buffersize = 0;
    rgbimage.buffer = NULL;

    /* initialze the SDL video subsystem */
    if(SDL_Init(SDL_INIT_VIDEO) < 0) {
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
        exit(EXIT_FAILURE);
    }

    /* just allocate a large buffer for the JPEGs */
    if((frame = malloc(4096 * 1024)) == NULL) {
        OPRINT("not enough memory for worker thread\n");
        exit(EXIT_FAILURE);
    }

    /* set cleanup handler to cleanup allocated ressources */
    pthread_cleanup_push(worker_cleanup, NULL);

    while(!pglobal->stop) {
        DBG("waiting for fresh frame\n");
        pthread_cond_wait(&pglobal->in[plugin_number].db_update, &pglobal->in[plugin_number].db);

        /* read buffer */
        frame_size = pglobal->in[plugin_number].size;
        memcpy(frame, pglobal->in[plugin_number].buf, frame_size);

        pthread_mutex_unlock(&pglobal->in[plugin_number].db);

        /* decompress the JPEG and store results in memory */
        if(decompress_jpeg(frame, frame_size, &rgbimage)) {
            DBG("could not properly decompress JPEG data\n");
            continue;
        }

        if(firstrun) {
            /* create the primary surface (the visible window) */
            screen = SDL_SetVideoMode(rgbimage.width, rgbimage.height, 0, SDL_ANYFORMAT | SDL_HWSURFACE);
            SDL_WM_SetCaption("MJPG-Streamer Viewer", NULL);

            /* create a SDL surface to display the data */
            image = SDL_AllocSurface(SDL_SWSURFACE, rgbimage.width, rgbimage.height, 24,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
                                     0x0000FF, 0x00FF00, 0xFF0000,
#else
                                     0xFF0000, 0x00FF00, 0x0000FF,
#endif
                                     0);

            /* copy the decoded data across */
            memcpy(image->pixels, rgbimage.buffer, rgbimage.width * rgbimage.height * 3);
            free(rgbimage.buffer);

            /* now, that we know the dimensions, we can directly copy to the right surface */
            rgbimage.buffer = image->pixels;
            rgbimage.buffersize = rgbimage.width * rgbimage.height * 3;

            firstrun = 0;
        }

        /* copy the image to the primary surface */
        SDL_BlitSurface(image, NULL, screen, NULL);

        /* redraw the whole surface */
        SDL_Flip(screen);
    }

    pthread_cleanup_pop(1);

    /* get rid of the image */
    SDL_FreeSurface(image);

    return NULL;
}
开发者ID:PRINTR3D,项目名称:mjpg-streamer-fixed,代码行数:88,代码来源:output_viewer.c

示例10: doSDL

int doSDL(void) {
    SDL_Surface *screen = NULL;
    SDL_Surface *rot = NULL;
    const SDL_VideoInfo *videoInfo = NULL;
    double scale;
    int prevValue = 0;
    int rc = 0;

    pthread_t thread[7];
    void *status[7];

    pthread_mutex_init(&mutexVALUE, NULL); 
    pthread_mutex_init(&mutexIMAGE, NULL);

    pthread_create(&thread[0], NULL, take_screen, NULL);

    /*-----------------------------------------------------------------*/

    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        fprintf(stderr, "SDL_Init failed - %s\n", SDL_GetError());
        return 1;
    }

    /*-----------------------------------------------------------------*/

    videoInfo = SDL_GetVideoInfo();

    if (videoInfo == 0)
    {
        fprintf(stderr, "SDL_GetVideoInfo failed - %s\n", SDL_GetError());
        SDL_Quit();
        return 1;
    }

    /*-----------------------------------------------------------------*/

    rc = pthread_join(thread[0], &status[0]);

    pthread_create(&thread[1], NULL, get_screen, NULL);

    pthread_create(&thread[0], NULL, take_screen, NULL);

    rc = pthread_join(thread[1], &status[1]);

    pthread_create(&thread[2], NULL, load_image, NULL);
    
    rc = pthread_join(thread[0], &status[0]);

    /*-----------------------------------------------------------------*/
while(1){
    pthread_create(&thread[1], NULL, get_screen, NULL);

    pthread_create(&thread[0], NULL, take_screen, NULL);

    pthread_create(&thread[3], NULL, get_height, NULL);

    rc = pthread_join(thread[3], &status[3]);

    rc = pthread_join(thread[1], &status[1]);

    pthread_create(&thread[2], NULL, load_image, NULL);

    rc = pthread_join(thread[2], &status[2]);

    if (value != image->h) {
        //scale = (image->w)/(videoInfo->current_w);
        scale = 1;
	if (prevValue != image->h) {
	    screen = SDL_SetVideoMode((image->h)*scale,
		                      (image->w)*scale,
		                      videoInfo->vfmt->BitsPerPixel,
		                      SDL_SWSURFACE|SDL_DOUBLEBUF);
	}
        rot = rotozoomSurface( image, 90, scale, SMOOTHING_ON );
    }

    else if (value == image->h) {
	//scale = (image->h)/(videoInfo->current_h);
        scale = 0.5;
	if (prevValue != image->h) {
	    screen = SDL_SetVideoMode((image->w)*scale,
		                      (image->h)*scale,
		                      videoInfo->vfmt->BitsPerPixel,
		                      SDL_SWSURFACE|SDL_DOUBLEBUF);
	}
        rot = rotozoomSurface( image, 0, scale, SMOOTHING_ON );
    }

    SDL_FreeSurface(image);

    SDL_BlitSurface(rot, NULL, screen, 0);

    //SDL_Flip(screen);
    SDL_UpdateRect(screen, 0, 0, 0, 0);

    SDL_FreeSurface(rot);

    prevValue = value;

//.........这里部分代码省略.........
开发者ID:bass0324,项目名称:Senior_Design,代码行数:101,代码来源:sdl_test.c

示例11: main

int main(int argc, char *argv[])
{
	SDL_Surface *screen;
	TTF_Font *font;
	SDL_Surface *text;
	int ptsize;
	int done;
    SDL_Color mybackcolor = {0xff, 0, 0, 0};
    SDL_Color myforecolor = {0, 0, 0xff, 0};
	SDL_Color *forecol;
	SDL_Color *backcol;
	SDL_Rect dstrect;
	SDL_Event event;
	char *message;

	/* Default is black and white */
	forecol = &myforecolor;
	backcol = &mybackcolor;

	/* Initialize SDL */
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
		return(2);
	}

	/* Initialize the TTF library */
	if ( TTF_Init() < 0 ) {
		fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError());
		SDL_Quit();
		return(2);
	}

	/* Open the font file with the requested point size */
    ptsize = DEFAULT_PTSIZE;
	font = TTF_OpenFont(DEFAULT_FONT, ptsize);
	if ( font == NULL ) {
		fprintf(stderr, "Couldn't load %d pt font from %s: %s\n",
					ptsize, DEFAULT_FONT, SDL_GetError());
		cleanup(2);
	}

	/* Set a 640x480x8 video mode */
	screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
	if ( screen == NULL ) {
		fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
							SDL_GetError());
		cleanup(2);
	}

	/* Clear the background to background color */
	SDL_FillRect(screen, NULL,
			SDL_MapRGB(screen->format, backcol->r, backcol->g, backcol->b));
	SDL_UpdateRect(screen, 0, 0, 0, 0);

	/* Render and center the message */
    message = DEFAULT_TEXT;

	text = TTF_RenderText_Shaded(font,message,*forecol,*backcol);
	if ( text == NULL ) {
		fprintf(stderr, "Couldn't render text: %s\n", SDL_GetError());
		TTF_CloseFont(font);
		cleanup(2);
	}
	dstrect.x = (screen->w - text->w)/2;
	dstrect.y = (screen->h - text->h)/2;
	dstrect.w = text->w;
	dstrect.h = text->h;
	printf("Font is generally %d big, and string is %hd big\n",
						TTF_FontHeight(font), text->h);

	/* Blit the text surface */
	if ( SDL_BlitSurface(text, NULL, screen, &dstrect) < 0 ) {
		fprintf(stderr, "Couldn't blit text to display: %s\n", 
								SDL_GetError());
		TTF_CloseFont(font);
		cleanup(2);
	}
	SDL_UpdateRect(screen, 0, 0, 0, 0);

	/* Wait for a keystroke, and blit text on mouse press */
	done = 0;
	while ( ! done ) {
		if ( SDL_WaitEvent(&event) < 0 ) {
			fprintf(stderr, "SDL_PullEvent() error: %s\n",
								SDL_GetError());
			done = 1;
			continue;
		}
		switch (event.type) {
			case SDL_MOUSEBUTTONDOWN:
				dstrect.x = event.button.x - text->w/2;
				dstrect.y = event.button.y - text->h/2;
				dstrect.w = text->w;
				dstrect.h = text->h;
				if ( SDL_BlitSurface(text, NULL, screen,
							&dstrect) == 0 ) {
					SDL_UpdateRects(screen, 1, &dstrect);
				} else {
					fprintf(stderr,
					"Couldn't blit text to display: %s\n", 
//.........这里部分代码省略.........
开发者ID:doremi,项目名称:sdl,代码行数:101,代码来源:showfont.c

示例12: SDL_FreeSurface

// This should be rewritten
void ScoreScrollNode::renderText()
{
	// Init variables
	SDL_Surface *name, *points, *place, *surface;
	surface = _screen->game()->buffer();

	Highscore *hs;
	std::stringstream str, str_place;

	// The texts position on text
	SDL_Rect position;
	position.x = 0;

	// Get scores
	highscore_list &scores = _screen->menu()->manager.get();

	// Create surface on which to draw stuff
	int num_scores = scores.size();
	int height = num_scores * 2 * _font_height;

	_height = height;

	// Kill old stuff
	for ( score_triplet_list::iterator iter = _scores.begin(); iter != _scores.end(); iter++ )
	{
		SDL_Surface **surfaces = (*iter);
		SDL_FreeSurface(surfaces[0]);
		SDL_FreeSurface(surfaces[1]);
		SDL_FreeSurface(surfaces[2]);
		delete [] surfaces;
	}

	_scores.erase(_scores.begin(), _scores.end());

	int i = 0;
	for ( highscore_list::iterator iter = scores.begin(); iter != scores.end(); iter++, i++ )
	{
		hs = *iter;
		str << hs->score << " points";
		str_place << (i + 1) << ". ";

		// Render texts
		place = TTF_RenderText_Blended(_font, str_place.str().c_str(), _name_color);
		name = TTF_RenderUNICODE_Blended(_font, hs->name, _name_color);
		points = TTF_RenderText_Blended(_font, str.str().c_str(), _score_color);

		SDL_Surface **surfaces = new SDL_Surface*[3];
		surfaces[0] = place;
		surfaces[1] = name;
		surfaces[2] = points;
		_scores.push_back(surfaces);

		str.str("");
		str_place.str("");
	}

	// draw()
	// the area on which we draw ourselves
	SDL_Rect rect = _screen->makeRect(_pos);

	SDL_FreeSurface(_image);
	_image = SDL_CreateRGBSurface(surface->flags, _pos.w, _pos.h, surface->format->BitsPerPixel, 0, 0, 0, 0);
	SDL_BlitSurface(_screen->menu()->overlay(), &rect, _image, NULL);

	// unit height is the height of one score element
	int unit_height = _font_height * 2;

	int start_score = _scroll_rect.y / unit_height;

	// Check bounds for end_score
	int end_score = _pos.h / unit_height + 2 + start_score;
	end_score = (end_score > _scores.size()) ? _scores.size() : end_score;

	SDL_Rect cp_position;
	position.x = 0;
	position.y = start_score * unit_height - _scroll_rect.y;

	score_triplet_list::iterator iter, to;
	iter = _scores.begin() + start_score;
	to = _scores.begin() + end_score;

	for (; iter != to; iter++)
	{
		SDL_Surface **surfaces = (*iter);

		// Place
		cp_position = position;
		SDL_BlitSurface(surfaces[0], NULL, _image, &cp_position);

		// Name
		position.x += surfaces[0]->clip_rect.w;
		cp_position = position;
		SDL_BlitSurface(surfaces[1], NULL, _image, &cp_position);

		// Points
		position.x -= surfaces[0]->clip_rect.w;
		position.y += _font_height;
		cp_position = position;
		SDL_BlitSurface(surfaces[2], NULL, _image, &cp_position);
//.........这里部分代码省略.........
开发者ID:davehorner,项目名称:KM-Bubble-Shooter,代码行数:101,代码来源:scorescrollnode.cpp

示例13: IMG_SavePNG_RW


//.........这里部分代码省略.........
			if (!fmt->Amask) { /* check for 32bit but no alpha */
				funky_format=1; 
			}else{
				/* Check for ARGB/ABGR/GBAR/RABG/etc surfaces.*/
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
				if(fmt->Rmask!=0xFF000000
				|| fmt->Gmask!=0x00FF0000
				|| fmt->Bmask!=0x0000FF00
				|| fmt->Amask!=0x000000FF){
#else
				if(fmt->Rmask!=0x000000FF
				|| fmt->Gmask!=0x0000FF00
				|| fmt->Bmask!=0x00FF0000
				|| fmt->Amask!=0xFF000000){
#endif
					funky_format=1;
				}
			}
		}else{ /* 555 or 565 16 bit color */
			funky_format=1;
		}
		if (funky_format) {
			/* Allocate non-funky format, and copy pixeldata in*/
			if(fmt->Amask){
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
				tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24,
										0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
#else
				tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24,
										0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
#endif
			}else{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
				tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24,
										0xff0000, 0x00ff00, 0x0000ff, 0x00000000);
#else
				tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24,
										0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000);
#endif
			}
			if(!tempsurf){
				SDL_SetError("Couldn't allocate temp surface");
				goto savedone;
			}
			if(surf->flags&SDL_SRCALPHA){
				temp_alpha=fmt->alpha;
				used_alpha=1;
				SDL_SetAlpha(surf,0,255); /* Set for an opaque blit */
			}else{
				used_alpha=0;
			}
			if(SDL_BlitSurface(surf,NULL,tempsurf,NULL)!=0){
				SDL_SetError("Couldn't blit surface to temp surface");
				SDL_FreeSurface(tempsurf);
				goto savedone;
			}
			if (used_alpha) {
				SDL_SetAlpha(surf,SDL_SRCALPHA,(Uint8)temp_alpha); /* Restore alpha settings*/
			}
			for(i=0;i<tempsurf->h;i++){
				row_pointers[i]= ((png_byte*)tempsurf->pixels) + i*tempsurf->pitch;
			}
			if(SDL_MUSTLOCK(tempsurf)){
				SDL_LockSurface(tempsurf);
			}
			png_write_image(png_ptr, row_pointers);
			if(SDL_MUSTLOCK(tempsurf)){
				SDL_UnlockSurface(tempsurf);
			}
			SDL_FreeSurface(tempsurf);
		} else {
			for(i=0;i<surf->h;i++){
				row_pointers[i]= ((png_byte*)surf->pixels) + i*surf->pitch;
			}
			if(SDL_MUSTLOCK(surf)){
				SDL_LockSurface(surf);
			}
			png_write_image(png_ptr, row_pointers);
			if(SDL_MUSTLOCK(surf)){
				SDL_UnlockSurface(surf);
			}
		}
	}

	png_write_end(png_ptr, NULL);
	ret=0; /* got here, so nothing went wrong. YAY! */

savedone: /* clean up and return */
	png_destroy_write_struct(&png_ptr,&info_ptr);
	if (palette) {
		free(palette);
	}
	if (palette_alpha) {
		free(palette_alpha);
	}
	if (row_pointers) {
		free(row_pointers);
	}
	return ret;
}
开发者ID:ytomino,项目名称:glcaml,代码行数:101,代码来源:IMG_savepng.c

示例14: main

int main()
{
    const int FPS = 60;
    const int FRAME_TIME = 1000/FPS; //Temps entre chaque frame en ms
    
    long time = 0, lastTime = 0;
    
    SDL_Surface *ecran = NULL, *ballonTex[12];
    SDL_Rect posBallon[12];
    SDL_Event event;

    SDL_Init(SDL_INIT_VIDEO);

    ecran = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Robocup Python POC", NULL);

    ballonTex[0] = IMG_Load("images/football.png");
    ballonTex[1] = IMG_Load("images/football_red.png");
    if(ballonTex != NULL){
	    
	    StrategieEngine strategie; //Initialiseur de l'engin de stratégie

	    int exit = 0;
	    while (!exit){

		time = SDL_GetTicks(); //Temps depuis l'execution du programme

		GameState gameState;

		gameState.time = time;

		strategie.setGameState(gameState); //Envoi de l'état du jeu

		if(time - lastTime > FRAME_TIME){ //Voir s'il est temps de dessiner le prochain frame
			struct StrategyState pyGame = strategie.getState(); //Reception de l'état du moteur de stratégie

			//Affichage
			SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));	
			
			for(int b = 0; b<2; b++){
				setPosition(ballonTex[b], &posBallon[b], pyGame.players[b].x * ecran->w/2 + ecran->w/2, pyGame.players[b].y * ecran->h/2 + ecran->h/2);
			
				SDL_BlitSurface(ballonTex[b], NULL, ecran, &posBallon[b]);

			}

			SDL_Flip(ecran);

			lastTime = time;
		}
		else{
			SDL_Delay(FRAME_TIME - (time - lastTime)); //Attendre jusqu'au prochain frame
		}

		//Gestion d'events (Dans ce cas fermeture de fenêtre)
		SDL_PollEvent(&event); 
		switch(event.type)
		{
		    case SDL_QUIT:
			exit = 1;
			break;
		}

	    }
    }
    else{
	printf("Cannot find \"football.png\". Exiting...\n");
    }
    for(int s = 0; s < 2; s++){
	SDL_FreeSurface(ballonTex[s]);
    }
    
    SDL_Quit();

    return EXIT_SUCCESS;
}
开发者ID:felixpelletier,项目名称:RuleSSL_Python,代码行数:76,代码来源:main.cpp

示例15: SDL_BlitSurface

void Sprite::draw(SDL_Surface * screen){
  SDL_BlitSurface(*img, NULL, screen, *edge);
}
开发者ID:BastionFennell,项目名称:BWI-GUI,代码行数:3,代码来源:Sprite.cpp


注:本文中的SDL_BlitSurface函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。