Exemplo n.º 1
0
Arquivo: main.cpp Projeto: df3n5/iet
void initGL(const jfWindow& window)
{
	setupLighting();
	glShadeModel( GL_SMOOTH );
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClearDepth( 10.0f );
	glDepthFunc( GL_LEQUAL );
	glEnable( GL_DEPTH_TEST );
	glClearAccum(0.1, 0.1, 0.8, 0.0);

	glViewport(0, 0, window.getWidth(), window.getHeight());
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60.0f,(float)window.getWidth()/(float)window.getHeight(),0.1,600);


	// Enable color tracking
	GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };

	glEnable(GL_COLOR_MATERIAL);
	// Set material properties to follow glColor values
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	// All materials hereafter have full specular reflectivity
	// with a high shine
	glMaterialfv(GL_FRONT, GL_SPECULAR,specref);
	glMateriali(GL_FRONT,GL_SHININESS,128);

	glEnable(GL_NORMALIZE);

}
Exemplo n.º 2
0
void drawPlanet()
{   
	glUseProgram(planetShader);
	setupLighting(planetShader);
	vec3 Position = getCameraPosition();
	v = getViewMatrix();
		
	for(int i = 0; i < 11; i++)
	{	
		mat4 rotation = multiplymat4(rotateY(rotationSpeedArray[i]), rotateX(planetInstanceArray[i].axialTilt+45));
		mat4 translation = multiplymat4(translate(planetInstanceArray[i].radius*1000, 0.0, 0.0), rotation);
		mat4 b = translate(0.0, 0.0, -400.0);
		mat4 roty = rotateY(orbitSpeedArray[i]);
		mat4 rotxy = multiplymat4(b, roty);
		mat4 c = multiplymat4(rotxy, translation);
		m = multiplymat4(c, scale(planetInstanceArray[i].size*100));
		planetInstanceArray[i].planetLocation = m;
    	
		//mv = modelMatrices[i];
		initMVP(planetShader, m, v);
		glUniform3f(glGetUniformLocation(planetShader, "cameraPos"), Position.x, Position.y, Position.z);
    
    	glBindVertexArray (planetVAO);
    	bindTexture(GL_TEXTURE0, planetInstanceArray[i].texture);
    	bindTexture(GL_TEXTURE1, planetInstanceArray[i].normal);
    	glUniform1i(glGetUniformLocation(planetShader, "tex"), 0);
    	glUniform1i(glGetUniformLocation(planetShader, "normalTex"), 1);
    	glDrawArrays( GL_TRIANGLES, 0, planet.vertexNumber);
    	glBindVertexArray(0);
    }
}
Exemplo n.º 3
0
// restore re-activates the display device
//
bool Display::restore() {

    bool rc = false;

    if (d3dd) {
        HRESULT hr;
		hr = d3dd->TestCooperativeLevel();
		if (hr == D3DERR_DEVICENOTRESET)
			// reset the display device
			rc = d3dd->Reset(&d3dpp) == D3D_OK;
		else if (hr == S_OK)
			rc = true;
	}
	if (rc) {
		// reacquire sprite manager references to video memory
		if (scrManager) scrManager->OnResetDevice();
    }

	// complete the restoration
	if (rc) {
        setupProjection();
        setupLighting();
		setupBlending();
	}

    return rc;
}
Exemplo n.º 4
0
void main()
{
	dglWindowOpen("Light example", 900, 750, false);    // create a GL-enabled window of given pixel size

	setupLighting();
	setupTexture();

	glEnable(GL_DEPTH_TEST);
 
	// variables to control object rotation
	float	rotAngle = 0.0f;
	unsigned long long int prevTime = dglGetCurrentTime();

	while( !dglGetAsyncKeyState(DGLK_ESCAPE) )		// begin the main loop. Keep on running until user presses escape
	{
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(30, 900.0/750.0, 1.0, 100.0);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// clear screen black before drawing

		glRotatef(rotAngle, 0, 0.2, 0.2);
		glutSolidTeapot(1.5);
		
		dglSwapBuffers();	// frame is done and can be shown on the screen
		
		rotAngle += 0.02f * (dglGetCurrentTime() - prevTime);				// rotation speed 0.02 (degrees per millisecond)
		prevTime = dglGetCurrentTime();
	}

	dglWindowClose();
}
Exemplo n.º 5
0
void drawSun()
{   
	glUseProgram(sunShader);
	
	setupLighting(sunShader);
	
	//glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
	vec3 Position = getCameraPosition();
	
	v = getViewMatrix();
	
	mat4 a = translate(0.0, 0.0, -400.0); //333.0 Times
	mat4 rotation = rotateY(thetaY);
	mat4 b = multiplymat4(a, rotation);
	m = multiplymat4(b, scale(100.0));
	
	initMVP(sunShader, m, v);
	glUniform3f(glGetUniformLocation(sunShader, "cameraPos"), Position.x, Position.y, Position.z);
	glUniform1f(glGetUniformLocation(sunShader, "systemTime"), glfwGetTime());
    
    glBindVertexArray (planetVAO);
    bindTexture(GL_TEXTURE0, sunTexture);
    bindTexture(GL_TEXTURE1, sunNormal);
    glUniform1i(glGetUniformLocation(sunShader, "tex"), 0);
    glUniform1i(glGetUniformLocation(sunShader, "normalTex"), 1);
    
    glDrawArrays( GL_TRIANGLES, 0, planet.vertexNumber );
    glBindVertexArray(0);
    //glBindFramebuffer(GL_FRAMEBUFFER, 0);  
    
    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, colorBuffer);
    glUniform1f(glGetUniformLocation(sunShader, "exposure"), 1.0);
}
Exemplo n.º 6
0
void ArmGLWidget::initializeGL() {
    /* Initial OpenGL Setup */
    glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    setupLighting();
}
Exemplo n.º 7
0
void drawAtmosphere()
{
	glUseProgram(atmosphereShader);
	setupLighting(atmosphereShader);
	vec3 Position = getCameraPosition();
	v = getViewMatrix();
	
	for(int i = 0; i < 11; i++)
    {	
    	float scaleFactor = 1.025;
    	m = multiplymat4(planetInstanceArray[i].planetLocation, scale(scaleFactor));
    	
    	float fOuter = planetInstanceArray[i].size*100*scaleFactor;
		float fInner = (planetInstanceArray[i].size*100);
		
		//float fOuter = (fScale);
		//float fInner = fScale/scaleFactor;
		
		//printf("fInner: %f, fOuter: %f\n", fInner, 1/(fOuter-fInner));
		//printf("camera: %f, %f, %f\n", Position.x, Position.y, Position.z);
		//printf("camera: %f, %f, %f\n", 1.0f / pow(0.650f, 4.0f), 1.0f / pow(0.570f, 4.0f), 1.0f / pow(0.475f, 4.0f));
		
		glUniform4f(glGetUniformLocation(atmosphereShader, "LightPosition"), light_position.x, light_position.y, light_position.z, light_position.w);
    	glUniform3f(glGetUniformLocation(atmosphereShader, "camPosition"), Position.x, Position.y, Position.z);
    	glUniform3f(glGetUniformLocation(atmosphereShader, "v3InvWavelength"), 1.0f / pow(0.650f, 4.0f), 1.0f / pow(0.570f, 4.0f), 1.0f / pow(0.475f, 4.0f));
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fCameraHeight"), lengthvec3(getCameraPosition()));
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fCameraHeight2"), (lengthvec3(getCameraPosition())) * (lengthvec3(getCameraPosition())));
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fInnerRadius"), fInner);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fInnerRadius2"), fInner*fInner);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fOuterRadius"), fOuter);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fOuterRadius2"), fOuter*fOuter);
    
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fKrESun"), 0.0025f * 20.0f);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fKmESun"), 0.0015f * 20.0f);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fKr4PI"), 0.0025f * 4.0f * 3.141592653f);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fKm4PI"), 0.0015f * 4.0f * 3.141592653f);
    
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fScale"), 1/(fOuter-fInner));
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fScaleDepth"), 0.25);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fScaleOverScaleDepth"), 1.0/(fOuter-fInner)/0.25);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "g"), -0.990f);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "g2"), -0.990f*-0.990f);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "time"), glfwGetTime());
    	
    	initMVP(atmosphereShader, m, v);
    	
    	glBindVertexArray (atmosphereVAO);
    	glDrawArrays( GL_TRIANGLES, 0, planet.vertexNumber);
    	glBindVertexArray(0);
    }
}
Exemplo n.º 8
0
// Called by GLUT when we need to redraw the screen.
void display(void) {
    
    // Clear the buffer we will draw into.
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    // Setup camera projection.
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(50.0, double(windowWidth) / double(windowHeight), 0.1, 25);
    
    // Setup camera position/orientation.
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(
        0, 2.5, 10, // eye
        0, 2.5, 0,  // centre
        0, 1  , 0   // up
    );
    glRotated(viewPhi, 1, 0, 0);
    glRotated(viewTheta, 0, 1, 0);
    
    // Must be done after the view is rotated as the lights are stored in
    // eye coords when glLight call is made.
    setupLighting();
    
    // For debugging; show us what the current transformation matrix looks like.
    drawAxis();
    
    // Draw the robot!
    robot.draw();
    
    // Draw a floor. Since it is transparent, we need to do it AFTER all of
    // the opaque objects.
    for (int x = -5; x < 5; x++) {
        for (int y = -5; y < 5; y++) {
            glColor4f(1, 1, 1, (x + y) % 2 ? 0.75 : 0.5);
            glNormal3f(0, 1, 0);
            glBegin(GL_POLYGON);
            glVertex3f(x    , 0, y    );
            glVertex3f(x + 1, 0, y    );
            glVertex3f(x + 1, 0, y + 1);
            glVertex3f(x    , 0, y + 1);
            glEnd();
        }
    }
    
    // Make the buffer we just drew into visible.
    glutSwapBuffers();
}
Exemplo n.º 9
0
//--------------------------------------------------------------
void ofApp::setup() {
  ofSetVerticalSync(true);

  selectedIndex = -1;
  selectedIndexChanged();

  setupLighting();
  setupLattice();
  setupIndexInput();
  setupStrands();
  setupLightController();
  setupIsKeyDown();

  RhombododdyReport report(&lattice);
  report.save("render.png");
}
Exemplo n.º 10
0
void drawMoon()
{
	glUseProgram(planetShader);
	setupLighting(planetShader);
	vec3 Position = getCameraPosition();
	v = getViewMatrix();
	
	mat4 rt = multiplymat4(rotateY(orbitSpeedArray[3]), translate(planetInstanceArray[3].radius*1000, 0.0, 0.0));
	m = multiplymat4(multiplymat4(rt, translate(10.0, 0.0, 0.0)), scale(100));
	
	//mv = modelMatrices[i];
	initMVP(planetShader, m, v);
	glUniform3f(glGetUniformLocation(planetShader, "cameraPos"), Position.x, Position.y, Position.z);
    
    glBindVertexArray (planetVAO);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, planetInstanceArray[2].texture);
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, planetInstanceArray[2].normal);
 	glUniform1i(glGetUniformLocation(planetShader, "tex"), 0);
    glUniform1i(glGetUniformLocation(planetShader, "normalTex"), 1);
    //glDrawArrays( GL_TRIANGLES, 0, planet.vertexNumber );
    glBindVertexArray(0);
}
Exemplo n.º 11
0
// setup creates the display device according to the context
// parameters and associates the device with the application window
// (HWND)hwnd
//
bool Display::setup(void* hwnd) {

    bool rc = false;

	// store address of main application window
    this->hwnd = (HWND)hwnd;

    // set the D3D presentation parameters
    UINT adapter;
	D3DFORMAT d3dFormat;
    ZeroMemory(&d3dpp, sizeof d3dpp);
    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferCount = 1;
    d3dpp.EnableAutoDepthStencil = TRUE;
    D3DDISPLAYMODE d3ddm;
    if (!runInWindow) {
		D3DFORMAT Format[] = D3D_DOC_FORMATS;
		d3dFormat = Format[pixel];
        if (FAILED(d3d->EnumAdapterModes(display, d3dFormat, mode, &d3ddm))) {
            error(L"Display::10 Failed to get selected display mode");
            error(L"Display::11 Defaulting to windowed mode");
            runInWindow = true;
        }
        else {
            adapter = display;
            d3dpp.BackBufferWidth  = d3ddm.Width;
            d3dpp.BackBufferHeight = d3ddm.Height;
            d3dpp.BackBufferFormat = d3ddm.Format;
            d3dpp.FullScreen_RefreshRateInHz = d3ddm.RefreshRate;
            width  = d3ddm.Width;
            height = d3ddm.Height;
        }
    }
    if (runInWindow) {
        adapter = D3DADAPTER_DEFAULT;
		d3d->GetAdapterDisplayMode(adapter, &d3ddm);
		d3dFormat = d3ddm.Format;
        d3dpp.Windowed = TRUE;
		d3dpp.BackBufferWidth  = WND_WIDTH;
		d3dpp.BackBufferHeight = WND_HEIGHT;
		d3dpp.BackBufferFormat = d3dFormat;
        width  = WND_WIDTH;
        height = WND_HEIGHT;
    }
	aspect = (float) width / height;
    context->set(GF_FR_ASP, aspect);

    // find the best format for depth buffering and stenciling
    //
    D3DDEVTYPE devtype;
    if (D3D_OK == d3d->CheckDeviceFormat(adapter, D3DDEVTYPE_HAL,
     d3dFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32)) {
        d3dpp.AutoDepthStencilFormat = D3DFMT_D32; // depth buffer
        devtype = D3DDEVTYPE_HAL;                  // HAL device   
    }
    else if (D3D_OK == d3d->CheckDeviceFormat(adapter, D3DDEVTYPE_HAL, 
     d3dFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16)) {
        d3dpp.AutoDepthStencilFormat = D3DFMT_D16;  // depth buffer
        devtype = D3DDEVTYPE_HAL;                   // HAL Device
    }
    // if the above attempts fail, use the REF (software emulation) device
    // with a 32-bit depth buffer rather than the HAL (hardware accelerated) 
	// device
    else if (D3D_OK == d3d->CheckDeviceFormat(adapter, D3DDEVTYPE_REF,
     d3dFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32)) {
        d3dpp.AutoDepthStencilFormat = D3DFMT_D32;   // depth buffer
        devtype = D3DDEVTYPE_REF;                    // REF Device
    }
    // if all else fails, use the REF (software emulation) with a 16-bit
    // depth buffer, hoping that it will work. (If it doesn't, we are out
    // of luck anyway.)
    else {
        d3dpp.AutoDepthStencilFormat = D3DFMT_D16;   // depth buffer
        devtype = D3DDEVTYPE_REF;                    // REF Device
    }

    // extract the device capabilities and configure the limits
    D3DCAPS9 caps;
    d3d->GetDeviceCaps(adapter, devtype, &caps);

	// hardware or software vertex processing?
	DWORD behaviorFlags;
	if ((caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0)
	    behaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
	else
	    behaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;

    // retrieve the Interface to the D3D display device
    if (d3dd)
        error(L"Display::11 Pointer to Direct3D interface is not NULL");
    else if (FAILED(d3d->CreateDevice(adapter, devtype, (HWND)hwnd, 
	 behaviorFlags, &d3dpp, &d3dd)))
        error(L"Display::12 Failed to create Direct3D device");
    else {
        // maximum number of lights supported by the display device
		maxLights = caps.MaxActiveLights ? caps.MaxActiveLights : MAX_ACTIVE_LIGHTS;
        // set anisotropic filtering to the maximum available on the device
        if (FAILED(d3dd->SetSamplerState(0, D3DSAMP_MAXANISOTROPY,
         caps.MaxAnisotropy - 1)))
            error(L"Display::17 Failed to set up anisotropic filtering");

		// create a sprite COM object to manage the drawing of the hud texture
		// and the drawing of the text item fonts
		if (!scrManager && FAILED(D3DXCreateSprite(d3dd, &scrManager)))
			error(L"Display::18 Failed to create the sprite manager");

		// setup successful
        APILight::connectsThrough(d3dd);
        d3dd->AddRef();
        APITexture::connectsThrough(d3dd);
        d3dd->AddRef();
        APIGraphic::connectsThrough(d3dd);
        d3dd->AddRef();
        APIText::connectsThrough(d3dd);
        d3dd->AddRef();
        APITexture::isManagedBy(scrManager);
        scrManager->AddRef();
        APIText::isManagedBy(scrManager);
        scrManager->AddRef();
        APITexture::hasClientArea(width, height);
        APIText::hasClientArea(width, height);
        rc = true;
    }

	// complete the setup
	if (rc) {
        setupProjection();
        setupLighting();
		setupBlending();
	}

    return rc;
}
Exemplo n.º 12
0
// setup creates the display device according to the context
// parameters and associates the device with the application window
// (HWND)hwnd
//
bool Display::setup(void* hwnd) {

    bool rc = false;

	// store address of main application window
    this->hwnd = (HWND)hwnd;

    // set the D3D presentation parameters
    UINT adapter;
	D3DFORMAT d3dFormat;
    ZeroMemory(&d3dpp, sizeof d3dpp);
    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferCount = 1;
    d3dpp.EnableAutoDepthStencil = TRUE;
    D3DDISPLAYMODE d3ddm;
    if (!runInWindow) {
		D3DFORMAT Format[] = D3D_DOC_FORMATS;
		d3dFormat = Format[pixel];
        if (FAILED(d3d->EnumAdapterModes(display, d3dFormat, mode, &d3ddm))) {
            error(L"Display::10 Failed to get selected display mode");
            error(L"Display::11 Defaulting to windowed mode");
            runInWindow = true;
        }
        else {
            adapter = display;
            d3dpp.BackBufferWidth  = d3ddm.Width;
            d3dpp.BackBufferHeight = d3ddm.Height;
            d3dpp.BackBufferFormat = d3ddm.Format;
            d3dpp.FullScreen_RefreshRateInHz = d3ddm.RefreshRate;
            width_  = d3ddm.Width;
            height_ = d3ddm.Height;
        }
    }
    if (runInWindow) {
        adapter = D3DADAPTER_DEFAULT;
		d3d->GetAdapterDisplayMode(adapter, &d3ddm);
		d3dFormat = d3ddm.Format;
        d3dpp.Windowed = TRUE;
		d3dpp.BackBufferWidth  = WND_WIDTH;
		d3dpp.BackBufferHeight = WND_HEIGHT;
		d3dpp.BackBufferFormat = d3dFormat;
        width_  = WND_WIDTH;
        height_ = WND_HEIGHT;
    }
	aspect = (float) width_ / height_;

    // find the best format for depth buffering and stenciling
    //
    D3DDEVTYPE devtype;
    if (D3D_OK == d3d->CheckDeviceFormat(adapter, D3DDEVTYPE_HAL,
     d3dFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32)) {
        d3dpp.AutoDepthStencilFormat = D3DFMT_D32; // depth buffer
        devtype = D3DDEVTYPE_HAL;                  // HAL device   
    }
    else if (D3D_OK == d3d->CheckDeviceFormat(adapter, D3DDEVTYPE_HAL, 
     d3dFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16)) {
        d3dpp.AutoDepthStencilFormat = D3DFMT_D16;  // depth buffer
        devtype = D3DDEVTYPE_HAL;                   // HAL Device
    }
    // if the above attempts fail, use the REF (software emulation) device
    // with a 32-bit depth buffer rather than the HAL (hardware accelerated) 
	// device
    else if (D3D_OK == d3d->CheckDeviceFormat(adapter, D3DDEVTYPE_REF,
     d3dFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32)) {
        d3dpp.AutoDepthStencilFormat = D3DFMT_D32;   // depth buffer
        devtype = D3DDEVTYPE_REF;                    // REF Device
    }
    // if all else fails, use the REF (software emulation) with a 16-bit
    // depth buffer, hoping that it will work. (If it doesn't, we are out
    // of luck anyway.)
    else {
        d3dpp.AutoDepthStencilFormat = D3DFMT_D16;   // depth buffer
        devtype = D3DDEVTYPE_REF;                    // REF Device
    }

    // extract the device capabilities and configure the limits
    D3DCAPS9 caps;
    d3d->GetDeviceCaps(adapter, devtype, &caps);
	DWORD behaviorFlags;
	// hardware or software vertex processing?
	if ((caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 ||
	 caps.VertexShaderVersion < D3DVS_VERSION(1,1))
	    behaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
	else
	    behaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
    // retrieve the Interface to the D3D display device
    if (d3dd)
        error(L"Display::11 Pointer to Direct3D interface is not NULL");
    else if (FAILED(d3d->CreateDevice(adapter, devtype, (HWND)hwnd, 
	 behaviorFlags, &d3dpp, &d3dd)))
        error(L"Display::12 Failed to create Direct3D device");
    else {
        // maximum number of lights supported by the display device
		maxLights = caps.MaxActiveLights ? caps.MaxActiveLights : 8;
        // set anisotropic filtering to the maximum available on the device
        if (FAILED(d3dd->SetSamplerState(0, D3DSAMP_MAXANISOTROPY,
         caps.MaxAnisotropy - 1)))
            error(L"Display::13 Failed to set up anisotropic filtering");

		// create a sprite COM object to manage the drawing of the hud texture
		// and the drawing of the text item fonts
		if (!spriteManager_ && FAILED(D3DXCreateSprite(d3dd, &spriteManager_)))
			error(L"Display::14 Failed to create the font manager");

		// setup successful
        rc = true;
    }
	//setup fog
	if (caps.RasterCaps & D3DPRASTERCAPS_FOGRANGE)
	{
		//configure fog distances and thickness
		float fogStart = FOGSTART_DEFAULT;
		float fogEnd = FOGEND_DEFAULT;

		//enable fog
		d3dd->SetRenderState(D3DRS_FOGENABLE,TRUE);
		
		//enable ranged base fog
		d3dd->SetRenderState(D3DRS_RANGEFOGENABLE,TRUE);

		//configure fog color
		d3dd->SetRenderState(D3DRS_FOGCOLOR,FOGCOLOR_DEFAULT);
		
		//set fog to be vertex fog using linear fog formula
		d3dd->SetRenderState(D3DRS_FOGVERTEXMODE,D3DFOG_LINEAR);

		//set fog distances and thickness
		d3dd->SetRenderState(D3DRS_FOGSTART,*(DWORD*)(&fogStart));
		d3dd->SetRenderState(D3DRS_FOGEND,*(DWORD*)(&fogEnd));
	
	}
	// complete the setup
	if (rc) {
        setupProjection();
        setupLighting();
		setupBlending();
	}

    return rc;
}