D3DXCreateTexture(m_pDevice, width, height, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_pTextures[i]); D3DLOCKED_RECT d3dlr; m_pTextures[i]->LockRect(0, &d3dlr, NULL, 0); memcpy(d3dlr.pBits, pData, 4 * width * height); m_pTextures[i]->UnlockRect(0);
🔒 Locked
Odd-Sized Textures
Advertisement
Original Post
It appears that textures in D3D have to be sized by powers of 2. However, in OpenGL I am able to make non-power of 2 sized textures using gluBuild2DMipmaps. Is there a way to do this in D3D?
Currently this is how I am doing it, and it isn't working.
-dizzy
[edited by - yzzid on February 18, 2003 9:06:25 AM]
d3d can make arbitrary sizes too. i''m failing to see the problem here. it''s created ok right? no errors? if you go like this after you create the texture..
IDirect3DSurface8 *tex_surface=NULL;
D3DSURFACE_DESC surDesc;
// m_pTexture = texture you just created
m_pTexture->GetSurfaceLevel(0,&tex_surface);
tex_surface->GetDesc(&surDesc);
// and look at surDesc.Width and Height members.
// if they''re the height and width you specified
// then it must be something with your memcpy.
I tried and D3D is changing the sizes to powers of 2!
For example I have a texture that is 128 x 160 and when I get the description D3D gives back 128 x 256. So it is creating a texture by increasing the value to the next power of two greater than the given size.
Not sure of a way around this.
-dizzy
For example I have a texture that is 128 x 160 and when I get the description D3D gives back 128 x 256. So it is creating a texture by increasing the value to the next power of two greater than the given size.
Not sure of a way around this.
-dizzy
D3DXCreateTexture(m_pDevice, width, height, D3DX_FILTER_NONE, D3DX_FILTER_NONE, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_pTextures[i]);
D3DX_FILTER_NONE
[edit] [ code ] tags dont work for {i}?
.lick
[edited by - Pipo DeClown on February 18, 2003 10:30:47 AM]
[edited by - Pipo DeClown on February 18, 2003 10:31:55 AM]
Hi - D3D_FILTER_NONE will not prevent directx from resizing your textures to a size of power 2, but it will prevent direct3d from scaling the contents of your original image to fill the new, and presumably larger, texture surface. The original image will stay the same size in the new texture and the parts of the new texture it does not fill will be black.
You can then adjust your texture coordinates, etc... to reference only the part of the texture you need.
I''ll have to try the createtexture, loadtexturefromemory, filtertexture method - it looks interesting.
BM
You can then adjust your texture coordinates, etc... to reference only the part of the texture you need.
I''ll have to try the createtexture, loadtexturefromemory, filtertexture method - it looks interesting.
BM
I am sorry I should elaborate on my findings.
When calling D3DXLoadSurfaceFromMemory() you must use a filter parameter of D3DX_FILTER_LINEAR or the texture will be copied as is and all area that is expanded will be filled with black as bmoberly stated. Then you must call D3DXFilterTexture to get the other mip map levels filled. If you do not call D3DXFilterTexture your mipmaps will all be black.
Hope this helps someone.
-dizzy
When calling D3DXLoadSurfaceFromMemory() you must use a filter parameter of D3DX_FILTER_LINEAR or the texture will be copied as is and all area that is expanded will be filled with black as bmoberly stated. Then you must call D3DXFilterTexture to get the other mip map levels filled. If you do not call D3DXFilterTexture your mipmaps will all be black.
Hope this helps someone.
-dizzy
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement