本文整理汇总了C++中SDL_RenderSetViewport函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_RenderSetViewport函数的具体用法?C++ SDL_RenderSetViewport怎么用?C++ SDL_RenderSetViewport使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_RenderSetViewport函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bmx_SDL_RenderSetViewport
int bmx_SDL_RenderSetViewport(SDL_Renderer * renderer, int x, int y, int w, int h) {
if (x < 0 || y < 0 || w < 0 || h < 0) {
return SDL_RenderSetViewport(renderer, 0);
} else {
SDL_Rect r = { x, y, w, h };
return SDL_RenderSetViewport(renderer, &r);
}
}
示例2: VL_SDL2_Present
static void VL_SDL2_Present(void *surface, int scrlX, int scrlY)
{
// TODO: Verify this is a VL_SurfaceUsage_FrontBuffer
VL_SDL2_ResizeWindow();
SDL_Surface *surf = (SDL_Surface *)surface;
SDL_Rect srcr = {(Sint16)scrlX, (Sint16)scrlY, VL_EGAVGA_GFX_WIDTH, VL_EGAVGA_GFX_HEIGHT};
SDL_Rect integerRect = {0, 0, vl_integerWidth, vl_integerHeight};
SDL_Rect renderRect = {(Sint16)vl_renderRgn_x, (Sint16)vl_renderRgn_y, vl_renderRgn_w, vl_renderRgn_h};
SDL_Rect fullRect = {(Sint16)vl_fullRgn_x, (Sint16)vl_fullRgn_y, vl_fullRgn_w, vl_fullRgn_h};
SDL_BlitSurface(surf, &srcr, vl_sdl2_stagingSurface, 0);
SDL_UpdateTexture(vl_sdl2_texture, 0, vl_sdl2_stagingSurface->pixels, vl_sdl2_stagingSurface->pitch);
SDL_SetRenderTarget(vl_sdl2_renderer, vl_sdl2_scaledTarget);
SDL_SetRenderDrawColor(vl_sdl2_renderer,
VL_EGARGBColorTable[vl_emuegavgaadapter.bordercolor][0],
VL_EGARGBColorTable[vl_emuegavgaadapter.bordercolor][1],
VL_EGARGBColorTable[vl_emuegavgaadapter.bordercolor][2],
255);
SDL_RenderClear(vl_sdl2_renderer);
SDL_RenderCopy(vl_sdl2_renderer, vl_sdl2_texture, 0, &renderRect);
SDL_SetRenderTarget(vl_sdl2_renderer, 0);
SDL_SetRenderDrawColor(vl_sdl2_renderer, 0, 0, 0, 255);
SDL_RenderClear(vl_sdl2_renderer);
SDL_RenderSetViewport(vl_sdl2_renderer, 0);
SDL_RenderCopy(vl_sdl2_renderer, vl_sdl2_scaledTarget, 0, &fullRect);
SDL_RenderPresent(vl_sdl2_renderer);
}
示例3: SDL_GetWindowSize
void Render_SW_SDL::resetViewport()
{
float w, w1, h, h1;
int wi, hi;
SDL_GetWindowSize(PGE_Window::window, &wi, &hi);
w=wi; h=hi; w1=w; h1=h;
scale_x=(float)((float)(w)/(float)window_w);
scale_y=(float)((float)(h)/(float)window_h);
viewport_scale_x = scale_x;
viewport_scale_y = scale_y;
if(scale_x>scale_y)
{
w1=scale_y*window_w;
viewport_scale_x=w1/window_w;
}
else if(scale_x<scale_y)
{
h1=scale_x*window_h;
viewport_scale_y=h1/window_h;
}
offset_x=(w-w1)/2;
offset_y=(h-h1)/2;
//glViewport(offset_x, offset_y, (GLsizei)w1, (GLsizei)h1); GLERRORCHECK();
SDL_Rect topLeftViewport;
topLeftViewport.x = offset_x;
topLeftViewport.y = offset_y;
topLeftViewport.w = w1;
topLeftViewport.h = h1;
SDL_RenderSetViewport( m_gRenderer, &topLeftViewport );
setViewportSize(window_w, window_h);
}
示例4: SDL_RendererEventWatch
static int
SDL_RendererEventWatch(void *userdata, SDL_Event *event)
{
SDL_Renderer *renderer = (SDL_Renderer *)userdata;
if (event->type == SDL_WINDOWEVENT) {
SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
if (window == renderer->window) {
if (renderer->WindowEvent) {
renderer->WindowEvent(renderer, &event->window);
}
if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
/* Try to keep the previous viewport centered */
int w, h;
SDL_Rect viewport;
SDL_GetWindowSize(window, &w, &h);
viewport.x = (w - renderer->viewport.w) / 2;
viewport.y = (h - renderer->viewport.h) / 2;
viewport.w = renderer->viewport.w;
viewport.h = renderer->viewport.h;
SDL_RenderSetViewport(renderer, &viewport);
} else if (event->window.event == SDL_WINDOWEVENT_MINIMIZED) {
renderer->minimized = SDL_TRUE;
} else if (event->window.event == SDL_WINDOWEVENT_RESTORED) {
renderer->minimized = SDL_FALSE;
}
}
}
return 0;
}
示例5: SDL_RenderSetViewport
//renderizar
void ViewPort::render()
{
//renderizamos en el viewport seleccionado
SDL_RenderSetViewport( gRenderer, ¶m );
//Render texture to screen
tex.render(gRenderer, &tamañofin);
}
示例6: UpdateLogicalSize
static int
UpdateLogicalSize(SDL_Renderer *renderer)
{
int w, h;
float want_aspect;
float real_aspect;
float scale;
SDL_Rect viewport;
if (SDL_GetRendererOutputSize(renderer, &w, &h) < 0) {
return -1;
}
want_aspect = (float)renderer->logical_w / renderer->logical_h;
real_aspect = (float)w / h;
/* Clear the scale because we're setting viewport in output coordinates */
SDL_RenderSetScale(renderer, 1.0f, 1.0f);
if (SDL_fabs(want_aspect-real_aspect) < 0.0001) {
/* The aspect ratios are the same, just scale appropriately */
scale = (float)w / renderer->logical_w;
SDL_RenderSetViewport(renderer, NULL);
} else if (want_aspect > real_aspect) {
/* We want a wider aspect ratio than is available - letterbox it */
scale = (float)w / renderer->logical_w;
viewport.x = 0;
viewport.w = w;
viewport.h = (int)SDL_ceil(renderer->logical_h * scale);
viewport.y = (h - viewport.h) / 2;
SDL_RenderSetViewport(renderer, &viewport);
} else {
/* We want a narrower aspect ratio than is available - use side-bars */
scale = (float)h / renderer->logical_h;
viewport.y = 0;
viewport.h = h;
viewport.w = (int)SDL_ceil(renderer->logical_w * scale);
viewport.x = (w - viewport.w) / 2;
SDL_RenderSetViewport(renderer, &viewport);
}
/* Set the new scale */
SDL_RenderSetScale(renderer, scale, scale);
return 0;
}
示例7: SDL_RenderSetViewport
void Menu::renderizar() {
SDL_RenderSetViewport(renderer_principal, &vista_juego);
// Renderizar botones
for (int i = 0; i < NUM_BOTONES; i++) {
botones[i]->renderizar();
}
}
示例8: sdl_refresh_renderer
static void sdl_refresh_renderer(sdl2_video_t *vid)
{
SDL_RenderClear(vid->renderer);
SDL_Rect r = { vid->vp.x, vid->vp.y, (int)vid->vp.width, (int)vid->vp.height };
SDL_RenderSetViewport(vid->renderer, &r);
// breaks int scaling
// SDL_RenderSetLogicalSize(vid->renderer, vid->vp.width, vid->vp.height);
}
示例9: loop
void
loop()
{
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_RenderSetViewport(renderer, NULL);
displayrect.w = window_w = event.window.data1;
displayrect.h = window_h = event.window.data2;
}
break;
case SDL_MOUSEBUTTONDOWN:
displayrect.x = event.button.x - window_w / 2;
displayrect.y = event.button.y - window_h / 2;
break;
case SDL_MOUSEMOTION:
if (event.motion.state) {
displayrect.x = event.motion.x - window_w / 2;
displayrect.y = event.motion.y - window_h / 2;
}
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_SPACE) {
paused = !paused;
break;
}
if (event.key.keysym.sym != SDLK_ESCAPE) {
break;
}
case SDL_QUIT:
done = SDL_TRUE;
break;
}
}
#ifndef __EMSCRIPTEN__
SDL_Delay(fpsdelay);
#endif
if (!paused) {
i = (i + 1) % MOOSEFRAMES_COUNT;
SDL_UpdateTexture(MooseTexture, NULL, MooseFrame[i], MOOSEPIC_W*SDL_BYTESPERPIXEL(pixel_format));
}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, MooseTexture, NULL, &displayrect);
SDL_RenderPresent(renderer);
#ifdef __EMSCRIPTEN__
if (done) {
emscripten_cancel_main_loop();
}
#endif
}
示例10: main
int main(int argc, char **args) {
SDL_Event e;
bool quit = false;
if (init() && loadMedia()) {
while (!quit) {
while (SDL_PollEvent(&e) != 0) {
if (e.type == SDL_QUIT) {
quit = true;
}
}
SDL_Rect topLeftViewport;
topLeftViewport.x = 0;
topLeftViewport.y = 0;
topLeftViewport.w = SCREEN_WIDTH / 2;
topLeftViewport.h = SCREEN_HEIGHT / 2;
SDL_Rect topRightViewport;
topRightViewport.x = SCREEN_WIDTH / 2;
topRightViewport.y = 0;
topRightViewport.w = SCREEN_WIDTH / 2;
topRightViewport.h = SCREEN_HEIGHT / 2;
SDL_Rect bottomViewport;
bottomViewport.x = 0;
bottomViewport.y = SCREEN_HEIGHT / 2;
bottomViewport.w = SCREEN_WIDTH;
bottomViewport.h = SCREEN_HEIGHT / 2;
SDL_RenderSetViewport(renderer, &topLeftViewport);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderSetViewport(renderer, &topRightViewport);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderSetViewport(renderer, &bottomViewport);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
}
return 0;
}
示例11: SDL_SetRenderTarget
int
SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
{
SDL_Rect viewport;
if (!SDL_RenderTargetSupported(renderer)) {
SDL_Unsupported();
return -1;
}
if (texture == renderer->target) {
/* Nothing to do! */
return 0;
}
/* texture == NULL is valid and means reset the target to the window */
if (texture) {
CHECK_TEXTURE_MAGIC(texture, -1);
if (renderer != texture->renderer) {
SDL_SetError("Texture was not created with this renderer");
return -1;
}
if (!(texture->access & SDL_TEXTUREACCESS_TARGET)) {
SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET");
return -1;
}
if (texture->native) {
/* Always render to the native texture */
texture = texture->native;
}
}
if (texture && !renderer->target) {
/* Make a backup of the viewport */
renderer->viewport_backup = renderer->viewport;
}
renderer->target = texture;
if (renderer->SetRenderTarget(renderer, texture) < 0) {
return -1;
}
if (texture) {
viewport.x = 0;
viewport.y = 0;
viewport.w = texture->w;
viewport.h = texture->h;
} else {
viewport = renderer->viewport_backup;
}
if (SDL_RenderSetViewport(renderer, &viewport) < 0) {
return -1;
}
/* All set! */
return 0;
}
示例12: SDL_RenderSetViewport
void Render_SW_SDL::setViewport(int x, int y, int w, int h)
{
SDL_Rect topLeftViewport;
topLeftViewport.x = offset_x + (int)ceil((float)x*viewport_scale_x);
topLeftViewport.y = offset_y + (int)ceil((float)y*viewport_scale_y);
topLeftViewport.w = (int)round((float)w*viewport_scale_x);
topLeftViewport.h = (int)round((float)h*viewport_scale_y);
SDL_RenderSetViewport( m_gRenderer, &topLeftViewport );
viewport_x=(float)x;
viewport_y=(float)y;
setViewportSize(w, h);
}
示例13: Size
void
SDLRenderer::apply_viewport()
{
Size target_size = (g_config->use_fullscreen && g_config->fullscreen_size != Size(0, 0)) ?
g_config->fullscreen_size :
g_config->window_size;
float pixel_aspect_ratio = 1.0f;
if (g_config->aspect_size != Size(0, 0))
{
pixel_aspect_ratio = calculate_pixel_aspect_ratio(m_desktop_size,
g_config->aspect_size);
}
else if (g_config->use_fullscreen)
{
pixel_aspect_ratio = calculate_pixel_aspect_ratio(m_desktop_size,
target_size);
}
// calculate the viewport
Size max_size(1280, 800);
Size min_size(640, 480);
Size logical_size;
calculate_viewport(min_size, max_size,
target_size,
pixel_aspect_ratio,
g_config->magnification,
m_scale, logical_size, m_viewport);
SCREEN_WIDTH = logical_size.width;
SCREEN_HEIGHT = logical_size.height;
if (m_viewport.x != 0 || m_viewport.y != 0)
{
// Clear the screen to avoid garbage in unreachable areas after we
// reset the coordinate system
SDL_SetRenderDrawColor(m_renderer, 0, 0, 0, 255);
SDL_SetRenderDrawBlendMode(m_renderer, SDL_BLENDMODE_NONE);
SDL_RenderClear(m_renderer);
SDL_RenderPresent(m_renderer);
SDL_RenderClear(m_renderer);
}
// SetViewport() works in scaled screen coordinates, so we have to
// reset it to 1.0, 1.0 to get meaningful results
SDL_RenderSetScale(m_renderer, 1.0f, 1.0f);
SDL_RenderSetViewport(m_renderer, &m_viewport);
SDL_RenderSetScale(m_renderer, m_scale.x, m_scale.y);
}
示例14: SDL_RenderSetViewport
void Window::updateViewportPosition(s16 x, s16 y) {
// Check if the viewport is in the map
if(x < 0) x = 0;
if(x + m_viewportW >= MapManager::currentMap->width() * 16) x = MapManager::currentMap->width() * 16 - m_viewportW - 1;
if(y < 0) y = 0;
if(y + m_viewportH >= MapManager::currentMap->height() * 16) y = MapManager::currentMap->height() * 16 - m_viewportH - 1;
// Update viewport position
m_viewportX = x;
m_viewportY = y;
// Set viewport
SDL_Rect viewportRect = {-x, y - m_height / 2, m_width, m_height};
SDL_RenderSetViewport(m_renderer, &viewportRect);
}
示例15: SDL_RenderClear
void CApp::OnRender() {
// have a weak read only pointer for the purpose of
// not needing .get() all the time.
auto *renderer = _renderer.get();
SDL_RenderClear(renderer);
SDL_RenderSetViewport(renderer, nullptr);
for (auto *entity: CEntity::_entityList) {
if (entity != nullptr) {
entity->OnRender(renderer);
}
}
SDL_RenderPresent(renderer);
}