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


C++ SDL_RenderCopyEx函数代码示例

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


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

示例1: Render

void Render () {
	policeDest.x = frameX.p - (POLICE_WIDTH / 2);
	policeDest.y = frameY.p - (POLICE_HEIGHT / 2);

	float angle = atan2(-frameY.v, -frameX.v) * (180.0 / M_PI);

	// Clear frame to black
	SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
	SDL_RenderClear(renderer);

	// Draw police car
	SDL_RenderCopyEx(renderer, police, NULL, &policeDest, angle, NULL, SDL_FLIP_NONE);

	// Draw vectors
	SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
	SDL_RenderDrawLine(renderer, frameX.p, frameY.p, frameX.p+(frameX.a/5), frameY.p+(frameY.a/5));
	SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
	SDL_RenderDrawLine(renderer, frameX.p, frameY.p, frameX.p+(frameX.v/5), frameY.p+(frameY.v/5));

	// Flip frame
	SDL_RenderPresent(renderer);
}
开发者ID:chronzerg,项目名称:PID-Demo,代码行数:22,代码来源:main.c

示例2: UpdateScreen

/* Update (redraw) the screen*/
inline void UpdateScreen(double steer_angle, unsigned char direction, unsigned char pwm, unsigned char speed) {

	SDL_RenderClear(sdlRenderer); // trick: we don't need clear the render while updated textures are placed on updated background.

	/* Draw meters area */
	SDL_RenderCopy(sdlRenderer, sdlSpeedometerTexture, NULL, &sdlSpeedometerDstrect);
	SDL_RenderCopy(sdlRenderer, sdlPwmTexture, NULL, &sdlPwmDstrect);

	SDL_RenderCopyEx(sdlRenderer, sdlMeterArrowTexture, NULL, &sdlMeterArrowDstrect, ( (double) pwm ) - 135.0, &sdlMeterArrowCenterPoint, 0);
	SDL_RenderCopyEx(sdlRenderer, sdlPwmArrowTexture, NULL, &sdlPwmArrowDstrect, ( (double) speed ) - 135.0, &sdlPwmArrowCenterPoint, 0);

	/* Draw car scheme */
	SDL_RenderCopy(sdlRenderer, sdlCarTexture, NULL, &sdlCarDstrect);

	SDL_RenderCopyEx(sdlRenderer, sdlWheelTexture, NULL, &sdlLeftWheelDstrect, steer_angle, NULL, 0);
	SDL_RenderCopyEx(sdlRenderer, sdlWheelTexture, NULL, &sdlRightWheelDstrect, steer_angle, NULL, SDL_FLIP_HORIZONTAL);

	switch (direction) {
	case FORWARD:
		SDL_RenderCopyEx(sdlRenderer, sdlArrowTexture, NULL, &sdlRightArrowDstrect, 0, NULL, 0);
		SDL_RenderCopyEx(sdlRenderer, sdlArrowTexture, NULL, &sdlLeftArrowDstrect, 0, NULL, 0);
		//WriteText(5, 250, "FORWARD!", 26, sdlBlack); // debug
		break;
	case BACKWARD:
		SDL_RenderCopyEx(sdlRenderer, sdlArrowTexture, NULL, &sdlRightArrowDstrect, 0, NULL, SDL_FLIP_VERTICAL);
		SDL_RenderCopyEx(sdlRenderer, sdlArrowTexture, NULL, &sdlLeftArrowDstrect, 0, NULL, SDL_FLIP_VERTICAL);
		//WriteText(5, 250, "BACKWARD!", 26, sdlBlack); // debug
		break;
	case NONE:
		break;
	}

	SDL_RenderCopy(sdlRenderer, sdlTextTexture, NULL, &sdlTextDstrect);

	SDL_RenderPresent(sdlRenderer);
}
开发者ID:jesstr,项目名称:linux-wifibot-client,代码行数:37,代码来源:graphic.c

示例3: SDL_QueryTexture

