Jump to content
  • Advertisement
Sign in to follow this  
silvia_steven_2000

(1) DirectX9 Texture (2) Dimmed TGA image

This topic is 4875 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

Hi All I have two questions: (1) I create an empty texture like this: //Create an empty texture using the provided image HRESULT hr = m_d3dDev9->CreateTexture ( 256, 256, 0, 0, D3DFMT_R8G8B8, D3DPOOL_MANAGED, &m_d3dTex9, NULL ); it fails however if I use D3DFMT_A8R8G8B8 it succeeds why is that ? (2) I wrote a simple tga loader and used it to texture map a cube. the image loaded fine and the cube was textured fine but there was a little problem. the image is dimmed, it is darker than the original image but it is not distorted however. when I use D3DXCreateTextureFromFile it appears normal not dimmed. is there any hints to resolve that problem ? I do not know how to post an image to the formum to show u the two pictures. the image I am loading is 24 bit true color and I load it into an A8R8G8B8 texture putting the alpha channel to some temp value. I am afraid this this what causing the problem. any help is really appreciated , thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
As for (1): not all texture formats are supported by just any device. In fact, the documentation of DirectX says that you have to explicitly test if a format is available (via the device caps or one of the check-functions). You cannot assume that your fixed format is available.

For (2): your texture now appears in a dynamic 3D scene. It is influenced by lighting parameters. If you have a light in your scene, it will brighten or darken the texture when it faces away or faces towards the camera, respectively. If you have no lights present, there is still ambient lighting. This is an 'all-over' lighting which lights or darkens all parts of the scene evenly. Only when the ambient is set to maximum white or when the a light lights the surface directly will the texture appear as bright as it is in itself (full bright). Also, the material settings affect this.

To solve this, thus check:
- the value of ambient lighting
- the presence of a light in the scene and its color/direction
- the normals on the mesh
- the material currently set

Also note that usually the beauty of a scene comes from lighting; we usually do not want textures to appear as bright as created.

Greetz,

Illco

Share this post


Link to post
Share on other sites
as for (1) I will check for that
for (2) : lighting is disabled. it is bright whith D3DX function and dimmed using my loading routince. all settings are kept the same whether I use the D3Dx function or my routine and that is what confusing me. matrial properites used are the same also.

Share this post


Link to post
Share on other sites
With no lights and no ambient the scene will be black. So either one shall be enabled.

Share this post


Link to post
Share on other sites
Quote:
Original post by silvia_steven_2000
as for (1) I will check for that
for (2) : lighting is disabled. it is bright whith D3DX function and dimmed using my loading routince. all settings are kept the same whether I use the D3Dx function or my routine and that is what confusing me. matrial properites used are the same also.


Is alpha blending enabled? If so, are you filling in the alpha values? Is it possible that d3dx is choosing an xRGB format whereas you are selecting ARGB?

Paul

Share this post


Link to post
Share on other sites
ambient light is white
alpha blending is disabled
I tried x8r8g8b8 but still the colot is dimmed.
any other hints, thanks so much.

this gives me the real picture:

IDirect3DTexture9* d3dtex;
D3DXCreateTextureFromFile(Device, "image.tga", &d3dtex);
Device->SetTexture(0, d3dtex);

versus

this gives me the dimmed pictue:

Image* img = new ImageTGA("image.tga");
img->loadImage();
Texture* tx = rs->createTexture(img);
Device->SetTexture(0, ((TextureDX9*)tx)->getTextureDX9());

despite the fact that I have the same settings, so what does d3dx do ?
or if I am loading the image the wrong way but still this would corrupt the
image if that is true since as I said the image is not distorted and it seems
there is something to do wiht lighitng or blending however similar settings
are used in d3dx and mine.

Share this post


Link to post
Share on other sites
Quote:
Original post by silvia_steven_2000
ambient light is white
alpha blending is disabled
I tried x8r8g8b8 but still the colot is dimmed.
any other hints, thanks so much.

this gives me the real picture:

IDirect3DTexture9* d3dtex;
D3DXCreateTextureFromFile(Device, "image.tga", &d3dtex);
Device->SetTexture(0, d3dtex);

versus

this gives me the dimmed pictue:

Image* img = new ImageTGA("image.tga");
img->loadImage();
Texture* tx = rs->createTexture(img);
Device->SetTexture(0, ((TextureDX9*)tx)->getTextureDX9());

despite the fact that I have the same settings, so what does d3dx do ?
or if I am loading the image the wrong way but still this would corrupt the
image if that is true since as I said the image is not distorted and it seems
there is something to do wiht lighitng or blending however similar settings
are used in d3dx and mine.


What format is the tga? What format does d3dx choose (GetLevelDesc and look at the Format of the D3DSURFACE_DESC)? How are you converting from the tga pixels to the texture pixels in loadImage() and/or createTexture()?

Paul

Share this post


Link to post
Share on other sites
I checked : the d3dx uses x8r8g8b8
my tga is 24 bit (bgr) then I convert it to x8r8g8b8.
then I copy the pixles to the texture as follows:

D3DLOCKED_RECT rect;
HRESULT hr = m_d3dTex9->LockRect(0, &rect, 0, 0);

memcpy(rect.pBits, pointer_to_image_in_x8r8g8b8, img.width*img.height*4);

Share this post


Link to post
Share on other sites
Quote:
Original post by silvia_steven_2000
I checked : the d3dx uses x8r8g8b8
my tga is 24 bit (bgr) then I convert it to x8r8g8b8.
then I copy the pixles to the texture as follows:

D3DLOCKED_RECT rect;
HRESULT hr = m_d3dTex9->LockRect(0, &rect, 0, 0);

memcpy(rect.pBits, pointer_to_image_in_x8r8g8b8, img.width*img.height*4);



hmm. If your tga is 24-bit and you're texture is 32-bit (xrgb), that memcpy isn't going to work.

Paul

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!