directx-how to use no texture

This is a discussion on directx-how to use no texture within the Game Programming forums, part of the General Programming Boards category; This (should) be fairly easy. I've been using meshes loaded from .x files and also loading materials and textures from ...

  1. #1
    Registered User Vick jr's Avatar
    Join Date
    May 2009
    Location
    Galifray
    Posts
    27

    directx-how to use no texture

    This (should) be fairly easy.

    I've been using meshes loaded from .x files and also loading materials and textures from them. Now i want to use a custom made material without a texture (just a solid diffuse color basically), like they do here.

    I can set the material correctly. I've tried resetting the texture to a default white with

    Code:
    d3ddev->SetTexture(0,NULL);
    but all the objects then appear pure white. the diffuse and ambient colors of the amterial doesn't seem to have any effect. How to i make the colors of the object be the color of the material diffuse?

    Thank you!

    Also, I know the function D3DXMatrixLookAtLH can make a view translation/rotation matrix based on a position vector, look-at vector, and up direction. Is there any function that can make a translation/rotation matrix for transforming an object (not view matrix) based on its position and vectors representing its rotated local axis?
    (I have a position vector and a "looking at" vector (corresponding to the z axis) which i want to use to transform objects. The up direction would remain {0,1,0}.
    Last edited by Vick jr; 06-09-2010 at 10:55 AM.
    Frogblast the ventcore!

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    1. SetTexture(0,0) sets texture sampler 0 to use no texture. Make sure you have your mesh material set, make sure you have your light set and turned on and make sure you have the diffuse material source set correctly.

    2. You would need an orientation class or a frame class to orient an object correctly. The frame class does essentially what the camera does for the view except the final matrix is the transpose of what the camera would compute.

  3. #3
    Registered User Vick jr's Avatar
    Join Date
    May 2009
    Location
    Galifray
    Posts
    27
    Quote Originally Posted by Bubba View Post
    1. SetTexture(0,0) sets texture sampler 0 to use no texture. Make sure you have your mesh material set, make sure you have your light set and turned on and make sure you have the diffuse material source set correctly.

    2. You would need an orientation class or a frame class to orient an object correctly. The frame class does essentially what the camera does for the view except the final matrix is the transpose of what the camera would compute.
    I initialize the material to be red with this code:

    Code:
    D3DMATERIAL9 material;
    ZeroMemory(&material, sizeof(D3DMATERIAL9));    
    material.Diffuse = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f);    
    material.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);   
    material.Specular= D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
    then use it with no texture with this code (d3ddev is the directx device):
    Code:
    d3ddev->SetMaterial(&material);
    d3ddev->SetTexture(0,NULL);
    There is no texture, but I can't get the color to to constant. It is colored by my lights (if I have lighting enabled when I'm rendering the objects), but is always white otherwise. I want to it have a constant color and not be affected by lights.

    One more thing: how to I clear a std::basic_stringstream<TCHAR> so that it will have no characters in it? I've tried the clear() function and sync() but nothing works. I'm using the stream to output information like camera position and rotation, so i need to clear it every frame to fill it with new data.

    Thanks!
    Frogblast the ventcore!

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    There is no texture, but I can't get the color to to constant. It is colored by my lights (if I have lighting enabled when I'm rendering the objects), but is always white otherwise. I want to it have a constant color and not be affected by lights.
    Not possible using fixed function pipeline. Colored lights always affect the color of the object. Use a pure white light if you only want the object to display it's material color. Keep in mind the specular color for the material should be white unless you want it to be something else.

  5. #5
    Registered User Vick jr's Avatar
    Join Date
    May 2009
    Location
    Galifray
    Posts
    27
    Quote Originally Posted by Bubba View Post
    Not possible using fixed function pipeline. Colored lights always affect the color of the object. Use a pure white light if you only want the object to display it's material color. Keep in mind the specular color for the material should be white unless you want it to be something else.
    I can just turn off the lights while I'm rendering objects that i don't want affected by them, or turn off lighting in general:

    Code:
    d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);
    Are saying that with no texture and no dynamic lights affecting the object, the color will always be white, and the material diffuse has no effect?

    If this is the case, could I change the color by changing the global ambient light while I'm rendering the objects?

    Code:
    d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(255,0,0));//make all subsequient objects rendered with red ambien light
    
    ...code to render objects...
    
    d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(150,150,150));//change back to white ambient light
    Would the materials "Emissive" color be any use?

    Thanks again!
    Last edited by Vick jr; 06-15-2010 at 02:01 PM.
    Frogblast the ventcore!

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    If you turn off lights for objects with normals then the objects will be black. Everything in a 3D scene is lit by lights and any attempt to thwart this design will result in problems. 2D doesn't operate on lights but 3D does. Any effects you are trying to achieve in 3D should not change this behavior.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. d3d9 c++ texture wrapper... again...
    By yaya in forum Game Programming
    Replies: 0
    Last Post: 04-01-2009, 01:08 PM
  2. D3d Texture Wrapper == ARRRGGGGHHH
    By yaya in forum Game Programming
    Replies: 1
    Last Post: 03-25-2009, 06:41 PM
  3. Replies: 4
    Last Post: 02-27-2008, 02:10 PM
  4. OpenGL - look trough surface -nehe lesson
    By GanglyLamb in forum Game Programming
    Replies: 8
    Last Post: 08-24-2006, 11:06 PM
  5. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21