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 714411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:04:18+00:00 2026-05-14T05:04:18+00:00

Can anybody help with converting an SDL_Surface object, a texture loaded from a file,

  • 0

Can anybody help with converting an SDL_Surface object, a texture loaded from a file, into an IDirect3DTexture9 object.

  • 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-05-14T05:04:19+00:00Added an answer on May 14, 2026 at 5:04 am

    I honestly don’t know why you would ever want to do this. It sounds like a truly horrible idea for a variety of reasons, so please tell us why you want to do this so we can convince you not to ;).

    In the meanwhile, a quick overview of how you’d go about it:

    IDirect3DTexture9* pTex = NULL;
    HRESULT            hr   = S_OK;
    hr = m_d3dDevice->CreateTexture(
        surface->w,
        surface->h,
        1,
        usage,
        format,
        D3DPOOL_MANAGED,
        &pTex,
        NULL);
    

    This creates the actual texture with the size and format of the SDL_Surface. You’ll have to fill in the usage on your own, depending on how you want to use it (see D3DUSAGE). You’ll also have to figure out the format on your own – you can’t directly map a SDL_PixelFormat to a D3DFORMAT. This won’t be easy, unless you know exactly what pixel format your SDL_Surface is.

    Now, you need to write the data into the texture. You can’t use straight memcpy here, since the SDL_Surface and the actual texture may have different strides. Here’s some untested code that may do this for you:

    HRESULT        hr;
    D3DLOCKED_RECT lockedRect;
    
    // lock the texture, so that we can write into it
    // Note: if you used D3DUSAGE_DYNAMIC above, you should 
    // use D3DLOCK_DISCARD as the flags parameter instead of 0.
    hr = pTex->LockRect(0, &lockedRect, NULL, 0);
    if(SUCCEEDED(hr))
    {
        // use char pointers here for byte indexing
        char*  src     = (char*) surface->pixels;
        char*  dst     = (char*) lockedRect->pBits;
        size_t numRows = surface->h;
        size_t rowSize = surface->w * surface->format->BytesPerPixel;
    
        // for each row...
        while(numRows--)
        {
            // copy the row
            memcpy(dst, src, rowSize);
    
            // use the given pitch parameters to advance to the next
            // row (since these may not equal rowSize)
            src += surface->pitch;
            dst += lockedRect->Pitch;
        }
    
        // don't forget this, or D3D won't like you ;)
        hr = pTex->UnlockRect(0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 363k
  • Answers 363k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The reason is that you are telling VBA to add… May 14, 2026 at 3:26 pm
  • Editorial Team
    Editorial Team added an answer Look at QMimeData and its documentation, it has a virtual… May 14, 2026 at 3:26 pm
  • Editorial Team
    Editorial Team added an answer MVC seems to have dispersed in its definition. This definition… May 14, 2026 at 3:26 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.