Creating Traffic lights (.x)

Started by
6 comments, last by Buckeye 8 years, 12 months ago

I am loading a traffic lights model with the.x functions the problem is i want 3 texture states for the lights etc, red, amba , green , how would i load 3 different textures if the model loading function loads 1 texture?

for(DWORD i = 0; i < numMaterials; i++) // for each material...
{
material = tempMaterials.MatD3D; // get the material info
material.Ambient = material.Diffuse; // make ambient the same as diffuse
// if there is a texture to load, load it
if(FAILED(D3DXCreateTextureFromFileA(d3ddev,
tempMaterials.pTextureFilename,
&texture)))
texture = NULL; // if there is no texture, set the texture to NULL
}

could i not use D3DXCreateTextureFromFileA 3 times on the different texture states and apply the texture this way?

because in code i need to set device->SetTexture(&red); , device->SetTexture(&amba); device->SetTexture(&green);

http://i.imgur.com/hGL4nHH.png?1

thanks if you can help

:)
Advertisement

Hi.

A trafic light sounds like a system made up of other parts and needs proccessing.

So maybe the traffic light needs to be the post and the outer shape and the lights are models of there own rendered only when the light state is green, amber or red.

or it can be all modeled in the one .X file, but you need to name the lights frame so you can not render the none active lights, this keeps it all in the one .X file 1 image(I do it this way).

would that work with as an animated x tho?, how would you animate the lights exactly?

:)
You could make one mesh for the trafic light pole/ object with it's textures, and then create a point light. The point light can be set at different position and color to control red, amber and green

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

You may also want to consider using all three colors all the time. I.e., one can normally see the color of the non-lit lights. Then increase the brightness of the "lit" light either by using a brighter texture, or adding (and saturating) a white color to the output in the pixel shader based on a flag of some sort.

EDIT: Any reason to use textures? Why not just set the rendering color for each "light lens" portion of the mesh?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

You could use 2 different models for each light: 1 off and 1 on. Then just move one of the models forward/backwards to change the traffic lights state?

Buckeyes suggestion is also a good solution.

You may also want to consider using all three colors all the time. I.e., one can normally see the color of the non-lit lights. Then increase the brightness of the "lit" light either by using a brighter texture, or adding (and saturating) a white color to the output in the pixel shader based on a flag of some sort.

EDIT: Any reason to use textures? Why not just set the rendering color for each "light lens" portion of the mesh?

sorry Buckeye can you elaborate on that idea

:)

First - normally one can see the color of the red/yellow/green lenses in a traffic light. I initially suggested you render all 3 lights with a dim color, just to make it look more like a "common" traffic light.

I'm assumed you could render each individual light separately. Now that I think about, rendering the "on" or "lit" light a second time to brighten the color will likely have depth issues. Sorry about that.

Another approach would be to set the tex coords for the 3 lights to appropriate separate areas in a single texture. Then you can have 3 textures. The 3 textures would be "RedOn," "YellowOn," and "GreenOn." Just select the texture to render with based on the state of the lights. The pix below is just a quick Paint job, so you'd have to enhance the color differences. Hopefully it gives you the idea.

[attachment=27272:traffic_lights.png]

EDIT: You'd actually only need a couple pixels per light in each texture, as the color will be "stretched" across the entire light portion of the mesh.

[attachment=27273:traffic_lights2.png]

etc.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement