D3DIM Lightning Question

Started by
6 comments, last by Sieggy 23 years, 11 months ago
If anyone could help with this one it would be greatly appreciated! Its probably something simple that I forgot, still being on the new side to IM and thanks ahead of time. I'm trying to manually light vertices using D3DTLVERTEX. I've been using an assignment such as below: vertex.color = D3DRGB (0.5f, 0.5f, 0.5f); However, despite numerous variations (including dumping in random numbers inside the rendering loop) the values seem to have absolutely zero effect on the textured polys being drawn. I'm using 7.0, btw. Thanks for help! Sieggy Edited by - Sieggy on 4/30/00 4:16:58 PM Edited by - Sieggy on 4/30/00 4:17:30 PM
Advertisement
Im not using DX7IM any more, Im now in OpenGl, but Do you have the SetRenderState(), that turn lighting to TRUE. Sorry if you already have.
Since you wan''t to manually light the vertices, you must disable Direct3D''s lighting engine. You do this by calling pD3DDev->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE); Note that lighting is on by default making all your rendering black, unless you have enabled any lightsources.

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

quote:Original post by Esap1

Im not using DX7IM any more, Im now in OpenGl, but Do you have the SetRenderState(), that turn lighting to TRUE. Sorry if you already have.


WTF? WHY? Let''s have a moment of silence for our former D3D member....?
Well, nes8bit, its true. I just kept looking at that simple OpenGL code, and how short and clean it looked. I just wanted to stop worrying about the API and more on the game, so, I havent converted totally yet, theres still hope for me to change back, But Im just experimenting right now, but OpenGL doesnt look soo back after all.
Well, no luck with the change suggested. I''ve dumped the crucial code in this lighting test and if someone could look and see where I screwed up it would be a big help. Bear in mind this is a simple test and code is actually from more than one function. It renders the polys and textures fine. Last, I''ve been testing this in software mode on my laptop, however I did not think that that would be an issue in this problem. Any thoughts would be a big help:

//**************d3d init*************************************

//inits
HRESULT r;

//init d3dx
if (FAILED(r = D3DXInitialize())) {
HandleError ("CD3DIntf::Init3D, D3DX failed to init",
r, true);
return false;
}

//create the d3dx context
r = D3DXCreateContext (D3DX_DEFAULT, //device index value
0, //def to windowed mode
GetSafeHwnd(), //main wnd handle
D3DX_DEFAULT, //def width to curr sz
D3DX_DEFAULT, //def height to curr sz
&m_pd3dx); //intf ptr
if ( FAILED (r) ) {
HandleError ("CD3DIntf::Init3D, D3DX could not create context",
r, true);
return false;
}

//get d3d device
m_pd3dev = m_pd3dx->GetD3DDevice ();

if (m_pd3dev == NULL) {
//device could not be created
HandleError (" C3DIntf::Init3d(), device creation returned null.", true);
return false;
}

m_pddraw = m_pd3dx->GetDD ();

if (m_pddraw == NULL) {
//direct draw
HandleError (" C3DIntf::Init3d(), direct draw request returned null.", true);
return false;
}

//get d3d device
m_pd3d = m_pd3dx->GetD3D ();

if (m_pd3d == NULL) {
//direct3d
HandleError (" C3DIntf::Init3D(), could not get 3d device", true);
return false;
}

//determine level of acceleration
if (FAILED (m_pd3dev->GetInfo(0,&m_deviceinfo, sizeof (D3DDEVICEINFO)))) {
HandleError (" C3DIntf::Init3D(), could get retrieve acceleration info", true);
return false;
}

(m_deviceinfo.bHardware > 0) ? m_hardware = true: m_hardware = false;

if (!m_hardware) {
HandleError (" C3DIntf::Init3D(), no hardware device could be found, using software");
}

//set initial render states

//dithering
r = m_pd3dev->SetRenderState( D3DRENDERSTATE_DITHERENABLE, TRUE);
if (FAILED (r)) {
HandleError (" C3DIntf::Init3d(), dither state could not be set.", true);
return false;
}

