Question about projection matrix & textures in D3D

Started by
4 comments, last by Kikiloco 17 years, 7 months ago
First Question: I have learned to create textures in D3D using the D3DXCreateTextureFromFile function. Well I want to know the width and height of the image I load in. How do I do this? I haven't seen any functions in the LPDIRECT3DTEXTURE9 object for getting the width or height. Also, is there any way to create a texture in a similar was as OpenGL? Like by giving it an array of bytes I load in with my own code? Second Question: Could someone explain to me or direct me to a web page that explains the projection matrix? Because I want to set the matrix up to do 2D graphics. I tried setting the matrix up in the same was as glOrtho sets up the projection matrix in OpenGL but the x and y directions were like inverted. I could probably fiddle around with it enough to make it work like I want but I'd really rather understand it. Also, could someone explain to me the difference of a right handed and left handed projection matrix. I'm thinking that in the modelview matrix right handed means that with an identity matrix, you're at 0, 0, 0 looking down the negative z axis, and with left handed your looking down the positive z axis? If that's not right tell me and explain the difference between the two in the modelview matrix too please. ... Ok one more question. D3D seems to have two "modelview" matrices. The world and the view matrix. This is kind of weird to me. Could someone explain or link me to a site that explains how they fit together? In OpenGL there was only one matrix that described the translation/rotation of things. Well, I asked more questions than I had originally intended to. When I started thinking about the matrices I realized there were several questions I had about them. Heh. Well as I said above, a link to a site would also be good, since I doubt you want to try to explain all that to me =). Thanks in advance.
Advertisement
Use GetLevelDesc() with the level set to 0. This retrieves the description of the top-level surface of the texture (i.e. the normal size; sub-levels contain mip-mapped smaller sized versions of the texture if it is enabled). The description holds the dimensions.

Regarding the projection matrix be sure to check out the SDK documentation -- it has lots of explanations about all basic things you will encounter. Or use google of course.

Greetz,

Illco
Just starting out myself, I will explain what I know so far (also to make sure what I know :)

On most questions I would highly recommend thumbing through the MSDN direct X library online. I find myself constantly referencing it while I’m coding.

MSDN Library My most used Bookmark :)

Multiple Questions

1. Getting loaded texture dimensions
2. Loading like OpenGL
3.Ortho Projection Matrix
4. Right handed/ Left Handed Coordinates
5. View Matrix -vs- World Matrix

1. I see two ways of doing this..
A.)D3DXGetImageInfoFromFile
B.)D3DXGetImageInfoFromResource
These will load a D3DXIMAGE_INFO Structure with the image info like width, height, color depth... stuff like that

2. Loading like OpenGL... can't help you there, never used OpenGL

3. Ortho Projection Matrix ... [google]... and MSDN
A.)D3DXMatrixOrthoLH
B.)D3DXMatrixOrthoRH
C.)D3DXMatrixOrthoOffCenterLH
D.)D3DXMatrixOrthoOffCenterRH

4. Right handed versus Left Handed I'm not sure on this one :(

5. View Matrix -vs- World Matrix
A.)The world matrix is what you load your individual transform matrices into to move stuff around in the world.
B.)View Matrix controls the Camera Position and angle (you are not always at 0,0,0 looking at -Z.

Hope these help... let me know if there is anything else I can confuse you on :)

[edit]hehe took too long to compose sutff :)[/edit]
Quando Omni Flunkus MoritatiWhen All Else Fails, Play Dead!
Ebola0001:
4. Right handed versus Left Handed I'm not sure on this one :(


Here it is...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/Coordinate_Systems.asp

HTH
Illco: Ahah! So there is a function for getting width and height in the LPDIRECT3DTEXTURE9 object (among other info apparently). Thanks =).

Ebola0001: Wow. I can't believe I missed those ortho functions. I checked the DirectX documentation and was typing in things in the index section trying to guess the name of an ortho function but never found it. Thanks =).

EDIT: Ajit: Thanks for site link.
Quote:Also, is there any way to create a texture in a similar was as OpenGL? Like by giving it an array of bytes I load in with my own code?



Use LPD3DDEV9->CreateTexture for create a empty texture surface with the dimension and properties you need, then use LPDIRECT3DTEXTURE9->LockRect for lock and get a pointer to the texture surface and then fill it with the texture data loaded from your own, then use LPDIRECT3DTEXTURE9->UnLockRect for unlock the texture surface.

This topic is closed to new replies.

Advertisement