Here's an example from the HL2 code of making a material from code:

KeyValues *pVMTKeyValues = new KeyValues( "UnlitGeneric" );
pVMTKeyValues->SetInt( "$flat", 1 );
pVMTKeyValues->SetFloat( "$vertexcolor", 0.05f );
IMaterial *pDrawFlatMaterial = materials->CreateMaterial( "___flat.vmt", 
pVMTKeyValues );

Gary

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Ignacio Martín
> Sent: Wednesday, May 11, 2005 7:23 PM
> To: hlcoders@list.valvesoftware.com
> Subject: [hlcoders] CreateMaterial, KeyValues...
>
> --
> [ Picked text/plain from multipart/alternative ] Hi again. I
> have already succesfully finished the night vision using
> shaders. I have created a dummy vmt material (well, it is not
> actually dummy, as it has a variable used by the shader), but
> I do not want to give people the chance to cheat with it, so
> I think that the best choice is to create the material inside
> the code, thanks to the IMaterial *CreateMaterial( const char
> *pMaterialName, KeyValues *pVMTKeyValues ) function. I would
> bind it to my shader using void SetShader( const char
> *pShaderName ). The question comes now. How does KeyValues
> work? I mean, if I have this:
>
> "My_shader"
> {
>
> "$var1" "0.5"
> "$var2" "1.5"
> "$var3" "2"
> "$var4" "1.7"
> "$var5" "1"
> }
>
> How can I create KeyValues to create that material? It may
> sound silly, but what is the relationship between "Name" and
> "firstKey" in the constructors?
> (are they parent-child?).
> In my example, if I set Name as "My_shader", would be it
> enough for CreateMaterial to know which shader to use?
> Otherwise I would have to call SetShader.
> If I want to get a value, do I have to find "firstKey"? As I
> can guess, when I call functions like SetFloat or SetString,
> new keys are created as sub-keys, and stored at the end of
> that sub-key list. Isn´t it like that?
> As you see, I´m quite lost with KeyValues, hehe.
>
> Finally, the last question (at last!): does IMaterial
> *CreateMaterial( const char *pMaterialName, KeyValues
> *pVMTKeyValues ) "store" a reference to this material in
> materialsystem so that I can use materials->FindMaterial
> anywhere in my code?
>
> Thank you for your time
>
> Regards,
>
> Ignacio Martin
>
> FIRE WAR MOD - Spanish HL2 Modification
> www.firewar.net <http://www.firewar.net>
> --
>
> _______________________________________________
> To unsubscribe, edit your list preferences, or view the list
> archives, please visit:
> http://list.valvesoftware.com/mailman/listinfo/hlcoders
>
>

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to