//set the background color
r = m_pd3dx->SetClearColor (D3DRGBA (0.0f,0.0f,0.0f,0));
if (FAILED (r)) {
HandleError (" C3DIntf::Init3d(), could not set bkgrnd color", true);
return false;
}

//clear buffers
r = m_pd3dx->Clear (D3DCLEAR_TARGET / D3DCLEAR_ZBUFFER);
if (FAILED (r)) {
HandleError (" C3DIntf::Init3d(), could not clear target", true);
return false;
}

//turn off d3d lighting
m_pd3dev->SetRenderState( D3DRENDERSTATE_LIGHTING, FALSE );

//return
return false;

//****************************init texturing***********************************
//init
HRESULT hr;

//attempt to use local directory
D3DTextr_SetTexturePath ("");

//load the desired texture
hr = D3DTextr_CreateTextureFromFile ("grass.bmp");
TRACE ("%d\n", hr);
if (FAILED (hr)) {
HandleError (" InitTexturing(), could not load file.", hr, true);
return false;
}

//setup textures for the device
if (FAILED (hr = D3DTextr_RestoreAllTextures( m_pd3dev ))) {
HandleError (" InitTexturing(), could not setup textures for device.",hr,true);
return false;
}

//bilinear texturing mode
hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTFN_LINEAR );
hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTFG_LINEAR );
hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
hr = m_pd3dev->SetRenderState( D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE );

if (FAILED (hr)) {
HandleError (" InitTexturing(), texture stage init failed", hr, true);
}

//done!
return true;

//***************vertex init***************************************
D3DVECTOR vFar = D3DVECTOR (0.0f, 0.0f, 0.5f);
m_points[0] = D3DTLVERTEX (vFar, 1.0f, 0xffffffff, 0, 0.0f, 1.0f);
m_points[1] = D3DTLVERTEX (vFar, 1.0f, 0xffffffff, 0, 0.0f, 0.0f);
m_points[2] = D3DTLVERTEX (vFar, 1.0f, 0xffffffff, 0, 1.0f, 1.0f);
m_points[3] = D3DTLVERTEX (vFar, 1.0f, 0xffffffff, 0, 1.0f, 0.0f);

D3DVIEWPORT7 viewport;
m_pd3dev->GetViewport(&viewport);
float vh = (float)viewport.dwHeight;
float vw = (float)viewport.dwWidth;
m_points[0].sy = vh;
m_points[2].sy = vh;
m_points[2].sx = vw;
m_points[3].sx = vw;

//******************rendering*********************************
//test
//turn off d3d lighting
m_pd3dev->SetRenderState( D3DRENDERSTATE_LIGHTING, FALSE );

//instruct d3d we are ready
HRESULT r;
r = m_pd3dev->BeginScene();

if (SUCCEEDED (r)) {
//progress with the frame
//clear the target
m_pd3dx->Clear (D3DCLEAR_TARGET / D3DCLEAR_ZBUFFER);

//init the texture
r = m_pd3dev->SetTexture( 0, D3DTextr_GetSurface("grass.bmp") );
if (FAILED (r)) {
HandleError ("Draw(), could not set texture", r, true);
}

m_points[0].color = D3DRGB(rand()/5000,rand()/5000,rand()/5000);
m_points[1].color = D3DRGB(rand()/5000,rand()/5000,rand()/5000);
m_points[2].color = D3DRGB(rand()/5000,rand()/5000,rand()/5000);
m_points[3].color = D3DRGB(rand()/5000,rand()/5000,rand()/5000);

m_pd3dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,
D3DFVF_TLVERTEX,
m_points,
4,
NULL);


//close it up
m_pd3dev->EndScene();
}
else {
HandleError (" Draw(), could not begin scene", r, true);
return false;
}

ShowFramesPerSecond();

//update the frame
r = m_pd3dx->UpdateFrame (0);

Thanks Again,

Sieggy
Found your problem

You tell Direct3D to use the color from the texture only. That way it doesn''t matter what color the vertices have. To
enable vertex colors do this:

hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

I think that should do it.

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks WitchLord, that solved it. Guess I need to do another review of the texture args. Thanks for the help!

Sieggy

This topic is closed to new replies.

Advertisement