本文整理汇总了C++中SDL_RenderCopy函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_RenderCopy函数的具体用法?C++ SDL_RenderCopy怎么用?C++ SDL_RenderCopy使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_RenderCopy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: backend_render_32bits
// NB not used at the moment because we want to do smooth scrolling with a pixel offset.
void backend_render_32bits()
{
//SDL_RenderPresent(renderer);
uint32_t *plane_idx_0 = (uint32_t *)backend_bitplane[0].data;
uint32_t *plane_idx_1 = (uint32_t *)backend_bitplane[1].data;
uint32_t *plane_idx_2 = (uint32_t *)backend_bitplane[2].data;
uint32_t *plane_idx_3 = (uint32_t *)backend_bitplane[3].data;
uint32_t *plane_idx_4 = (uint32_t *)backend_bitplane[4].data;
int fb_idx = 0;
for(int y = 0; y < window_height; y++) {
int x = 0;
while(x < window_width) {
uint32_t plane0 = be32toh(*plane_idx_0++); // we always have at least 2 bitplanes (TODO?)
uint32_t plane1 = be32toh(*plane_idx_1++);
uint32_t plane2 = plane_idx_2 ? be32toh(*plane_idx_2++) : 0;
uint32_t plane3 = plane_idx_3 ? be32toh(*plane_idx_3++) : 0;
uint32_t plane4 = plane_idx_4 ? be32toh(*plane_idx_4++) : 0;
// Turn 32 bits from each plane into 32 pixels.
unsigned bit;
for(bit = 0x80000000UL; bit > 0x800000UL; bit >>= 1) {
framebuffer[fb_idx + x] = palette[
((plane0 & bit) ? 1 : 0)
| ((plane1 & bit) ? 2 : 0)
| ((plane2 & bit) ? 4 : 0)
| ((plane3 & bit) ? 8 : 0)
| ((plane4 & bit) ? 16 : 0)];
x++;
}
for(; bit > 0x8000; bit >>= 1) {
framebuffer[fb_idx + x] = palette[
((plane0 & bit) ? 1 : 0)
| ((plane1 & bit) ? 2 : 0)
| ((plane2 & bit) ? 4 : 0)
| ((plane3 & bit) ? 8 : 0)
| ((plane4 & bit) ? 16 : 0)];
x++;
}
for(; bit > 0x80; bit >>= 1) {
framebuffer[fb_idx + x] = palette[
((plane0 & bit) ? 1 : 0)
| ((plane1 & bit) ? 2 : 0)
| ((plane2 & bit) ? 4 : 0)
| ((plane3 & bit) ? 8 : 0)
| ((plane4 & bit) ? 16 : 0)];
x++;
}
for(; bit; bit >>= 1) {
framebuffer[fb_idx + x] = palette[
((plane0 & bit) ? 1 : 0)
| ((plane1 & bit) ? 2 : 0)
| ((plane2 & bit) ? 4 : 0)
| ((plane3 & bit) ? 8 : 0)
| ((plane4 & bit) ? 16 : 0)];
x++;
}
}
fb_idx += window_width;
}
SDL_UpdateTexture(texture, NULL, framebuffer, window_width * 4);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
示例2: SDL_RenderCopy
void MyRenderer::renderCopy(SDL_Texture * texture)
{
SDL_RenderCopy(renderer, texture, NULL, NULL);
}
示例3: main
//.........这里部分代码省略.........
bool quit = false;
SDL_Event e;
SDL_Rect cratePos;
cratePos.w = CRATE_SIZE;
cratePos.h = CRATE_SIZE;
SDL_Rect crateBasePos;
crateBasePos.x = 30;
crateBasePos.y = 20;
crateBasePos.w = CRATE_SIZE;
crateBasePos.h = CRATE_SIZE;
SDL_Rect cranePos;
cranePos.x = 30;
cranePos.y = 200;
cranePos.w = 80;
cranePos.h = 76;
SDL_Rect rect;
rect.x = 20;
rect.y = crateBasePos.y+CRATE_SIZE*(sceneHeigth-1);
rect.w = 80;
rect.h = 40;
printf("Rect y: %d\n", rect.y);
SDL_Rect basePos = rect;
printf("Main Loop!\n");
while(!quit) {
if(res == NOT_DONE) {
res = scene.Tick( &function, &task);
} else if(res == SUCCES) {
printf("YOU WON\n");
res = DONE;
} else if(res == FAILURE) {
printf("YOU LOST!\n");
res = DONE;
}
//Handle events on queue
while( SDL_PollEvent( &e ) != 0 ) {
//User requests quit
if( e.type == SDL_QUIT ) {
quit = true;
}
//User presses a key
else if( e.type == SDL_KEYDOWN )
{
//Select surfaces based on key press
switch( e.key.keysym.sym )
{
case SDLK_UP:
printf("UP pressed!\n");
break;
}
}
}
// Render box's in grid
for (int i = 0; i < (int)scene.box.size(); ++i) {
if(scene.box[i].pos.x == 0) // Box is in crane, so use that pos
cratePos.x = crateBasePos.x+(CRATE_SIZE+40)*(scene.crane.pos.y);
else
cratePos.x = crateBasePos.x+(CRATE_SIZE+40)*(scene.box[i].pos.y);
cratePos.y = crateBasePos.y-CRATE_SIZE*(-scene.box[i].pos.x);
switch(scene.box[i].color) {
case YELLOW:
SDL_RenderCopy( Renderer, yellow_crate, NULL, &cratePos );
break;
case BLUE:
SDL_RenderCopy( Renderer, blue_crate, NULL, &cratePos );
break;
};
}
for(int i = 0; i < sceneWidth; i++) {
basePos.x = rect.x+(CRATE_SIZE+40)*i;
Draw::FilledRectangleRoundEdge(Renderer, basePos, 10);
}
cranePos.x = crateBasePos.x+(CRATE_SIZE+40)*(scene.crane.pos.y)-10;
cranePos.y = crateBasePos.y-CRATE_SIZE*(-scene.crane.pos.x)-20;
SDL_RenderCopy(Renderer, craneT, NULL, &cranePos );
//Apply the image
//SDL_RenderCopy( Renderer, crateT, NULL, &cratePos );
//SDL_RenderCopy( Renderer, crateT, NULL, &cratePos2);
SDL_RenderPresent(Renderer);
SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 0);
SDL_RenderClear(Renderer);
SDL_SetRenderDrawColor(Renderer, 100, 0, 0, 0);
SDL_Delay(750);
}
SDL_DestroyRenderer( Renderer );
SDL_DestroyWindow( Window );
SDL_Quit();
return 0;
}
示例4: switch
void TrainingMode::update()
{
/*
STEPS
0: How to move
1: How to shoot
2: Paintball Gun
3: How to select weapons - Glock
4: How to select weapons
5: How to use C4
6: Show Ammobox & how to use it
7: Show Tiger Generator, kill tiger
8: Show how to destroy tiger generator
9: Explain Survival Mode
10: Explain Mercenary Mode
*/
if(Main::ammoBoxes.size() > 0 && step != AmmoBoxes) Main::ammoBoxes.clear();
if(Main::tgs.size() > 0 && step!= TigerGenerators && step != DestroyTigerGenerator) Main::tgs.clear();
if(step != TigerGenerators) Main::spawning = false;
else Main::spawning = true;
SDL_Texture *tex = nullptr;
switch(step)
{
case Move:
message = "Move with the WASD keys";
rect.h = LargeFontSize;
rect.w = message.size() * LargeFontSize;
instructionSurface = TTF_RenderText_Solid(font,message.c_str(),fg);
tex = SDL_CreateTextureFromSurface(renderer,instructionSurface);
SDL_FreeSurface(instructionSurface);
SDL_RenderCopy(renderer,tex,NULL,&rect);
if(SDL_GetTicks() - start > 3000)
{
step++;
start = SDL_GetTicks();
SDL_DestroyTexture(tex);
}
break;
case Shoot:
message = "Shoot with the Left Mouse Button";
rect.h = LargeFontSize;
rect.w = message.size() * LargeFontSize;
instructionSurface = TTF_RenderText_Solid(font,message.c_str(),fg);
tex = SDL_CreateTextureFromSurface(renderer,instructionSurface);
SDL_FreeSurface(instructionSurface);
SDL_RenderCopy(renderer,tex,NULL,&rect);
if(SDL_GetTicks() - start > 3000)
{
step++;
start = SDL_GetTicks();
SDL_DestroyTexture(tex);
}
break;
case Paintball:
message = "The weapon you are holding is the Paintball Gun.";
rect.h = MediumFontSize;
rect.w = message.size() * MediumFontSize;
instructionSurface = TTF_RenderText_Solid(font,message.c_str(),fg);
tex = SDL_CreateTextureFromSurface(renderer,instructionSurface);
SDL_FreeSurface(instructionSurface);
SDL_RenderCopy(renderer,tex,NULL,&rect);
message = "With the Paintball Gun,";
rect2.h = MediumFontSize;
rect2.w = message.size() * MediumFontSize;
instructionSurface = TTF_RenderText_Solid(font,message.c_str(),fg);
tex = SDL_CreateTextureFromSurface(renderer,instructionSurface);
SDL_FreeSurface(instructionSurface);
SDL_RenderCopy(renderer,tex,NULL,&rect2);
message = "you can shoot with the Right Mouse Button too.";
rect3.h = MediumFontSize;
rect3.w = message.size() * MediumFontSize;
instructionSurface = TTF_RenderText_Solid(font,message.c_str(),fg);
tex = SDL_CreateTextureFromSurface(renderer,instructionSurface);
SDL_FreeSurface(instructionSurface);
SDL_RenderCopy(renderer,tex,NULL,&rect3);
if(SDL_GetTicks() - start > 6000)
{
step++;
start = SDL_GetTicks();
SDL_DestroyTexture(tex);
}
break;
case SelectGlock:
message = "Select Weapons by hitting number keys.";
rect.h = LargeFontSize;
rect.w = message.size() *LargeFontSize;
instructionSurface = TTF_RenderText_Solid(font,message.c_str(),fg);
tex = SDL_CreateTextureFromSurface(renderer,instructionSurface);
SDL_FreeSurface(instructionSurface);
SDL_RenderCopy(renderer,tex,NULL,&rect);
message = "Select the Glock by pressing 0.";
rect2.h = LargeFontSize;
rect2.w = message.size() *LargeFontSize;
instructionSurface = TTF_RenderText_Solid(font,message.c_str(),fg);
tex = SDL_CreateTextureFromSurface(renderer,instructionSurface);
SDL_FreeSurface(instructionSurface);
//.........这里部分代码省略.........
示例5: SDL_RenderCopy
//------------------------------------------------------------------------------
void Texture::Render(int X, int Y, int Width, int Height, int SX, int SY, int SWidth, int SHeight) {
SDL_Rect Source = {SX, SY, SWidth, SHeight};
SDL_Rect Destination = {X, Y, Width, Height};
SDL_RenderCopy(Renderer, SDLTexture, &Source, &Destination);
}
示例6: main
int main(int argc, char *argv[])
{
srand(time(NULL));
SDL_Window *screen;
SDL_Renderer *renderPrim;
SDL_Event eventHandle;
SDL_Texture *scoreDisplay;
TTF_Font *defaultText;
SDL_Color cPlayer = {0,255,255,255};
SDL_Color cPoint = {255,255,0,255};
SDL_Color cBackground = {0,0,0,255};
SDL_Color cScore = {0,255,0,255};
int runningGame,gotPoint, pointCount, oldScore;
runningGame = 0;
gotPoint = 0;
pointCount = -1;//first point spawns on player
SDL_Rect rPlayer = {0,0,PLAYER_WIDTH, PLAYER_HEIGHT};
SDL_Rect rPoint = {0,0,POINT_WIDTH,POINT_HEIGHT};
SDL_Rect rScore = {0,0,0,0};
screen = init("Piss easy snake", SCREEN_WIDTH, SCREEN_HEIGHT);
renderPrim = createRenderer(screen);
defaultText = loadFont("default.ttf", 15, renderPrim);
while(runningGame == 0)
{
oldScore = pointCount;
if(gotPoint == 1)
{
pointCount++;
rPoint.x = rand() % SCREEN_WIDTH;//new random position
rPoint.y = rand() % SCREEN_HEIGHT;
gotPoint = 0;
}
while(SDL_PollEvent(&eventHandle) != 0)
{
if(eventHandle.type == SDL_KEYDOWN)
{
handleInput(&rPlayer, eventHandle, &runningGame);
}
else if(eventHandle.type == SDL_QUIT)
{
runningGame = 1;
}
}
SDL_SetRenderDrawColor(renderPrim, cBackground.r,cBackground.g,cBackground.b,cBackground.a);
SDL_RenderClear(renderPrim);
SDL_SetRenderDrawColor(renderPrim,cPlayer.r,cPlayer.g,cPlayer.b,cPlayer.a);
SDL_RenderFillRect(renderPrim,&rPlayer);
SDL_SetRenderDrawColor(renderPrim,cPoint.r,cPoint.g,cPoint.b,cPoint.a);
SDL_RenderFillRect(renderPrim,&rPoint);
if(oldScore < pointCount)
{
scoreDisplay = renderScore(defaultText,cScore,&rScore, renderPrim, pointCount, scoreDisplay);
}
SDL_RenderCopy(renderPrim, scoreDisplay, NULL, &rScore);
SDL_RenderPresent(renderPrim);
gotPoint = SDL_HasIntersection(&rPlayer,&rPoint);
}
SDL_DestroyRenderer(renderPrim);
SDL_DestroyWindow(screen);
TTF_CloseFont(defaultText);
TTF_Quit();
SDL_Quit();
return 0;
}
示例7: ApplyBlendToTexture
//Draw the texture from the PackedSprite structure
//param:packedSprite->The packed sprite to draw from
void SpriteBatch::DrawTexture(PackedSprite packedSprite)
{
if(packedSprite.Type == PackedSprite::PackType::Sprite)
{
//Get the texture (we dont do bounds checking because when we added the texture to the list
//we checked the bounds) We also don't check for begin, because that would've been checked in the
//users call to DrawTexture. This is a private function. Only spritebatch calls this one.
SDL_Texture* tex = textureList[packedSprite.Texture];
//Apply any blends
ApplyBlendToTexture(tex, packedSprite.Tint);
//if no flip or angle, draw with Render Copy
if(packedSprite.Rotation == 0 && packedSprite.FlipEffects == 0)
SDL_RenderCopy(renderer, tex, packedSprite.SourceRect, packedSprite.DestRect);
else
///Draw the image with any flip/angle
SDL_RenderCopyEx(renderer, tex, packedSprite.SourceRect, packedSprite.DestRect,
packedSprite.Rotation, packedSprite.Origin, packedSprite.FlipEffects);
}
else
{
SDL_Surface* textSurface;
//Generate surface based on draw mode
if(packedSprite.DrawMode == StringDrawMode::Blended)
{
if(packedSprite.WrapLength <= 0)
textSurface = TTF_RenderText_Blended(fontManager->GetFont(packedSprite.Texture), packedSprite.Message.c_str(),
packedSprite.Tint);
else
textSurface = TTF_RenderText_Blended_Wrapped(fontManager->GetFont(packedSprite.Texture),
packedSprite.Message.c_str(), packedSprite.Tint, packedSprite.WrapLength);
}
else if(packedSprite.DrawMode == StringDrawMode::Shaded)
{
textSurface = TTF_RenderText_Shaded(fontManager->GetFont(packedSprite.Texture), packedSprite.Message.c_str(),
packedSprite.Tint, packedSprite.BackgroundColor);
}
else if(packedSprite.DrawMode == StringDrawMode::Solid)
{
textSurface = TTF_RenderText_Solid(fontManager->GetFont(packedSprite.Texture), packedSprite.Message.c_str(),
packedSprite.Tint);
}
//Generate the texture from the surface
SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, textSurface);
//Free the surface and get rid of the pointer to it
SDL_FreeSurface(textSurface);
textSurface = nullptr;
int w = 0;
int h = 0;
SDL_QueryTexture(tex, NULL, NULL, &w, &h);
//Create a rectangle that is the size of the string
SDL_Rect sourceRect = CreateRect(0, 0, w, h);
SDL_Rect destRect = CreateRect(packedSprite.DestRect->x, packedSprite.DestRect->y,
(Uint32)(w * packedSprite.StringScale), (Uint32)(h * packedSprite.StringScale));
//if no flip or angle, draw with Render Copy
if(packedSprite.Rotation == 0 && packedSprite.FlipEffects == SDL_RendererFlip::SDL_FLIP_NONE)
SDL_RenderCopy(renderer, tex, &sourceRect, &destRect);
else
///Draw the image with any flip/angle
SDL_RenderCopyEx(renderer, tex, &sourceRect, &destRect,
packedSprite.Rotation, packedSprite.Origin, packedSprite.FlipEffects);
}
}
示例8: ANDROID_UnlockHWSurface
static void ANDROID_UnlockHWSurface(_THIS, SDL_Surface *surface)
{
SDL_PixelFormat format;
Uint32 hwformat = PixelFormatEnumColorkey;
int bpp;
SDL_Surface * converted = NULL;
if( !SDL_ANDROID_InsideVideoThread() )
{
__android_log_print(ANDROID_LOG_INFO, "libSDL", "Error: calling %s not from the main thread!", __PRETTY_FUNCTION__);
return;
}
if( !surface->hwdata )
return;
if( surface->format->Amask )
hwformat = PixelFormatEnumAlpha;
if( surface == SDL_CurrentVideoSurface ) // Special case
hwformat = PixelFormatEnum;
/* Allocate the new pixel format for the screen */
SDL_memset(&format, 0, sizeof(format));
SDL_PixelFormatEnumToMasks( hwformat, &bpp,
&format.Rmask, &format.Gmask,
&format.Bmask, &format.Amask );
format.BytesPerPixel = SDL_ANDROID_BYTESPERPIXEL;
format.BitsPerPixel = bpp;
// TODO: support 24bpp and 32bpp
if( format.BitsPerPixel == surface->format->BitsPerPixel &&
format.Rmask == surface->format->Rmask &&
format.Gmask == surface->format->Gmask &&
format.Bmask == surface->format->Bmask &&
format.Amask == surface->format->Amask )
{
converted = surface; // No need for conversion
}
else
{
Uint16 x, y;
converted = SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, format.BitsPerPixel,
format.Rmask, format.Gmask, format.Bmask, format.Amask);
if( !converted ) {
SDL_OutOfMemory();
return;
}
#define CONVERT_RGB565_RGBA5551( pixel ) (0x1 | ( (pixel & 0xFFC0) | ( (pixel & 0x1F) << 1 ) ))
if( surface->flags & SDL_SRCCOLORKEY )
{
DEBUGOUT("ANDROID_UnlockHWSurface() CONVERT_RGB565_RGBA5551 + colorkey");
for( y = 0; y < surface->h; y++ )
{
Uint16* src = (Uint16 *)( surface->pixels + surface->pitch * y );
Uint16* dst = (Uint16 *)( converted->pixels + converted->pitch * y );
Uint16 w = surface->w;
Uint16 key = surface->format->colorkey;
Uint16 pixel;
for( x = 0; x < w; x++, src++, dst++ )
{
pixel = *src;
*dst = (pixel == key) ? 0 : CONVERT_RGB565_RGBA5551( pixel );
}
}
}
else
{
DEBUGOUT("ANDROID_UnlockHWSurface() CONVERT_RGB565_RGBA5551");
for( y = 0; y < surface->h; y++ )
{
Uint16* src = (Uint16 *)( surface->pixels + surface->pitch * y );
Uint16* dst = (Uint16 *)( converted->pixels + converted->pitch * y );
Uint16 w = surface->w;
Uint16 pixel;
for( x = 0; x < w; x++, src++, dst++ )
{
pixel = *src;
*dst = CONVERT_RGB565_RGBA5551( pixel );
}
}
}
}
SDL_Rect rect;
rect.x = 0;
rect.y = 0;
rect.w = surface->w;
rect.h = surface->h;
SDL_UpdateTexture((struct SDL_Texture *)surface->hwdata, &rect, converted->pixels, converted->pitch);
if( surface == SDL_CurrentVideoSurface ) // Special case
SDL_RenderCopy((struct SDL_Texture *)SDL_CurrentVideoSurface->hwdata, NULL, NULL);
if( converted != surface )
SDL_FreeSurface(converted);
}
示例9: main
int main( int argc, char** argv )
{
// Create the optional arguments
boost::program_options::options_description generic( "Allowed options" );
generic.add_options()
("help,h", "produce help message")
("image,i",
boost::program_options::value<std::string>(),
"Set the optional image to render (with path)\n");
// Create the command-line argument parser
boost::program_options::options_description
cmdline_options( "Allowed options" );
cmdline_options.add(generic);
boost::program_options::variables_map vm;
boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).run(), vm );
boost::program_options::notify( vm );
// Check if the help message was requested
if( vm.count( "help" ) )
{
std::cerr << generic << std::endl;
return 1;
}
// Store the image name
std::string image_name;
if( vm.count( "image" ) )
image_name = vm["image"].as<std::string>();
// Initialize the window
if( !initialize() )
{
return 1;
}
else
{
// Load the bitmap
if( !loadMedia( image_name ))
{
return 1;
}
else
{
bool quit = false;
// Event
SDL_Event event;
// Main application loop
while( !quit )
{
while( SDL_PollEvent( &event ) != 0 )
{
if( event.type == SDL_QUIT )
quit = true;
}
// Render the user supplied image (texture) to the screen
if( image_name.size() > 0 )
{
// Clear the screen
SDL_RenderClear( g_renderer );
SDL_RenderCopy( g_renderer, g_texture, NULL, NULL );
}
else
{
SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
// Clear the screen
SDL_RenderClear( g_renderer );
}
// Render red filled quad
SDL_Rect fill_rect = { screen_width_height[0]/4,
screen_width_height[1]/4,
screen_width_height[0]/2,
screen_width_height[1]/2 };
SDL_SetRenderDrawColor( g_renderer, 0xFF, 0x00, 0x00, 0xFF );
SDL_RenderFillRect( g_renderer, &fill_rect );
// Render green outlined quad
SDL_Rect outline_rect = { screen_width_height[0]/6,
screen_width_height[1]/6,
screen_width_height[0]*2/3,
screen_width_height[1]*2/3 };
SDL_SetRenderDrawColor( g_renderer, 0x00, 0xFF, 0x00, 0xFF );
SDL_RenderDrawRect( g_renderer, &outline_rect );
// Draw a blue horizontal line
SDL_SetRenderDrawColor( g_renderer, 0x00, 0x00, 0xFF, 0xFF );
SDL_RenderDrawLine( g_renderer,
0,
screen_width_height[1]/2,
//.........这里部分代码省略.........
示例10: DrawText
void DrawText(Text* text, SDL_Renderer* renderer)
{
SDL_RenderCopy(renderer, text->texture, NULL, &text->rect);
}
示例11: int
void Renderer::draw_sprite(Sprite & spr, int x, int y, float scale) {
SDL_Rect dst = { x, y, int(spr.width * scale), int(spr.height * scale) };
SDL_RenderCopy(renderer, spr.texture, 0, &dst);
}
示例12: main
int main(){
init();
load_res();
SDL_Event event;
Uint8 red = 255, green = 255, blue = 255;
bool color_on = true;
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, color_wheel, NULL, NULL);
SDL_RenderPresent(renderer);
bool loop = true;
while(loop) {
while(SDL_PollEvent(&event) != 0) {
if(event.type == SDL_QUIT) {
loop = false;
}
if(event.type == SDL_KEYDOWN) {
switch(event.key.keysym.sym) {
case SDLK_SPACE:
color_on = !color_on;
break;
case SDLK_q:
red += 32;
break;
case SDLK_a:
red -= 32;
break;
case SDLK_w:
green += 32;
break;
case SDLK_s:
green -= 32;
break;
case SDLK_e:
blue += 32;
break;
case SDLK_d:
blue -= 32;
break;
case SDLK_r:
red = 255;
green = 255;
blue = 255;
break;
case SDLK_ESCAPE:
loop = false;
default:
break;
}
red = clamp(red);
green = clamp(green);
blue = clamp(blue);
if(color_on) {
SDL_SetTextureColorMod(color_wheel, red, green, blue);
printf("< R%03d G%03d B%03d >\n", red, green, blue);
} else {
SDL_SetTextureColorMod(color_wheel, 255, 255, 255);
printf("< R255 G255 B255 >\n");
}
}
}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, color_wheel, NULL, NULL);
SDL_RenderPresent(renderer);
}
quit();
return 0;
}
示例13: SDL_RenderCopy
void Personaje::dibujar()
{
rect.x = x;
rect.y = y;
SDL_RenderCopy(renderer, textures[state][current_texture], NULL, &rect);
}
示例14: MoveSprites
void
MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
{
int i;
SDL_Rect viewport, temp;
SDL_Rect *position, *velocity;
/* Query the sizes */
SDL_RenderGetViewport(renderer, &viewport);
/* Cycle the color and alpha, if desired */
if (cycle_color) {
current_color += cycle_direction;
if (current_color < 0) {
current_color = 0;
cycle_direction = -cycle_direction;
}
if (current_color > 255) {
current_color = 255;
cycle_direction = -cycle_direction;
}
SDL_SetTextureColorMod(sprite, 255, (Uint8) current_color,
(Uint8) current_color);
}
if (cycle_alpha) {
current_alpha += cycle_direction;
if (current_alpha < 0) {
current_alpha = 0;
cycle_direction = -cycle_direction;
}
if (current_alpha > 255) {
current_alpha = 255;
cycle_direction = -cycle_direction;
}
SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha);
}
/* Draw a gray background */
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
/* Test points */
SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
SDL_RenderDrawPoint(renderer, 0, 0);
SDL_RenderDrawPoint(renderer, viewport.w-1, 0);
SDL_RenderDrawPoint(renderer, 0, viewport.h-1);
SDL_RenderDrawPoint(renderer, viewport.w-1, viewport.h-1);
/* Test horizontal and vertical lines */
SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
SDL_RenderDrawLine(renderer, 1, 0, viewport.w-2, 0);
SDL_RenderDrawLine(renderer, 1, viewport.h-1, viewport.w-2, viewport.h-1);
SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h-2);
SDL_RenderDrawLine(renderer, viewport.w-1, 1, viewport.w-1, viewport.h-2);
/* Test fill and copy */
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
temp.x = 1;
temp.y = 1;
temp.w = sprite_w;
temp.h = sprite_h;
SDL_RenderFillRect(renderer, &temp);
SDL_RenderCopy(renderer, sprite, NULL, &temp);
temp.x = viewport.w-sprite_w-1;
temp.y = 1;
temp.w = sprite_w;
temp.h = sprite_h;
SDL_RenderFillRect(renderer, &temp);
SDL_RenderCopy(renderer, sprite, NULL, &temp);
temp.x = 1;
temp.y = viewport.h-sprite_h-1;
temp.w = sprite_w;
temp.h = sprite_h;
SDL_RenderFillRect(renderer, &temp);
SDL_RenderCopy(renderer, sprite, NULL, &temp);
temp.x = viewport.w-sprite_w-1;
temp.y = viewport.h-sprite_h-1;
temp.w = sprite_w;
temp.h = sprite_h;
SDL_RenderFillRect(renderer, &temp);
SDL_RenderCopy(renderer, sprite, NULL, &temp);
/* Test diagonal lines */
SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
SDL_RenderDrawLine(renderer, sprite_w, sprite_h,
viewport.w-sprite_w-2, viewport.h-sprite_h-2);
SDL_RenderDrawLine(renderer, viewport.w-sprite_w-2, sprite_h,
sprite_w, viewport.h-sprite_h-2);
/* Conditionally move the sprites, bounce at the wall */
if (iterations == -1 || iterations > 0) {
for (i = 0; i < num_sprites; ++i) {
position = &positions[i];
velocity = &velocities[i];
position->x += velocity->x;
if ((position->x < 0) || (position->x >= (viewport.w - sprite_w))) {
velocity->x = -velocity->x;
position->x += velocity->x;
}
position->y += velocity->y;
//.........这里部分代码省略.........
示例15: Draw
void WorldTip::Draw(double dt) {
if(ply->pos.Distance(this->origin) < 200) {
SDL_Rect rect = {this->rect.x - camera.x, this->rect.y - camera.y, this->rect.w, this->rect.h};
if(SDL_RenderCopy(renderer, this->texture, NULL, &rect) != 0) {printf("Worldtip Render failed: %s\n", SDL_GetError());}
}
}