本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
示例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");
}
}
示例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);
}
示例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);
}
示例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;
}
示例12: SDL_RenderCopyEx
void Car::Draw(SDL_Renderer *renderer) {
SDL_RenderCopyEx(renderer, this->texture, NULL, &this->rect, rotation, NULL, SDL_FLIP_NONE);
}
示例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);
}
示例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);
}
示例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);
}