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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:54:23+00:00 2026-06-04T19:54:23+00:00

I can’t seem to find a way to create a texture from the surface

  • 0

I can’t seem to find a way to create a texture from the surface data I acquire through the front buffer data of my application

This is the code I’m pretty sure is working (Direct X 9, C++)

// capture screen
IDirect3DSurface9* pSurface;
g_pd3dDevice->CreateOffscreenPlainSurface(640, 480,
    D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pSurface, NULL);
g_pd3dDevice->GetFrontBufferData(0, pSurface);

Now that I’ve got my frontBufferData, I would like to create a IDirect3DTexture9 object with it.

This function /
D3DXCreateTextureFromFileInMemory /
seemed the most logical but doesn’t seem to do the trick.

I’m pretty sure there is a way to do this, tough I am unsure how. Any help would be greatly welcome!

Thanks!

  • 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-04T19:54:24+00:00Added an answer on June 4, 2026 at 7:54 pm

    It’s preferable to utilize GetRenderTargetData() instead of GetFrontBufferData(), because the former is faster. With that said, that’s not really the question. You wish to store the data you get from the frontbuffer, or the stuff you’re currently observing on the screen, into a texture.

    First of all, IDirect3DTexture9 and IDirect3DSurface9 are actually, kind of, siblings, but they’re not the same even though at some point in their class hiearchy they converge to IDirect3DResource9 (which is logical, as they are resources). What’s neat about both of them is that they implement common functionality, specifically the possibility of LockRect() and manually copying the data from the surface (which is, crudely, just one mipmap level surface (a bunch of pixels) to the texture (which may consist of multiple mipmap levels). Therefore, your target is the level0 surface of the texture object.

    With that in mind, since all CreateOffscreenPlainSurface() are considered to stand alone, we cannot find a parent texture of which this surface might be a child of (being a particular mipmap of a texture). Long story short, if we don’t LockRect both of them and manually copy the data, we can use StretchRect().

    While its name might not give away one of its purpose, it’ll help us out here. Remember about our comparison talk between textures and surfaces, surfaces kind of being their little brother. Well, if you define a texture properly (same as the surface), you’re actually getting automated miplevels which you can manually define how many of them are there. But in essence, each of these levels is a surface. And “converting” from IDirect3DSurface9 to IDirect3DTexture9 is just a matter of filling in the proper miplevel surface (which in this case ought to be level0, since it is a screenshot basically).

    Therefore, sipping this into coarse code gives us:

    IDirect3DTexture9* texture; // needs to be created, of course
    IDirect3DSurface9* dest = NULL; // to be our level0 surface of the texture
    texture->GetSurfaceLevel(0, &dest);
    g_pD3DDevice->StretchRect(pSurface, NULL, dest, NULL, D3DTEXF_LINEAR);
    

    And there you go, one IDirect3DTexture9 to go. Would you like fries with that, sir? Do note I’m working off memory here, I haven’t touched DX9 in quite a while (dropped in favor of DX10). Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't seem to figure out what's wrong with the simple getJSON call below. It's
Can anybody tell what is the best(easy) way to sort the following string 'index'
Can't figure out how to do this in a pretty way : I have
Can MOSS integrate and get user profiles from multiple Active Directory and/or LDAP stores?
Can a Visual Studio 2008 custom tool be passed additional parameters from the custom
Can somebody give me advice on how to create a recursive version of GetEnumerator()?
Can't work out a way to make an array of buttons in android. This
Can anyone help me trying to find out why this doesn't work. The brushes
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Does anyone know how can I replace this 2 symbol below from the string

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.