Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Specular component

Posted on 2001-06-09
4
Medium Priority
?
310 Views
Last Modified: 2013-12-26
I am trying to implement some specular highlights on a circle in dx8 but the code does not work. I am writing the important part of code.

//global variables
LPDIRECT3D8             g_pD3D       = NULL; LPDIRECT3DDEVICE8       g_pd3dDevice = NULL; LPDIRECT3DVERTEXBUFFER8 g_pVB        = NULL;

struct CUSTOMVERTEX
{
    D3DXVECTOR3 position;
    D3DXVECTOR3 normal;  
};

#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL)

HRESULT InitD3D( HWND hWnd )
{
   
    if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
        return E_FAIL;

 
    D3DDISPLAYMODE d3ddm;
    if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
        return E_FAIL;

    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = d3ddm.Format;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

 
    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_REF , hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &g_pd3dDevice ) ) )
    {
        return E_FAIL;
    }
 
    // Turn off culling
    g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

    // Turn on the zbuffer
    g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );

    return S_OK;
}

HRESULT InitGeometry()
{
    // Create the vertex buffer.
    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 50*sizeof(CUSTOMVERTEX),
                                                  0, D3DFVF_CUSTOMVERTEX,
                                                  D3DPOOL_DEFAULT, &g_pVB ) ) )
    {
        return E_FAIL;
    }

    CUSTOMVERTEX* pVertices;
    if( FAILED( g_pVB->Lock( 0, 0, (BYTE**)&pVertices, 0 ) ) )
        return E_FAIL;

pVertices[0].position = D3DXVECTOR3( 0.0f,3.0f, 0.0f );
pVertices[0].normal   = D3DXVECTOR3( 0.0f, 3.0f, 0.0f );
 
  for( DWORD i=1; i<49; i++ )
    {
        FLOAT theta = (2*D3DX_PI* i)/(49-1);

    pVertices[i].position = D3DXVECTOR3( 3*sinf(theta), 3*cosf(theta),0.0f );

        pVertices[i+0].normal   = D3DXVECTOR3( 3*sinf(theta), 3*cosf(theta) , 0.0f);
        }
    g_pVB->Unlock();

    return S_OK;
}

VOID SetupMatrices()
{
    D3DXMATRIX matWorld;
    D3DXMatrixIdentity( &matWorld );
   
   D3DXMatrixTranslation(&matWorld,1.0,0.0f,0.0f);
    g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

   
    D3DXMATRIX matView;
D3DXMatrixLookAtLH( &matView, &D3DXVECTOR3( 0.0f, 0.0f,-50.0f ),
                                  &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
                                  &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );
    g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

    D3DXMATRIX matProj;
    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
    g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}

VOID SetupMaterial()
{
    D3DMATERIAL8 mtrl;
    ZeroMemory( &mtrl, sizeof(D3DMATERIAL8) );
      
    mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f;
    mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f;
    mtrl.Diffuse.b = mtrl.Ambient.b = 0.0f;
    mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f;

    mtrl.Specular.r=0.0f;
      mtrl.Specular.g=1.0f;
      mtrl.Specular.b=0.0f;
      mtrl.Specular.a=1.0f;

      mtrl.Power=50.0f;

    g_pd3dDevice->SetMaterial( &mtrl );

        // Finally, turn on some ambient light.
      g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 );
   
}

VOID Render()
{
    // Clear the backbuffer and the zbuffer
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
                         D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

    // Begin the scene
    g_pd3dDevice->BeginScene();

    // Setup materials
    SetupMaterial();

    // Setup the world, view, and projection matrices
    SetupMatrices();

    // Render the vertex buffer contents
    g_pd3dDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );
    g_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
    g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 47 );

    // End the scene
    g_pd3dDevice->EndScene();

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}


A circle is drawn but there are no specular highlifgts. Also if I want to set a desired shade of red color how can I set that if I know its RGB value.And what color format is best for games 8,16 or 24 bit.  
0
Comment
Question by:Sana060101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 2

Expert Comment

by:cybermike3d
ID: 6179631
Welcome into the lions den. There are a very narrow set of parameters within which specularity will work. If you a scale setting other than 1, specularity will not work.

16 Bit DEFINATELY

I have made a program ... unfortunately it is in VB, but it allows you to do the testing. Maybe u should do the same for C and then maybe you'll get somewhere.

Take a look at http://www.cybermike3d.co.za/1jet1.jpg 

There are the setting guidelines to get specular lighting and material fx working

Does this help ?
0
 
LVL 2

Accepted Solution

by:
cybermike3d earned 160 total points
ID: 6179640
Lighting is wrong ... Specularity only seems to work with directional ... And very badly with point, and not at all with Spot.
0
 

Author Comment

by:Sana060101
ID: 6216568
Will you explain why 16 bit?
0
 
LVL 2

Expert Comment

by:cybermike3d
ID: 6216683
On certain cards (riva) the program is slower and also does not render properly, than if u use 32 bit. If u r transfering image data, 32 bits is twice as much data.
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question