Jump to content
  • Advertisement
Sign in to follow this  
Photon Man

IDirect3DTexture9 to char or string?

This topic is 3399 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I know this is an idiot question, but losers gotta learn some time, don't they? How do I extract the RGB bits data from a IDirect3DTexture9? I want to put it into a char[], or string. Actually a stringstream would be best. My plan is to write a simple function that reads the char[], string, *what-have-you*, of the newly loaded IDirect3DTexture9 bit data, then take every RGB bit and individually draw them to a window with a simple GDI PlotPixel() function. (Yes, I'm sorry, it has to be GDI...) I've tried a lot with the IDirect3DTexture9::GetPrivateData() function to no avail. Is this even the right function to use? Thanks for your time.

Share this post

Link to post
Share on other sites
Nope, tried that. This is my point, I can't figure out the whole darn thing!

void* crap;

/* What the heck are these filled with???
lckRect::Pitch = ?;
lckRect::pBits = ?;

IDirect3DTexture9::LockRect(0, lckRect, NULL,

IDirect3DTexture9::GetPrivateData(/*???What do I put here???*/,
crap, 0);


// now I have the pointer to the buffer, a.k.a "crap"
// Now what?
char buffer[80];

buffer[0] = crap;
buffer[1] = crap /* [plus] what?? Or how do I get to the next bit?*/;

Share this post

Link to post
Share on other sites
GetPrivateData doesn't do what you think it does. LockRect/UnlockRect does what you want.

An example of usage:

IDirect3DTexture9* myTexture;
myTexture->LockRect(0, &lckRect, NULL, D3DLOCK_READONLY);

// lckRect.pBits now points to the texture data


The pLockedRect parameter of LockRect is an out parameter, meaning the functions fills in the data. You're not supposed to set those members yourself.

You seem to be a little confused when it comes to C++ in general - LockRect() is a non-static member function, so you need to call it on an actual instance and not on the actual class. '::' is the scope resolution operator, you don't use it to access non-static members of a struct. That's what the '.' (dot) operator is for. Before attempting to learn a large, complex API such as DirectX, I suggest that you become familar with C++ first - otherwise you'll have a hard time understanding how to use the API.

Share this post

Link to post
Share on other sites

Thanks Sc4Freak! Actually to tell the truth, I knew about those stupid "::", ".", "->", symbols and the use for each. I believe the "." is for structures, (like you said), the "->" is for class members, and the "::" is used when declaring a class function like so:

class Myclass


int SubNumbers(int number, int sub);

/* fill in whatever */

// then when declaring the function you'd put.
Myclass::SubNumbers(int number, int sub)
/* Fill in blanks */
return answer;

Indeed, my frustration last night (when I couldn't get my coding answer) brought me to a crazed state of coding like a lunatic. I was too angered to care what I typed down! (hence, notice the "crap" variable...)

Anyway, I'll have to take more care when reading the MSDN library. I suppose the [in] and [out] under the Parameter name should have given me a clue...

///// MSDN Library //////


[in] Specifies the level of the texture resource to lock.
[out] Pointer to a D3DLOCKED_RECT structure, describing the locked region.


Again, thanks for helping an impatient soul.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!