// Blit to screen
bool ModuleRender::Blit(SDL_Texture* texture, int x, int y, SDL_Rect* section, float speed, double angle, int pivot_x, int pivot_y )
{
	bool ret = true;
	SDL_Rect rect;
	rect.x = (int) (camera.x * speed) + x * SCREEN_SIZE;
	rect.y = (int) (camera.y * speed) + y * SCREEN_SIZE;

	if(section != NULL)
	{
		rect.w = section->w;
		rect.h = section->h;
	}
	else
	{
		SDL_QueryTexture(texture, NULL, NULL, &rect.w, &rect.h);
	}

	rect.w *= SCREEN_SIZE;
	rect.h *= SCREEN_SIZE;

	SDL_Point* p = NULL;
	SDL_Point pivot;

	if(pivot_x != INT_MAX && pivot_y != INT_MAX)
	{
		pivot.x = pivot_x;
		pivot.y = pivot_y;
		p = &pivot;
	}

	if(SDL_RenderCopyEx(renderer, texture, section, &rect, angle, p, SDL_FLIP_NONE) != 0)
	{
		LOG("Cannot blit to screen. SDL_RenderCopy error: %s", SDL_GetError());
		ret = false;
	}

	return ret;
}
开发者ID:Jconrega,项目名称:PinBall2D,代码行数:39,代码来源:ModuleRender.cpp

示例4: SDL_SetRenderDrawColor

void GraphicsSystem::step(float /*delta_time*/)
{
	SDL_SetRenderDrawColor(_renderer, 0x00, 0x00, 0x5B, 0xFF);
	SDL_RenderClear(_renderer);

	for (unsigned int id : _entities) {
		Graphics *g = _entitymanager->get_component<Graphics>(id);
		if (!g->is_visible) {
			continue;
		}

		Transform *transform = _entitymanager->get_component<Transform>(id);

		/* create destination rect using the desired position
		 * and the texture's dimensions */
		SDL_Rect dest;
		dest.x = (int)transform->position.x;
		dest.y = (int)transform->position.y;
		dest.w = (int)(g->texture->getWidth() * transform->scale.x);
		dest.h = (int)(g->texture->getHeight() * transform->scale.y);

		const float radians_to_degrees = 57.324841f;
		const float rotation_degrees = transform->rotation.GetAngle() * radians_to_degrees;
		SDL_Point zero{ 0, 0 };
		bool success = SDL_RenderCopyEx(_renderer, g->texture->getTexture(), nullptr,
			&dest, rotation_degrees, &zero, SDL_FLIP_NONE) == 0;

		assert2(success, "Failed to render texture '%s'. SDL error: %s",
			g->texture->getName().c_str(), SDL_GetError());
	}

	for (auto& post_render_callback : _post_render_callbacks)
	{
		post_render_callback.function();
	}

	SDL_RenderPresent(_renderer);
}
开发者ID:ivarboms,项目名称:Objectless,代码行数:38,代码来源:GraphicsSystem.cpp

示例5: if

void Planet::Draw(b2Body *body) const
{
	if (Game::instance().SelectedLevel() == Game::Levels::INF)
	{
		Drawable::Draw(body);
	}

	static SDL_Point rot;
	rot.x = 0;
	rot.y = 2;
	if (Game::instance().SelectedWeapon() == Bomb::BombType::LASER)
	{
		laser_->Draw();
	}
	else if (weaponAim_.x != 0 || weaponAim_.y != 0)
	{
		b2Vec2 p1 = Screen::instance().toPixels(GetBody()->GetPosition(), true);
		unsigned int px = Screen::instance().pixelsPerMeter();

		SDL_Rect dst;
		dst.x = p1.x;
		dst.y = p1.y;
		dst.w = weaponAim_.Length() * px;
		dst.h = 5;

		float32 angle = (180 * atan2(weaponAim_.y, weaponAim_.x) / M_PI);
#ifdef __ANDROID__
		// There might be a bug in SDL...
		angle = -angle;
#endif
		SDL_RenderCopyEx(Screen::instance().renderer(), texture_, NULL, &dst, angle, &rot, SDL_FLIP_NONE);
	}

	if (Game::instance().SelectedLevel() != Game::Levels::INF)
	{
		Drawable::Draw(body);
	}
}
开发者ID:Deraen,项目名称:ohj2710,代码行数:38,代码来源:Planet.cpp

示例6: SDL_RenderCopyEx

