void texture_info::set_coloralphamode(SDL_Texture *texture_id, const render_color *color) { UINT32 sr = (UINT32)(255.0f * color->r); UINT32 sg = (UINT32)(255.0f * color->g); UINT32 sb = (UINT32)(255.0f * color->b); UINT32 sa = (UINT32)(255.0f * color->a); if (color->r >= 1.0f && color->g >= 1.0f && color->b >= 1.0f && is_opaque(color->a)) { SDL_SetTextureColorMod(texture_id, 0xFF, 0xFF, 0xFF); SDL_SetTextureAlphaMod(texture_id, 0xFF); } /* coloring-only case */ else if (is_opaque(color->a)) { SDL_SetTextureColorMod(texture_id, sr, sg, sb); SDL_SetTextureAlphaMod(texture_id, 0xFF); } /* alpha and/or coloring case */ else if (!is_transparent(color->a)) { SDL_SetTextureColorMod(texture_id, sr, sg, sb); SDL_SetTextureAlphaMod(texture_id, sa); } else { SDL_SetTextureColorMod(texture_id, 0xFF, 0xFF, 0xFF); SDL_SetTextureAlphaMod(texture_id, 0x00); } }
Uint32 my_callback(Uint32 interval,void* param){ Uint32 current_time = SDL_GetTicks(); timer_params t_p = *((timer_params*)param); if((t_p.window != NULL )&& (t_p.renderer != NULL)){ if(t_p.event->type == SDL_MOUSEBUTTONDOWN | t_p.event->type == SDL_MOUSEMOTION){ if(t_p.event->button.button == SDL_BUTTON_LEFT){ //printf("%d %d\n",t_p.board->cursor.rectangle.x,t_p.board->cursor.rectangle.y); SDL_SetTextureColorMod(t_p.board->cursor.texture,128,0,0); SDL_SetTextureAlphaMod(t_p.board->cursor.texture,255); } else if(t_p.event->button.button == SDL_BUTTON_RIGHT){ SDL_SetTextureColorMod(t_p.board->cursor.texture,0,0,128); SDL_SetTextureAlphaMod(t_p.board->cursor.texture,255); } } else if(t_p.event->type == SDL_MOUSEBUTTONUP && (t_p.event->button.button == SDL_BUTTON_LEFT | t_p.event->button.button == SDL_BUTTON_RIGHT)){ SDL_SetTextureColorMod(t_p.board->cursor.texture,0,0,0); SDL_SetTextureAlphaMod(t_p.board->cursor.texture,200); } if(r < 200){ r++; g++; b++; SDL_SetTextureColorMod(t_p.board->cursor.texture,200 - r,200 - g, 200 - b); } SDL_SetTextureColorMod(t_p.board->background_texture,r,g,b); render_scene(t_p.window,t_p.renderer,t_p.clear_color,t_p.board); printf("Main timer callback returned for %d time",++counter); return interval; } return 0; }
INLINE void set_coloralphamode(SDL_Texture *texture_id, const render_color *color) { UINT32 sr = (UINT32)(255.0f * color->r); UINT32 sg = (UINT32)(255.0f * color->g); UINT32 sb = (UINT32)(255.0f * color->b); UINT32 sa = (UINT32)(255.0f * color->a); if (color->r >= 1.0f && color->g >= 1.0f && color->b >= 1.0f && IS_OPAQUE(color->a)) { SDL_SetTextureColorMod(texture_id, 0xFF, 0xFF, 0xFF); SDL_SetTextureAlphaMod(texture_id, 0xFF); } /* coloring-only case */ else if (IS_OPAQUE(color->a)) { SDL_SetTextureColorMod(texture_id, sr, sg, sb); SDL_SetTextureAlphaMod(texture_id, 0xFF); } /* alpha and/or coloring case */ else if (!IS_TRANSPARENT(color->a)) { SDL_SetTextureColorMod(texture_id, sr, sg, sb); SDL_SetTextureAlphaMod(texture_id, sa); } else { SDL_SetTextureColorMod(texture_id, 0xFF, 0xFF, 0xFF); SDL_SetTextureAlphaMod(texture_id, 0xFF); } }
/* -------------------------------------------------------------------------------- RENDER FADE -------------------------------------------------------------------------------- * This method is similar to render_self() except it also gets and modifies the * alpha value of the texture instance, in effect, 'fading it out'. */ void Texture::render_fade( void ) { if( mFading ) { /* Get the alpha value */ Uint8 a; SDL_GetTextureAlphaMod( mTexture, &a ); /* Decrease the alpha value or set it to zero */ if( a >= 8 ) a -= 8; else a = 0; /* Apply the modified alpha to the texture */ SDL_SetTextureAlphaMod( mTexture, a ); /* Create the draw rect and render the texture */ SDL_Rect dRect = { mPos.x, mPos.y, mWidth, mHeight }; SDL_RenderCopy( gRenderer, mTexture, NULL, &dRect ); /* If we've hit zero alpha, reset the texture and switch off fading */ if( a == 0 ) { mFading = false; SDL_SetTextureAlphaMod( mTexture, (Uint8)255 ); } } }
Uint32 main_timer_callback(Uint32 interval,void* param){ if(param != NULL){ render_data_t data = *((render_data_t*)param); if((data.window != NULL )&& (data.renderer != NULL) && *data.running == true){ //Check if the game is still running before doing anything if(data.event->key.keysym.scancode == SDL_SCANCODE_ESCAPE){ *data.running = false; } SDL_GetMouseState(&data.board->cursor.rectangle.x,&data.board->cursor.rectangle.y); //Handle input from current user or AI handle_player_input(param); if(data.event->type == SDL_MOUSEBUTTONDOWN | data.event->type == SDL_MOUSEMOTION){ if(data.event->button.button == SDL_BUTTON_LEFT){ SDL_SetTextureColorMod(data.board->cursor.texture,128,0,0); SDL_SetTextureAlphaMod(data.board->cursor.texture,255); } else if(data.event->button.button == SDL_BUTTON_RIGHT){ SDL_SetTextureColorMod(data.board->cursor.texture,0,0,128); SDL_SetTextureAlphaMod(data.board->cursor.texture,255); } } else{ SDL_SetTextureColorMod(data.board->cursor.texture,156,156,156); SDL_SetTextureAlphaMod(data.board->cursor.texture,128); } render_scene(param); return interval; } } return 0; }
void image::sdraw(SDL_Renderer *_ren, signed int x, signed int y, unsigned int n, unsigned int r, unsigned int g, unsigned int b, unsigned int a) { SDL_SetTextureColorMod(img, r, g, b); SDL_SetTextureAlphaMod(img, a); //glColor4f(r / 255.0, g / 255.0, b / 255.0, a / 255.0); _draw(_ren, x, y, n); SDL_SetTextureAlphaMod(img, 255); SDL_SetTextureColorMod(img, 255, 255, 255); }
void MusicSelection::renderClickableButtons() { for (std::vector<MusicSelectionClickableButton>::iterator i = clickableButtons.begin(); i != clickableButtons.end(); ++i) { if (i->text == "EASY" || i->text == "NORMAL" || i->text == "HARD" || i->text == "EXTREME") { SDL_Rect backgroundRect = { i->x, i->y, i->width, i->height }; SDL_Rect shadowRect = backgroundRect; //Render shadow SDL_SetTextureColorMod(i->backgroundTexture.texture, 0, 0, 0); SDL_SetTextureAlphaMod(i->backgroundTexture.texture, 120); shadowRect.x = backgroundRect.x + (int)(initVariables.musicSelection_difficulty_button_shadow * ((float)initVariables.screen_width)); shadowRect.y = backgroundRect.y + (int)(initVariables.musicSelection_difficulty_button_shadow * ((float)initVariables.screen_width)); SDL_RenderCopy(Renderer, i->backgroundTexture.texture, NULL, &shadowRect); SDL_SetTextureAlphaMod(i->backgroundTexture.texture, 255); //Change colors respectively RGB difficultyColor; if (i->text == "EASY") { difficultyColor = initVariables.musicSelection_color_easy; } else if (i->text == "NORMAL") { difficultyColor = initVariables.musicSelection_color_normal; } else if (i->text == "HARD") { difficultyColor = initVariables.musicSelection_color_hard; } else if (i->text == "EXTREME") { difficultyColor = initVariables.musicSelection_color_extreme; } //Render background SDL_SetTextureColorMod(i->backgroundTexture.texture, difficultyColor.r, difficultyColor.g, difficultyColor.b); SDL_RenderCopy(Renderer, i->backgroundTexture.texture, NULL, &backgroundRect); //Render text SDL_Rect textRect; int centerOfButtonX = i->x + ((i->width) / 2); int centerOfButtonY = i->y + ((i->height) / 2); float widthToHeightRatio = ((float)i->fontTexture.width) / ((float)i->fontTexture.height); textRect.h = i->height; textRect.w = (int)(widthToHeightRatio * ((float)textRect.h)); textRect.x = centerOfButtonX - (textRect.w / 2); textRect.y = centerOfButtonY - (textRect.h / 2); SDL_RenderCopy(Renderer, i->fontTexture.texture, NULL, &textRect); } else { if (i->backgroundTexture.texture == NULL) { SDL_Rect backgroundRect = { i->x, i->y, i->width, i->height }; SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 155); SDL_RenderFillRect(Renderer, &backgroundRect); } if (i->fontTexture.texture != NULL) { SDL_Rect textRect = { i->x, i->y, i->width, i->height }; SDL_RenderCopy(Renderer, i->fontTexture.texture, NULL, &textRect); } } } }
void Particle::draw(){ sprite->step = alpha / 16; switch(color){ case BLUE: SDL_SetTextureAlphaMod(ResourceManager::getTexture("BlueParticle"),alpha); sprite->draw(x,y,angle); break; case RED: SDL_SetTextureAlphaMod(ResourceManager::getTexture("RedParticle"),alpha); spriteRed->draw(x,y,angle); break; } }
void Sprite::Load(SDL_Renderer* rend, std::string path, bool org) { //The final texture SDL_DestroyTexture(newTexture); newTexture = NULL; //Load image at specified path SDL_Surface* loadedSurface = IMG_Load(path.c_str()); if (loadedSurface == NULL) Debug::Fatal("Could not load image: " + path); //Create texture from surface pixels newTexture = SDL_CreateTextureFromSurface(rend, loadedSurface); if (newTexture == NULL) Debug::Fatal("Could not create texture from file: " + path); if (org) Scale = Vector(loadedSurface->w, loadedSurface->h); //Get rid of old loaded surface SDL_FreeSurface(loadedSurface); Texture = newTexture; SDL_SetTextureColorMod(Texture, Col.Red, Col.Green, Col.Blue); SDL_SetTextureBlendMode(Texture, SDL_BLENDMODE_BLEND); SDL_SetTextureAlphaMod(Texture, Col.Alpha); }
void renderParticle(Particle* part, int partNumber) { SDL_Rect *clip = NULL; //if (!isAlive(part)) return; if ( partNumber == 0 ) return; SDL_Rect smokeLocal = smoke; smokeLocal.h = round(smoke.h * part->m_scale); smokeLocal.w = round(smoke.w * part->m_scale); smokeLocal.x = round(part->m_x); //part->m_x-smoke.h * part->m_scale/2; smokeLocal.y = round(part->m_y); //part->m_y+smoke.w * part->m_scale/2; //printf("test"); SDL_SetTextureAlphaMod(smokeTexture, part->m_alpha * 150 ); SDL_RenderCopyEx(renderer, smokeTexture, clip, &smokeLocal, 0 /*part->m_angle*/, NULL, SDL_FLIP_NONE); }
void affiche_tower(SDL_Renderer *r, t_tower *s){ if (s->actif) { SDL_Rect Src; SDL_Rect Dst; Src.x = s->img_current * s->anim->tx; Src.y = 0; Src.w = s->anim->tx; Src.h = s->anim->ty; Dst.x = s->x - s->anim->tx/2; // permet de center le sprite sur les coordonnées Dst.y = s->y - s->anim->ty/2; Dst.w = s->anim->tx; Dst.h = s->anim->ty; SDL_SetTextureAlphaMod (s->anim->texture, s->visible); // Affichage if (s->selected) { SDL_SetRenderDrawColor (r, 254, 0, 0, 50); SDL_RenderDrawRect(r, &Dst); SDL_SetRenderDrawColor (r, 0, 0, 0, 50); affiche_tower_selected( r, s); } SDL_RenderCopyEx(r, s->anim->texture, &Src, &Dst, s->angle, NULL, 0); } }
void SDLRenderBackend::drawText(int x, int y, int w, SDL_Color color, const std::string &text) { SDL_Texture *textTexture = getTextRenderTexture(m_renderer, m_font, text, color, w); SDL_Texture *textShadowTexture = getTextRenderTexture(m_renderer, m_font, text, {0, 0, 0, 255}, w); SDL_SetTextureAlphaMod(textShadowTexture, 90); // render the shadow { Sprite sprite(textShadowTexture); sprite.setPosition(x+2, y+2); SDL_Rect dest = sprite.rect(); SDL_RenderCopyEx(m_renderer, textShadowTexture, nullptr, &dest, sprite.angle(), nullptr, SDL_FLIP_NONE); } // render the text { Sprite sprite(textTexture); sprite.setPosition(x, y); SDL_Rect dest = sprite.rect(); SDL_RenderCopyEx(m_renderer, textTexture, nullptr, &dest, sprite.angle(), nullptr, SDL_FLIP_NONE); } // TODO: create texture cache SDL_DestroyTexture(textTexture); SDL_DestroyTexture(textShadowTexture); }
static void render(void) { SDL_SetTextureAlphaMod(title_rotate[rotate_index].texture, 0xFF * brightness); SDL_SetRenderDrawColor(display.renderer, 0x20, 0x20, 0x20, 0x20); SDL_RenderClear(display.renderer); SDL_SetRenderDrawBlendMode(display.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawColor(display.renderer, 0xFF, 0xFF, 0xFF, 0x20); draw_text_splat(&title_rotate[rotate_index], -1, 0); draw_sprite(panel_timer, 16, 28); timer_blit(ticks_countup, REFERENCE_WIDTH - 22, 32); draw_text_splat(&elapsed_time, -1, 56); SDL_RenderDrawLine(display.renderer, 0, 80, REFERENCE_WIDTH, 80); draw_text_splat(&achievements, -1, 81); if (achievement_index != -1) { draw_sprite(panel_achievement, 0, 106); draw_sprite(achievement_index, 9, 114); draw_text_splat(&ach_title[achievement_index], 48, 130 - (ach_title[achievement_index].source_rect.h / 2)); draw_text_splat(&ach_desc[achievement_index], 4, 152); } else { draw_text_splat(&achievements_none, -1, 130); } SDL_RenderDrawLine(display.renderer, 0, 224, REFERENCE_WIDTH, 224); if (achievement_count > 1) { draw_text_splat(&achievements_more, -1, 232); draw_sprite(sui_arrow_left, 0, 226); draw_sprite(sui_arrow_right, REFERENCE_WIDTH - 32, 226); } }
void Sprite::draw() { //scale stuff this-> s_width = this -> width * this -> scale; this-> s_height = this -> height * this -> scale; //Set rendering space and render to screen this -> rect = { this -> pos . x - ( this -> s_width / 2 ), this -> pos . y - ( this -> s_height / 2 ), this -> s_width, this -> s_height }; const SDL_Rect * srcrect2 = & srcrect; const SDL_Rect * rect2 = & rect; //rotation center stuff center = { this -> s_width / 2, this -> s_height / 2}; SDL_Point * center2 = & center; //texture stuff SDL_SetTextureColorMod( texture, this -> red, this -> green, this -> blue ); SDL_SetTextureAlphaMod( this -> texture, this -> alpha ); //draw SDL_RenderCopyEx( renderer, texture, srcrect2, rect2, angle, center2, flip ); }
//------------------------------------------------------------------------------------------------- void Visuals::DrawSpriteOntoScreenBuffer(Uint16 index) { SDL_Rect destinationRect; int windowWidth; int windowHeight; Uint32 textureFormat; int textureAccess; int textureWidth; int textureHeight; SDL_GetWindowSize(Window, &windowWidth, &windowHeight); SDL_QueryTexture(Sprites[index].Texture, &textureFormat, &textureAccess, &textureWidth, &textureHeight); float winWidthFixed; float winHeightFixed; if (ForceAspectRatio == false) { winWidthFixed = (float)windowWidth / 640; winHeightFixed = (float)windowHeight / 480; } else { winWidthFixed = 1; winHeightFixed = 1; } destinationRect.x = ( Sprites[index].ScreenX * (winWidthFixed) ) - ( ( (textureWidth * Sprites[index].ScaleX) * (winWidthFixed) ) / 2 ); destinationRect.y = ( Sprites[index].ScreenY * (winHeightFixed) ) - ( ( (textureHeight * Sprites[index].ScaleY) * (winHeightFixed) ) / 2 ); destinationRect.w = textureWidth * Sprites[index].ScaleX * (winWidthFixed); destinationRect.h = textureHeight * Sprites[index].ScaleY * (winHeightFixed); SDL_SetTextureColorMod(Sprites[index].Texture, Sprites[index].RedHue, Sprites[index].GreenHue, Sprites[index].BlueHue); SDL_SetTextureAlphaMod(Sprites[index].Texture, Sprites[index].Transparency); if (Sprites[index].FlipX == false && Sprites[index].FlipY == false) { SDL_RenderCopyEx(Renderer, Sprites[index].Texture, NULL, &destinationRect, Sprites[index].RotationDegree , NULL, SDL_FLIP_NONE); } else if (Sprites[index].FlipX == true && Sprites[index].FlipY == false) { SDL_RenderCopyEx(Renderer, Sprites[index].Texture, NULL, &destinationRect, Sprites[index].RotationDegree , NULL, SDL_FLIP_HORIZONTAL); } else if (Sprites[index].FlipX == false && Sprites[index].FlipY == true) { SDL_RenderCopyEx(Renderer, Sprites[index].Texture, NULL, &destinationRect, Sprites[index].RotationDegree , NULL, SDL_FLIP_VERTICAL); } else if (Sprites[index].FlipX == true && Sprites[index].FlipY == true) { double flipHorizontallyAndVerticallyDegreeFix = Sprites[index].RotationDegree+180; SDL_RenderCopyEx(Renderer, Sprites[index].Texture, NULL, &destinationRect, flipHorizontallyAndVerticallyDegreeFix , NULL, SDL_FLIP_NONE); } }
void Render_SW_SDL::renderTextureCur(float x, float y, float w, float h, float ani_top, float ani_bottom, float ani_left, float ani_right) { if(!m_currentTexture) { renderRect(x, y, w, h, (unsigned char)(255.f*color_binded_texture[0]), (unsigned char)(255.f*color_binded_texture[1]), (unsigned char)(255.f*color_binded_texture[2]), (unsigned char)(255.f*color_binded_texture[3]) ); return; } SDL_Rect sourceRect = { (int)roundf((float)m_currentTextureRect.width()*ani_left), (int)roundf((float)m_currentTextureRect.height()*ani_top), abs((int)roundf((float)m_currentTextureRect.width()*ani_right)-(int)roundf((float)m_currentTextureRect.width()*ani_left)), abs((int)roundf((float)m_currentTextureRect.height()*ani_bottom)-(int)roundf((float)m_currentTextureRect.height()*ani_top)) }; SDL_Rect destRect = scaledRect(x, y, w, h); SDL_SetTextureColorMod( m_currentTexture, (unsigned char)(255.f*color_binded_texture[0]), (unsigned char)(255.f*color_binded_texture[1]), (unsigned char)(255.f*color_binded_texture[2])); SDL_SetTextureAlphaMod( m_currentTexture, (unsigned char)(255.f*color_binded_texture[3])); SDL_RenderCopy( m_gRenderer, m_currentTexture, &sourceRect, &destRect ); }
d_define_method_override(label, set_maskA)(struct s_object *self, unsigned int alpha) { d_using(label); label_attributes->last_mask_A = alpha; if (label_attributes->image) SDL_SetTextureAlphaMod(label_attributes->image, alpha); return self; }
void TransformableViewScene::Render(SDL_Renderer *renderer) { SDL_Rect srcrect; srcrect.x = 0; srcrect.y = 0; srcrect.w = targetSize.x; srcrect.h = targetSize.y; SDL_Rect dstrect; dstrect.x = origin.x; dstrect.y = origin.y; dstrect.w = size.x; dstrect.h = size.y; auto target = SDL_GetRenderTarget(renderer); int res = SDL_SetRenderTarget(renderer, renderTarget.get()); Uint8 r,g,b,a; SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_RenderClear(renderer); SDL_SetRenderDrawColor(renderer, r, g, b, a); scene->Render(renderer); res = SDL_SetRenderTarget(renderer, target); res = SDL_SetTextureAlphaMod(renderTarget.get(), opacity * 255); //SDL_RenderCopy(renderer, renderTarget.get(), &srcrect, &dstrect); SDL_RenderCopyEx(renderer, renderTarget.get(), &srcrect, &dstrect, rotation, &axis, SDL_FLIP_NONE); }
void showSplashScreen(void) { SDL_Rect rect; SDL_Texture * splashTexture = getTexture("assets/splash.png"); int w, h; SDL_QueryTexture(splashTexture, NULL, NULL, &w, &h); rect.w = w; rect.h = h; rect.x = viewport.w / 2 - w / 2; rect.y = viewport.h / 2 - h / 2; SDL_RendererInfo info; SDL_GetRendererInfo(renderer, &info); SDL_Delay(100); int alpha = 1; while(alpha < 255) { if(SDL_SetTextureAlphaMod(splashTexture, alpha) != 0) { quit(1); } SDL_RenderClear(renderer); SDL_RenderCopy(renderer, splashTexture, NULL, &rect); SDL_RenderPresent(renderer); SDL_Delay(TICK_INTERVAL); alpha = alpha + 6; } }
void image_set_alpha( void *image, float alpha ) { Uint8 alpha_int; alpha_int = (Uint8)( 255.0f * alpha ); SDL_SetTextureAlphaMod( asset_image_handle(image), alpha_int ); }
void affiche_sprite(SDL_Renderer *r, t_sprite *s){ SDL_Rect Src; SDL_Rect Dst; Src.x = s->img_current * s->anim->tx; Src.y = s->direction * s->anim->ty; Src.w = s->anim->tx; Src.h = s->anim->ty; Dst.x = s->x - s->anim->tx/2; // permet de center le sprite sur les coordonnées Dst.y = s->y - s->anim->ty/2; Dst.w = s->anim->tx; Dst.h = s->anim->ty; // mode transparent de l'animimation à l'arrivé if (s->is_actif == false && s->visible > 0 && s->time_before_ativiation == 0 ) { s->visible -=10 ; } if (s->visible < 0 ) { s->visible = 0; } SDL_SetTextureAlphaMod (s->anim->texture, s->visible); // SDL_SetRenderDrawColor (r, 254, 0, 0, 50); // Affichage SDL_RenderCopy ( r, s->anim->texture , &Src, &Dst); }
void Sprite::Draw(Window* rend, bool stick) { SetPos(); if (Col.Alpha != 255) { SDL_SetTextureAlphaMod(Texture, Col.Alpha); } if (!stick) { Source.x -= rend->Camera.position.x / rend->Camera.scale; Source.y -= rend->Camera.position.y / rend->Camera.scale; Source.x *= rend->Camera.scale; Source.y *= rend->Camera.scale; Source.w *= rend->Camera.scale; Source.h *= rend->Camera.scale; Vector roundedPos = Vector(Source.x, Source.y); roundedPos.x /= rend->Camera.scale; roundedPos.y /= rend->Camera.scale; Source.x = std::round(roundedPos.x) * rend->Camera.scale; Source.y = std::round(roundedPos.y) * rend->Camera.scale; } SDL_RenderCopyEx(rend->GetRenderer(), Texture, NULL, &Source, rotation, ¢erPoint, flipSDL); }
int CKT::GFX::CGfxObject::Render() { if (!m_IsVisible) return 0; SDL_Rect rDst = { (int)m_PosX, (int)m_PosY, (int)(m_Width + 0.5f), (int)(m_Height + 0.5f) }; if (m_AlphaMod < 255) { SDL_SetTextureBlendMode(m_Texture, m_BlendMode); SDL_SetTextureAlphaMod(m_Texture, m_AlphaMod); } if (m_UseRotate) { if (m_rClip.w == 0 && m_rClip.h == 0) CKT::GFX::renderTexture(m_Texture, m_pRenderer, rDst, m_Angle, &m_RotationCenter, m_Flipping); else CKT::GFX::renderTexture(m_Texture, m_pRenderer, rDst, m_Angle, &m_RotationCenter, m_Flipping, &m_rClip); } else { if (m_rClip.w == 0 && m_rClip.h == 0) CKT::GFX::renderTexture(m_Texture, m_pRenderer, rDst); else CKT::GFX::renderTexture(m_Texture, m_pRenderer, rDst, &m_rClip); } return 0; }
void Render_SW_SDL::renderTexture(PGE_Texture *texture, float x, float y) { if(!texture) return; setRenderTexture( texture->texture ); m_currentTextureRect.setRect( 0, 0, texture->w, texture->h ); if(!m_currentTexture) { renderRect(x, y, texture->w, texture->h, (unsigned char)(255.f*color_binded_texture[0]), (unsigned char)(255.f*color_binded_texture[1]), (unsigned char)(255.f*color_binded_texture[2]), (unsigned char)(255.f*color_binded_texture[3]) ); return; } SDL_Rect aRect = scaledRectIS(x, y, texture->w, texture->h); SDL_SetTextureColorMod( m_currentTexture, (unsigned char)(255.f*color_binded_texture[0]), (unsigned char)(255.f*color_binded_texture[1]), (unsigned char)(255.f*color_binded_texture[2])); SDL_SetTextureAlphaMod( m_currentTexture, (unsigned char)(255.f*color_binded_texture[3])); SDL_RenderCopy( m_gRenderer, m_currentTexture, NULL, &aRect ); setUnbindTexture(); }
/** * @brief Test to see if we can vary the alpha of the texture. Helper function. * * \sa * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureAlphaMod * http://wiki.libsdl.org/moin.cgi/SDL_GetTextureAlphaMod * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture */ static int _hasTexAlpha(void) { int fail; int ret; SDL_Texture *tface; Uint8 a; /* Get test face. */ tface = _loadTestFace(); if (tface == NULL) return 0; /* See if supported. */ fail = 0; ret = SDL_SetTextureAlphaMod( tface, 100 ); if (!_isSupported(ret)) fail = 1; ret = SDL_GetTextureAlphaMod( tface, &a ); if (!_isSupported(ret)) fail = 1; /* Clean up. */ SDL_DestroyTexture( tface ); if (fail) return 0; else if (a != 100) return 0; return 1; }
void Render_SW_SDL::renderTexture(PGE_Texture *texture, float x, float y, float w, float h, float ani_top, float ani_bottom, float ani_left, float ani_right) { if(!texture) return; setRenderTexture( texture->texture ); m_currentTextureRect.setRect( 0, 0, texture->w, texture->h ); if(!m_currentTexture) { renderRect(x, y, w, h, (unsigned char)(255.f*color_binded_texture[0]), (unsigned char)(255.f*color_binded_texture[1]), (unsigned char)(255.f*color_binded_texture[2]), (unsigned char)(255.f*color_binded_texture[3]) ); return; } SDL_Rect sourceRect = { (int)roundf((float)texture->w*ani_left), (int)roundf((float)texture->h*ani_top), (int)roundf((float)texture->w*ani_right)-(int)roundf((float)texture->w*ani_left), (int)roundf((float)texture->h*ani_bottom)-(int)roundf((float)texture->h*ani_top) }; SDL_Rect destRect = scaledRect(x, y, w, h); SDL_SetTextureColorMod( m_currentTexture, (unsigned char)(255.f*color_binded_texture[0]), (unsigned char)(255.f*color_binded_texture[1]), (unsigned char)(255.f*color_binded_texture[2])); SDL_SetTextureAlphaMod( m_currentTexture, (unsigned char)(255.f*color_binded_texture[3])); SDL_RenderCopy( m_gRenderer, m_currentTexture, &sourceRect, &destRect ); setUnbindTexture(); }
void SDLFrontend::renderImage (Texture* texture, int x, int y, int w, int h, int16_t angle, float alpha) { assert(_renderer); if (!texture->isValid()) return; getTrimmed(texture, x, y, w, h); const SDL_Rect destRect = { x, y, w, h }; const TextureRect& r = texture->getSourceRect(); const SDL_Rect srcRect = { r.x, r.y, r.w, r.h }; SDL_Texture *t = static_cast<SDL_Texture*>(texture->getData()); SDL_SetTextureAlphaMod(t, alpha * 255); SDL_SetTextureColorMod(t, _color[0] * 255, _color[1] * 255, _color[2] * 255); if (_softwareRenderer) { // angle is 0 here - because on the fly rotating is really expensive // TODO: create a lockup map here? if (SDL_RenderCopyEx(_renderer, t, &srcRect, &destRect, 0.0, nullptr, texture->isMirror() ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE) != 0) { error(LOG_CLIENT, "could not render texture " + texture->getName()); texture->setData(nullptr); } } else { if (SDL_RenderCopyEx(_renderer, t, &srcRect, &destRect, static_cast<double>(angle), nullptr, texture->isMirror() ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE) != 0) { error(LOG_CLIENT, "could not render texture " + texture->getName()); texture->setData(nullptr); } } }
void SDLSingleton::DoRender() { SDL_RenderClear(m_pRenderer); SDL_UpdateTexture(m_pGameTexture, NULL, m_pGameScreen->pixels, m_pGameScreen->pitch); SDL_Rect srcRect; SDL_Rect destRect; srcRect.x = 0; srcRect.y = 0; srcRect.w = destRect.w = 320; srcRect.h = destRect.h = 200; destRect.x = 0; destRect.y = 0; destRect.x = 0; destRect.y = 0; destRect.w = SDL_RATIO_X(destRect.w); destRect.h = SDL_RATIO_Y(destRect.h); SDL_SetTextureAlphaMod(m_pGameTexture, 255); SDL_RenderCopyEx(SDLSingleton::GetInstance()->GetRenderer(), m_pGameTexture, &srcRect, &destRect, 0, 0, SDL_FLIP_NONE); SDL_RenderPresent(m_pRenderer); }
void Image::SetAlpha(Uint8 a) { if (SDL_SetTextureAlphaMod(texture, a)) { std::ostringstream msg; msg << "Failed to set alpha; " << SDL_GetError(); throw(std::runtime_error(msg.str())); } }
void FadeScene::Render(SDL_Renderer *renderer) { SDL_Rect rect; rect.x = 0; rect.y = 0; rect.w = _w; rect.h = _h; auto target = SDL_GetRenderTarget(renderer); int res = SDL_SetRenderTarget(renderer, _renderTarget.get()); _scene->Render(renderer); res = SDL_SetRenderTarget(renderer, target); if (_scene->Running() && _opacity != 255) { _opacity = std::min(_opacity + _speed, 255.0); } else if (!_scene->Running() && _opacity != 0) { _opacity = std::max(_opacity - _speed, 0.0); } res = SDL_SetTextureAlphaMod(_renderTarget.get(), _opacity); SDL_RenderCopy(renderer, _renderTarget.get(), &rect, &rect); }