void OpenGLEngine::Initialize () { m_ClearDepth = 1.0f; m_ClearColor = glm::vec4 (0.0f, 0.0f, 0.0f, 1.0f); SetViewport (glm::vec4 (0.0f, 0.0f, 0.0f, 0.0f)); SetDepthRange (0.0f, 1.0f); m_DefaultBlendState = std::make_shared<BlendState> (); m_DefaultDepthStencilState = std::make_shared<DepthStencilState> (); m_DefaultRasterizerState = std::make_shared<RasterizerState> (); SetDefaultBlendState(); SetDefaultDepthStencilState(); SetDefaultRasterizerState(); }
// sets the range for the view frustum ( and z buffer range ) void C3dView::SetDepthRange ( float xFarZ ) { SetDepthRange(m_xNearZ,xFarZ); }
// initalise the OpenGL context void C3dView::InitGL ( long iX,long iY) { m_iViewportX = iX; m_iViewportY = iY; m_fAspect = 1.33f; if (m_iViewportY != 0) m_fAspect = (float) m_iViewportX / (float) m_iViewportY; // set the projection matrix and viewport info SetDepthRange(m_xNearZ,m_xFarZ); // set the BG color glClearColor ((float)m_BackGroundColor.r, (float)m_BackGroundColor.g, (float)m_BackGroundColor.b, 1.0); glClearDepth(1.0f); // Depth Buffer Setup // make everything look it's best not fastest. glHint(GL_PERSPECTIVE_CORRECTION_HINT ,GL_NICEST); // we want a z buffer glEnable (GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do // we want back face culling glEnable (GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CCW); // we want smooth filled polies glShadeModel (GL_SMOOTH); glPolygonMode (GL_FRONT, GL_FILL); glEnable (GL_LIGHTING); EnabletLight(0,true); float f[4] = {1.0f}; f[0] = f[1] = f[2] = 0.25f; SetLightInfo(0,eLightAmb,f); f[0] = f[1] = f[2] = 0.60f; SetLightInfo(0,eLightDif,f); f[0] = f[1] = f[2] = 0.60f; SetLightInfo(0,eLightSpec,f); f[0] = 0;f[1] = 0;f[2] = 10.0f; SetLightInfo(0,eLightPos,f); UpdateLights(); // but only enable one ?!? // glEnable (GL_LIGHT0); // we want alpha based transperancy glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_COLOR_MATERIAL); // clear out the model view matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity (); }