void Animation::Return_end(int x, int y, int angle, bool more, SDL_Renderer* render)
{
    if(more==true)
    {
        m_currentTime=SDL_GetTicks();
        SDL_Rect Destination{x, y, m_img_width, m_img_height};
        SDL_RenderCopyEx(render,m_sprite,&m_vector_frames[m_vector_index],&Destination,angle,NULL,m_flip);

        if(m_currentTime - m_startTime >= m_frame_duration)
        {
            if(m_return==false)
            {
                m_vector_index++;
            }
            else
                if(m_return==true)
                {
                    m_vector_index--;
                }

            if(unsigned(m_vector_index) == m_vector_frames.size())
            {
                m_vector_index--;
                m_return=true;
            }
            else
                if(m_vector_index == 0)
                {
                    m_return=false;
                }
            m_startTime = m_currentTime;
        }
    }
    else
        m_vector_index = 0;

}
开发者ID:nbu-gamedev,项目名称:spacewar-2014,代码行数:37,代码来源:Animation.cpp

示例7: internalDrawTextureSectionExt

void internalDrawTextureSectionExt(Game* game, Texture* texture, Pointf position,
	Pointi sourcePosition, Pointi sourceSize, Pointf scale, float angle,
	Pointi origin, bool horizontalFlip, bool verticalFlip, float alpha)
{
	Pointi offset;
	offset.x = (sourceSize.x * (scale.x - 1)) / 2;
	offset.y = (sourceSize.y * (scale.y - 1)) / 2;
	
	SDL_Rect source = 
	{
		sourcePosition.x, sourcePosition.y, 
		sourceSize.x, sourceSize.y
	};
		
	SDL_Rect destination = 
	{
		position.x - offset.x, position.y - offset.y, 
		sourceSize.x * scale.x, sourceSize.y * scale.y
	};
	
	SDL_RendererFlip flip = SDL_FLIP_NONE;
	if(horizontalFlip)
		flip = (SDL_RendererFlip)(SDL_FLIP_HORIZONTAL | flip);
	if(verticalFlip)
		flip = (SDL_RendererFlip)(SDL_FLIP_VERTICAL | flip);
	
	SDL_Point originSdl = getSdlPointi(origin);
	
	if(alpha < 1.0f)
		SDL_SetTextureAlphaMod(texture->data, (int)(alpha * 255));
		
	SDL_RenderCopyEx(game->renderer, texture->data, &source, &destination,
		angle, &originSdl, flip);
		
	if(alpha < 1.0f)
		SDL_SetTextureAlphaMod(texture->data, 255);
}
开发者ID:Jools64,项目名称:shmup,代码行数:37,代码来源:engine.c

示例8: draw_map

void draw_map(SDL_Renderer *r, GameMap *m) {

    unsigned int x = 0, y = 0;
    unsigned int c_count = 0, l_count = 0;
    char *t = NULL;

    for(c_count = 0; c_count < m->sz; c_count++) {
        t = m->t_map[c_count];
        for(l_count = 0; l_count < 31; l_count++) {
            // printf("Letra %c[%d %d]", *t, l_count, c_count);
            // printf(".%c", *t, l_count, c_count);
            SDL_Rect srect, drect;
            srect.x = srect.y = 0;
            srect.w = srect.h = 32;
            drect.x = l_count * 32; drect.y = c_count * 32;
            drect.w = drect.h = 32;

            if(*t == 'o')
                SDL_RenderCopy(r, m->wall, &srect, &drect);
            else if(*t == 'I')
                SDL_RenderCopyEx(r, m->wall, &srect, &drect, 90, NULL, SDL_FLIP_NONE);
            else if(*t == '#')
                SDL_RenderCopy(r, m->cross, &srect, &drect);
            else if(*t == '.')
                SDL_RenderCopy(r, m->pils, &srect, &drect);
            else if(*t == 'G')
                SDL_RenderCopy(r, m->ghost, &srect, &drect);
            else if(*t == 'Y')
                SDL_RenderCopy(r, m->special, &srect, &drect);
            else if(*t == 'P')
                SDL_RenderCopy(r, m->pacman, &srect, &drect);

            t++;
        }
        // printf("\n");
    }
}
开发者ID:MarcusxDM,项目名称:ic_games_dev,代码行数:37,代码来源:draw.c

示例9: SDL_RenderCopyEx

