int main(int argc, char **argv) { glutInit(&argc, argv); quadObj = gluNewQuadric(); /* this will be used in drawScene */ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("Two-sided lighting"); ax = 10.0; ay = -10.0; az = 0.0; initLightAndMaterial(); glutDisplayFunc(drawScene); glutReshapeFunc(resize); glutCreateMenu(menu); glutAddMenuEntry("Motion", 3); glutAddMenuEntry("Two-sided lighting", 1); glutAddMenuEntry("One-sided lighting", 2); glutAttachMenu(GLUT_RIGHT_BUTTON); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
BOOL initD3d(HWND hWnd, BOOL fullscreenMode) { D3DPRESENT_PARAMETERS d3d9pp; d3d9 = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface ZeroMemory(&d3d9pp, sizeof(D3DPRESENT_PARAMETERS)); if (fullscreenMode) d3d9pp.Windowed = FALSE; else d3d9pp.Windowed = TRUE; // use 64bit display mode if supported by Gcard, else use 32bit or 16bit if (SUCCEEDED(d3d9->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_A16B16G16R16, D3DFMT_A16B16G16R16, FALSE))) { d3d9pp.BackBufferFormat = D3DFMT_A16B16G16R16; MessageBox(hWnd, "Using 64bit color mode (D3DFMT_A16B16G16R16)", "Information", MB_ICONINFORMATION); } else if (SUCCEEDED(d3d9->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, FALSE))) d3d9pp.BackBufferFormat = D3DFMT_X8R8G8B8; else if (SUCCEEDED(d3d9->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_R5G6B5, D3DFMT_R5G6B5, FALSE))) d3d9pp.BackBufferFormat = D3DFMT_R5G6B5; else if (SUCCEEDED(d3d9->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X1R5G5B5, D3DFMT_X1R5G5B5, FALSE))) d3d9pp.BackBufferFormat = D3DFMT_X1R5G5B5; d3d9pp.BackBufferHeight = SCREEN_HEIGHT; d3d9pp.BackBufferWidth = SCREEN_WIDTH; d3d9pp.hDeviceWindow = hWnd; d3d9pp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3d9pp.EnableAutoDepthStencil = TRUE; // automatically run the z-buffer for us d3d9pp.AutoDepthStencilFormat = D3DFMT_D16; // 16-bit pixel format for the z-buffer d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3d9pp, &d3d9dev); if (!initD3dStuff(hWnd)) return FALSE; // init the 3D objects initLightAndMaterial(); // init the lights and objects materials d3d9dev->SetRenderState(D3DRS_LIGHTING, D3DZB_TRUE); // turn off the 3D lighting d3d9dev->SetRenderState(D3DRS_ZENABLE, TRUE); // turn on the z-buffer d3d9dev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50)); // ambient light d3d9dev->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE); // handle normals in scaling // cant get transperacy to work d3d9dev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); d3d9dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); d3d9dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); d3d9dev->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); d3d9dev->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS , TRUE); // antialising //d3d9dev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC); // antistrophic when scaled up //d3d9dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC); // antistrophic when scaled down return TRUE; }