Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8886571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:35:24+00:00 2026-06-14T21:35:24+00:00

Suppose I have a SDL_Surface that is just one image. What if I wanted

  • 0

Suppose I have a SDL_Surface that is just one image.
What if I wanted to make that SDL_Surface have three copies of that image, one below the other?

I came up with this function, but it doesn’t show anything:

void ElementView::adjust() 
{
    int imageHeight = this->img->h;
    int desiredHeight = 3*imageHeight;

    int repetitions =  desiredHeight / imageHeight ;
    int remainder = desiredHeight % imageHeight ;

    SDL_Surface* newSurf = SDL_CreateRGBSurface(img->flags, img->w, desiredHeight, 32, img->format->Rmask, img->format->Gmask, img->format->Bmask,img->format->Amask);

    SDL_Rect rect;
    memset(&rect, 0, sizeof(SDL_Rect));
    rect.w = this->img->w;
    rect.h = this->img->h;

    for (int i = 0 ; i < repetitions ; i++) 
    {
        rect.y = i*imageHeight;
        SDL_BlitSurface(img,NULL,newSurf,&rect);
    }
    rect.y += remainder;
    SDL_BlitSurface(this->img,NULL,newSurf,&rect);

    if (newSurf != NULL) {
        SDL_FreeSurface(this->img);
        this->img = newSurf;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:35:26+00:00Added an answer on June 14, 2026 at 9:35 pm

    I think you should

    • Create a new surface that is 3 times as long as the initial one
    • Copy from img to the new surface using code similar to what you have (SDL_BlitSurface), except having the destination as your new surface
    • SDL_FreeSurface on your original img
    • Assign your new surface to img

    Edit: Here is some sample code, didn’t have time to test it though…

    void adjust(SDL_Surface** img)
    {
        SDL_PixelFormat *fmt = (*img)->format;
        SDL_Surface* newSurf = SDL_CreateRGBSurface((*img)->flags, (*img)->w, (*img)->h * 3, fmt->BytesPerPixel * 8, fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask);
    
        SDL_Rect rect;
        memset(&rect, 0, sizeof(SDL_Rect));
        rect.w = (*img)->w;
        rect.h = (*img)->h;
    
        int i = 0;
        for (i ; i < 3; i++) 
        {
            SDL_BlitSurface(*img,NULL,newSurf,&rect);
            rect.y += (*img)->h;
        }
    
        SDL_FreeSurface(*img);
        *img = newSurf;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this animation that start at some point : myElement.animate({ top: -currentTempImageX,
Suppose you have val docs = List(List(one, two), List(two, three)) where e.g. List(one, two)
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
Suppose I have an array that looks like this array ([apple] => 1, [dog]=>2,
Suppose I have an HTML page that looks something like this: <html><body> 00123 <input
Suppose I have a vertical menu that is coded like this: <ul class=sub-menu> <li
Suppose i have an XML file, that i use as local database, like this):
Suppose we have buyers and sellers that are trying to find each other in
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have a static method of my class that returns an object of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.