void TextureManager::render(const std::string & id,
                            const int & src_x,
                            const int & src_y,
                            const int & src_w,
                            const int & src_h,
                            const int & dest_x,
                            const int & dest_y,
                            const int & dest_w,
                            const int & dest_h,
                            SDL_Renderer * renderer,
                            const SDL_RendererFlip & flip)
{
    SDL_Rect src, dest;
    src.x = src_x;
    src.y = src_y;
    src.w = src_w;
    src.h = src_h;
    dest.x = dest_x;
    dest.y = dest_y;
    dest.w = dest_w;
    dest.h = dest_h;

    SDL_RenderCopyEx(renderer, textures[id], &src, &dest, 0, 0, flip);    
}
开发者ID:ujpandey,项目名称:Kurota,代码行数:24,代码来源:TextureManager.cpp

示例10: doRender

/**
 * Renders the game's graphics.
 */
void doRender(gamestate* game)
{
	if (game->statusState == STATUS_STATE_LIVES)
	{
		draw_status_lives(game);
	}
	else if (game->statusState == STATUS_STATE_GAME)
	{	
		SDL_SetRenderDrawColor(game->renderer, 102, 204, 255, 255);
	
		SDL_RenderClear(game->renderer);

		for (int i = 0; i < 100; i++)
		{
			SDL_Rect tileRect = {game->tiles[i].x + game->scrollX, game->tiles[i].y, game->tiles[i].w, game->tiles[i].h};
			SDL_RenderCopy(game->renderer, game->tile, NULL, &tileRect);
		}

		SDL_Rect spookRect = {game->avatar.x + game->scrollX, game->avatar.y, 36, 36};
		SDL_RenderCopyEx(game->renderer, game->spook[game->avatar.aniFrame], NULL, &spookRect, 0, NULL, game->facingLeft);
	}

	SDL_RenderPresent(game->renderer);
}
开发者ID:Low-in-Sky,项目名称:spook_game,代码行数:27,代码来源:game.c

示例11: SDL_RenderCopyEx

bool Game::Draw(SDL_Texture* Temp,
                int x, int y, int w, int h,
                SDL_RendererFlip Flip)
{
    //Rectangle for Position
    SDL_Rect dstrect;

    //Texture is empty
    if(Temp == NULL)
    {
        return false;
    }

    dstrect.x = x;
    dstrect.y = y;
    dstrect.w = w;
    dstrect.h = h;


    //Draw on the screen
	SDL_RenderCopyEx(Renderer, Temp, NULL, &dstrect, 0, NULL, Flip);

	return true;
}
开发者ID:d1m1tur,项目名称:Blank,代码行数:24,代码来源:OnRender.cpp

示例12: SDL_RenderCopyEx

void Car::Draw(SDL_Renderer *renderer) {
    SDL_RenderCopyEx(renderer, this->texture, NULL, &this->rect, rotation, NULL, SDL_FLIP_NONE);
}
开发者ID:pepebecker,项目名称:car-game,代码行数:3,代码来源:Car.cpp

示例13: drawTexture

void drawTexture(SDL_Rect rect  ,SDL_Texture *texture){
    int w,h;
    SDL_QueryTexture(texture, NULL, NULL, &w, &h);
    SDL_RenderCopyEx(renderer, texture, NULL, &rect, 0, NULL, SDL_FLIP_NONE);
}
开发者ID:Tyfoid00,项目名称:CTratt,代码行数:5,代码来源:Engine.c

示例14: draw_tile

static void draw_tile(SDL_Renderer *r, tile const *t, SDL_Point const *pos, SDL_bool end, SDL_bool flip)
{
	SDL_Rect dest = (SDL_Rect) { pos->x - (end ? flip ? -t->box.w / 2 : 0 : t->box.x), pos->y - t->box.y, t->box.w / (end ? 2 : 1), t->box.h };
	SDL_RenderCopyEx(r, end ? t->end : t->main, 0, &dest, 0, 0, flip ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
}
开发者ID:fkmsoft,项目名称:fridge,代码行数:5,代码来源:editor.c

示例15: SDLDisplayBufferInWindow

internal void
SDLDisplayBufferInWindow(sdl_offscreen_buffer *Buffer) {
    SDL_UpdateTexture(Buffer->Texture, 0, Buffer->Memory, Buffer->Pitch);
    SDL_RenderCopyEx(Buffer->Renderer, Buffer->Texture, 0, 0, 0, 0, SDL_FLIP_VERTICAL);
    SDL_RenderPresent(Buffer->Renderer);
}
开发者ID:coeuvre,项目名称:handmade,代码行数:6,代码来源:sdl_handmade.cpp


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