Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Lighting and Sprites

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 dsm1891   Members   


Posted 22 July 2014 - 08:10 AM



I currently have a 2d engine, and I wanted to add lighting to it. I am not well versed in graphical programming (hence posting it in beginners). After following a few tutorials online I have managed to implement lights into my engine (kinda) that being I can draw a 2D plane (which I manually input the vertices)  with the lighting effects.





However, when ever I draw a sprite (see code below). The lighting effect is not present, it is the original image. I think, although I am unsure, this may have to do something with LPD3DXSPRITE (what I am using as the actual sprite) I suspect this does not have any vertices hence no normal that are required for the light effect to be shown. Is this correct?


If it is correct how would I go about correcting this? Would I have to create vertices for each sprite image and add a texture to it? If this is the case I would appreciate some guidance on how to do this. If it is not correct, what is my problem, I have been scratching my head for a while now :/ 



Sprite drawing:

void Graphics::drawSpriteWithOffset(const SpriteData &spriteData, 
int x, int y, COLOR_ARGB colour)


	D3DXMATRIX matrix;
	D3DXMatrixTransformation2D(&matrix, NULL, 0.0f, &scaling, &spriteCenter, (float) (spriteData.angle), &translate);


Creating the Light:

void Graphics::init_light(void)
    D3DLIGHT9 light;    // create the light struct
    D3DMATERIAL9 material;    // create the material struct

    ZeroMemory(&light, sizeof(light));    // clear out the light struct for use
    light.Type = D3DLIGHT_DIRECTIONAL;    // make the light type 'directional light'
    light.Diffuse = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);    // set the light's color
    light.Direction = D3DXVECTOR3(-1.0f, 0.0f, 1.0f);

    device3d->SetLight(0, &light);    // send the light struct properties to light #0
    device3d->LightEnable(0, TRUE);    // turn on light #0

    ZeroMemory(&material, sizeof(D3DMATERIAL9));    // clear out the struct for use
    material.Diffuse = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f);    // set diffuse color to white
    material.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set ambient color to white

    device3d->SetMaterial(&material);    // set the globably-used material to &material

Any help is appreciated, smile.png

Edited by dsm1891, 22 July 2014 - 08:12 AM.

Mobile Developer at PawPrint Games ltd.

(Not "mobile" as in I move around a lot, but as in phones, mobile phone developer)

(Although I am mobile. no, not as in a babies mobile, I move from place to place)

(Not "place" as in fish, but location.)

#2 cozzie   Members   


Posted 22 July 2014 - 12:27 PM

Drawing the sprite as a quad with 4 vertices, using the sprite image as a texture should work fine. Where you would technically be working in 3d, which basically all Z values 1. This actually creates nice opportunities for further development. Make sure you use a vertex format including normals. A directional light for example could have direction 1,0,0 meaning it would point straight towards sprites facing "the camera" (quads at Z is 1).

From your code I also see your using the fixed function pipeline, you might want to take a look at using shaders (starting with LPD3DXEFFECT as a start), this gives immensive possibilities on how in your case, your quad and eventually its textured pixels will be drawn on screen.

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

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.