IDirect3DTexture9 to char or string?

Started by
3 comments, last by Photon Man 14 years, 10 months ago
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.
Advertisement
I think you're after IDirect3DTexture9::LockRect ( and later, IDirect3DTexture9::UnlockRect. )
Nope, tried that. This is my point, I can't figure out the whole darn thing!

void* crap;D3DLOCKED_RECT lckRect;/* What the heck are these filled with???lckRect::Pitch = ?;lckRect::pBits = ?;*/IDirect3DTexture9::LockRect(0, lckRect, NULL,                             D3DLOCK_DONOTWAIT | D3DLOCK_NO_DIRTY_UPDATE);IDirect3DTexture9::GetPrivateData(/*???What do I put here???*/,                                    crap, 0);IDirect3DTexture9::UnlockRect(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?*/;



GetPrivateData doesn't do what you think it does. LockRect/UnlockRect does what you want.

An example of usage:

IDirect3DTexture9* myTexture;/*...*/D3DLOCKED_RECT lckRect;myTexture->LockRect(0, &lckRect, NULL, D3DLOCK_READONLY);// lckRect.pBits now points to the texture datamyTexture->UnlockRect(0);


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.
NextWar: The Quest for Earth available now for Windows Phone 7.
LOL!

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{public:   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 //////

Parameters

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

/////////////////////////


Again, thanks for helping an impatient soul.

This topic is closed to new replies.

Advertisement