Ejemplo n.º 1
0
HRESULT KRLCamera::SetCamera(IKG3DCamera* p3DCamera, IKG3DScene* p3DScene)
{
    int nRetCode = false;
    HRESULT hrResult = E_FAIL;
    float fYaw = 0.0f;
    float fPitch = 0.0f;
    float fRoll = 0.0f;

    KGLOG_PROCESS_ERROR(p3DCamera);
    KGLOG_PROCESS_ERROR(p3DScene);

    m_CommonInfo.p3DCamera = p3DCamera;
    m_CommonInfo.p3DScene = p3DScene;

    nRetCode = SetPerspective();
    KGLOG_PROCESS_ERROR(nRetCode);

    fYaw = g_pRL->m_TableList.GetNumber(RL_NUMBER_CAMERA_INIT_YAW);
    fPitch = g_pRL->m_TableList.GetNumber(RL_NUMBER_CAMERA_INIT_PITCH);
    fRoll = g_pRL->m_TableList.GetNumber(RL_NUMBER_CAMERA_INIT_ROLL);

    m_CommonInfo.CameraController.SetYaw(fYaw);
    m_CommonInfo.CameraController.SetPitch(fPitch);
    m_CommonInfo.CameraController.SetRoll(fRoll);

    m_pCamera->SetCamera();

    hrResult = S_OK;
Exit0:
    return hrResult;
}
Ejemplo n.º 2
0
void RendererOGL::Render()
{
	if(!IsShown())
        return;

    SetGLContext();
    
    // Init OpenGL once, but after SetCurrent
    if (!m_initialized)
    {
        InitGL();
        ScreenCreate();
        m_initialized = true;
    }
	
    SetPerspective();
	
    // clear color and depth buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glLoadIdentity();
    MoveCamera(m_camera);
    m_camera.Apply();
    
    if (!m_camera.IsEqualTo(m_camera2D, 0.01f))
        GeoDraw(m_geo);
    ScreenDraw();
	
    glFlush();
    SwapBuffers();

}
bool
GlRendererTemplate::InitializeGl(void)
{
	// TODO:
	// Initialize GL status. 

	glShadeModel(GL_SMOOTH);
	glViewport(0, 0, GetTargetControlWidth(), GetTargetControlHeight());

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	SetPerspective(60.0f, 1.0f * GetTargetControlWidth() / GetTargetControlHeight(), 1.0f, 400.0f);

	glClearColor(0, 0, 0, 1);
	glClear(GL_COLOR_BUFFER_BIT);

	return true;
}
Ejemplo n.º 4
0
Camera::Camera(const Vector3f &position, const Vector3f &target,
               const Vector3f &up, float fov, float aspect_ratio, float near,
               float far)
    : view_(Matrix4f::Identity()),
      perspective_projection_(Matrix4f::Identity()) {
  SetView(position, target, up);
  SetPerspective(fov, aspect_ratio, near, far);
}
Ejemplo n.º 5
0
void ResizeFunc(int NewWidth, int NewHeight)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

    glViewport(0, 0, NewWidth, NewHeight);
	//glOrtho(0, Width, 0, Height, -100, 1);
	SetPerspective(50.0f);
}
Ejemplo n.º 6
0
    // CView constructor
    CView::CView()
        //: m_Transform( RQuaternionZero(), RVector3( 0.0f, 90, -100.0f ) )
    {
        SetPerspective( 60.0f, 1024.0f/768.0f, 0.1f, 10000.0f );

        m_vPosition = RVector4( 10.0f, 100.0f, 10.0f, 0.0f );
        m_vLook =     RVector4( 0.0f, -4.0f, 10.0f, 0.0f );
        m_vUp =       RVector4( 0.0f, 1.0f, 0.0f, 0.0f );
    }
void
init_gles(Evas_Object *obj)
{
	ELEMENTARY_GLVIEW_USE(obj);
	appdata_s *ad = (appdata_s *)evas_object_data_get(obj, APPDATA_KEY);

	int width;
	int height;

	elm_glview_size_get(obj, &width, &height);

	ad->current_tex_index = 0;

	{
		glGenTextures(2, ad->tex_ids);

		glBindTexture(GL_TEXTURE_2D, ad->tex_ids[0]);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, IMAGE_4444_128_128_1);
		glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

		glBindTexture(GL_TEXTURE_2D, ad->tex_ids[1]);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, IMAGE_565_128_128_1);
		glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	}

	glShadeModel(GL_SMOOTH);

	glViewport(0, 0, width, height);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);

	{
		glEnable(GL_FOG);
		glFogx(GL_FOG_MODE,     GL_LINEAR);
		glFog(GL_FOG_DENSITY, GetGlUnit(0.25f));
		glFog(GL_FOG_START,   GetGlUnit(4.0f));
		glFog(GL_FOG_END,     GetGlUnit(6.5f));
		glHint(GL_FOG_HINT,     GL_DONT_CARE);
	}

	SetPerspective(obj, 60.0f, 1.0f * width / height, 1.0f, 400.0f);

	glClearColorEx(0, 0, 0, 1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void
resize_gl(Evas_Object *obj)
{
	ELEMENTARY_GLVIEW_USE(obj);

	int width;
	int height;

	elm_glview_size_get(obj, &width, &height);

	SetPerspective(obj, 60.0f, 1.0f * width / height, 1.0f, 400.0f);
}
Ejemplo n.º 9
0
HRESULT KG3DCamera::RestoreGlobalProject()
{
	if (m_bGlobalPerspective)
	{
		return SetPerspective(
			m_GlobalPerspectiveData.fFovy,  m_GlobalPerspectiveData.fAspect, 
			m_GlobalPerspectiveData.fzNear, m_GlobalPerspectiveData.fzFar
			);
	}
	else
	{
		return SetOrthogonal(
			m_GlobalOrthogonalData.fWidth, m_GlobalOrthogonalData.fHeight,
			m_GlobalOrthogonalData.fzNear, m_GlobalOrthogonalData.fzFar
			);
	}
}
void
View3DAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("View3DAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("viewNormal")) != 0)
        SetViewNormal(node->AsDoubleArray());
    if((node = searchNode->GetNode("focus")) != 0)
        SetFocus(node->AsDoubleArray());
    if((node = searchNode->GetNode("viewUp")) != 0)
        SetViewUp(node->AsDoubleArray());
    if((node = searchNode->GetNode("viewAngle")) != 0)
        SetViewAngle(node->AsDouble());
    if((node = searchNode->GetNode("parallelScale")) != 0)
        SetParallelScale(node->AsDouble());
    if((node = searchNode->GetNode("nearPlane")) != 0)
        SetNearPlane(node->AsDouble());
    if((node = searchNode->GetNode("farPlane")) != 0)
        SetFarPlane(node->AsDouble());
    if((node = searchNode->GetNode("imagePan")) != 0)
        SetImagePan(node->AsDoubleArray());
    if((node = searchNode->GetNode("imageZoom")) != 0)
        SetImageZoom(node->AsDouble());
    if((node = searchNode->GetNode("perspective")) != 0)
        SetPerspective(node->AsBool());
    if((node = searchNode->GetNode("eyeAngle")) != 0)
        SetEyeAngle(node->AsDouble());
    if((node = searchNode->GetNode("centerOfRotationSet")) != 0)
        SetCenterOfRotationSet(node->AsBool());
    if((node = searchNode->GetNode("centerOfRotation")) != 0)
        SetCenterOfRotation(node->AsDoubleArray());
    if((node = searchNode->GetNode("axis3DScaleFlag")) != 0)
        SetAxis3DScaleFlag(node->AsBool());
    if((node = searchNode->GetNode("axis3DScales")) != 0)
        SetAxis3DScales(node->AsDoubleArray());
    if((node = searchNode->GetNode("shear")) != 0)
        SetShear(node->AsDoubleArray());
    if((node = searchNode->GetNode("windowValid")) != 0)
        SetWindowValid(node->AsBool());
}
void
ViewAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("ViewAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("viewNormal")) != 0)
        SetViewNormal(node->AsDoubleArray());
    if((node = searchNode->GetNode("focus")) != 0)
        SetFocus(node->AsDoubleArray());
    if((node = searchNode->GetNode("viewUp")) != 0)
        SetViewUp(node->AsDoubleArray());
    if((node = searchNode->GetNode("viewAngle")) != 0)
        SetViewAngle(node->AsDouble());
    if((node = searchNode->GetNode("setScale")) != 0)
        SetSetScale(node->AsBool());
    if((node = searchNode->GetNode("parallelScale")) != 0)
        SetParallelScale(node->AsDouble());
    if((node = searchNode->GetNode("nearPlane")) != 0)
        SetNearPlane(node->AsDouble());
    if((node = searchNode->GetNode("farPlane")) != 0)
        SetFarPlane(node->AsDouble());
    if((node = searchNode->GetNode("imagePan")) != 0)
        SetImagePan(node->AsDoubleArray());
    if((node = searchNode->GetNode("imageZoom")) != 0)
        SetImageZoom(node->AsDouble());
    if((node = searchNode->GetNode("perspective")) != 0)
        SetPerspective(node->AsBool());
    if((node = searchNode->GetNode("windowCoords")) != 0)
        SetWindowCoords(node->AsDoubleArray());
    if((node = searchNode->GetNode("viewportCoords")) != 0)
        SetViewportCoords(node->AsDoubleArray());
    if((node = searchNode->GetNode("eyeAngle")) != 0)
        SetEyeAngle(node->AsDouble());
}
Ejemplo n.º 12
0
void PS2Sprite3D::Initialise(Vector4 Vertex_1, Vector4 Vertex_2, Vector4 Vertex_3, Vector4 Vertex_4)
//  Initialise the vertex points.  m_z, m_x, m_y etc are now not used.
//  Set the perspective matrix to the identity matrix.
{
	m_z = 128.0f;
	m_x = 0.0f;
	m_y = 0.0f;
	m_w = m_h = m_w_orig = m_h_orig = 32.0f;
	m_r = m_g = m_b = m_a = 0x80;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			colours[i][j] = m_r;
		}
	}

	m_TopLeftWorld = Vertex_1;
	m_BottomLeftWorld = Vertex_4;
	m_TopRightWorld = Vertex_2;
	m_BottomRightWorld = Vertex_3;
	
	SetPerspective(Matrix4x4::IDENTITY);
}
Ejemplo n.º 13
0
/* function to reset our viewport after a window resize */
int SDLScreen::ResizeWindow( int width, int height )
{
	if ( !m_kScreen )
	{
		return false;
	}

	/* Protect against a divide by zero */
	if ( height == 0 )
	{
		height = 1;
	}

	ratio = (GLfloat)width / (GLfloat)height;

	/* Setup our viewport. */
	glViewport( 0, 0, (GLint)width, (GLint)height );

	SetPerspective();

	return true;
}
Ejemplo n.º 14
0
void Render()
{
	SetOrtho();
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();
	glEnable(GL_TEXTURE_2D);

	//sprite.PaintModule(0, 200.0, 200.0, 1);
	//sprite.PaintFrame(0, 300, 10, 1);
	sprite.PaintAnimation(0, 0, 0, 1, true);
#if 0
	glDisable(GL_TEXTURE_2D);
	glTranslatef(64.0f, 64.0f, 0.0f);
	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	glNormal3f(0.0f, 0.0f, 1.0f);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	float ratio = (float)SCREEN_WIDTH / SCREEN_HEIGHT;
	SetPerspective(45.0f, ratio, 0.1f, 100.0f);
	glLoadIdentity();
	//glDisable(GL_TEXTURE_2D);
	glScalef(0.25f, 0.25f, 0.25f);
	glTranslatef(3.0f, 0.0f, -8.0f);

	glVertexPointer(3, GL_FLOAT, 0, vertices);
	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	//go through our index array and draw our vertex array
	glDrawElements(GL_TRIANGLE_STRIP, 24, GL_UNSIGNED_BYTE, indices);
	glPopMatrix();
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
#endif	//if0	
	eglSwapBuffers(glesDisplay, glesSurface);
	return;
}
Ejemplo n.º 15
0
void DisplayFunc()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();
	SetPerspective(50.0f);
	glTranslatef(0.0f, 0.0f, TransFactor);
	glRotatef(Angle, 0.0f, 1.0f, 0.0f);

	glBindTexture(GL_TEXTURE_2D, TexID1);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f);
		glVertex3i(-Width, -Height, Depth);
		glTexCoord2f(1.0f, 0.0f);
		glVertex3i(Width, -Height, Depth);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3i(Width, Height, Depth);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3i(-Width, Height, Depth);
	glEnd();

	glBindTexture(GL_TEXTURE_2D, TexID2);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f);
		glVertex3i(-Width, -Height, Depth);
		glTexCoord2f(1.0f, 0.0f);
		glVertex3i(-Width, -Height, -Depth);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3i(-Width, Height, -Depth);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3i(-Width, Height, Depth);
	glEnd();

	glBindTexture(GL_TEXTURE_2D, TexID3);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f);
		glVertex3i(Width, -Height, Depth);
		glTexCoord2f(1.0f, 0.0f);
		glVertex3i(Width, -Height, -Depth);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3i(Width, Height, -Depth);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3i(Width, Height, Depth);
	glEnd();

	glBindTexture(GL_TEXTURE_2D, TexID4);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f);
		glVertex3i(-Width, -Height, -Depth);
		glTexCoord2f(1.0f, 0.0f);
		glVertex3i(Width, -Height, -Depth);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3i(Width, Height, -Depth);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3i(-Width, Height, -Depth);
	glEnd();


	glFlush();
	glFinish();
	glutSwapBuffers();
}
Ejemplo n.º 16
0
void Enable3D()
{
	SetPerspective();
	glEnable(GL_LIGHTING);
	//glEnable(GL_TEXTURE_2D);
}
Ejemplo n.º 17
0
		void PSGLRenderManager::RenderToScreen()
		{
			//in opegl case just set again perspective
			SetPerspective();
		}
Ejemplo n.º 18
0
void KG3DCameraPreset::GetPresetCamera(KG3DModel *pModel, 
									   enuCameraPresetType Type,
									   float fAspect,
									   bool bUsedForMeshMdlThumbnail/*  = false */ )
{
	D3DXVECTOR3 vec3Position, vec3LookAt;
	float fWidth, fHeight, fDepth, fZFar;
	fZFar = 0.0f;
	D3DXMATRIX matTranlation;
	float offset_position = 0.0f;
	KG_PROCESS_ERROR(pModel);

	fWidth = abs(pModel->m_BBox.A.x - pModel->m_BBox.B.x);
	fHeight = abs(pModel->m_BBox.A.y - pModel->m_BBox.B.y);
	fDepth = abs(pModel->m_BBox.A.z - pModel->m_BBox.B.z);

	vec3LookAt.z = (pModel->m_BBox.A.z + pModel->m_BBox.B.z) / 2.0f;
	vec3LookAt.x = pModel->m_BBox.A.x + fWidth / 2.0f;
	vec3LookAt.y = (pModel->m_BBox.A.y + pModel->m_BBox.B.y) / 2;

	if (bUsedForMeshMdlThumbnail)
	{
		TCHAR strFile[MAX_PATH]; 
		TCHAR strDrive[MAX_PATH];
		TCHAR strPath[MAX_PATH];
		TCHAR strExt[MAX_PATH];
		_splitpath_s(pModel->m_scName.c_str(), 
			strDrive, 
			MAX_PATH,
			strPath, 
			MAX_PATH, 
			strFile, 
			MAX_PATH, 
			strExt,
			MAX_PATH);


		offset_position = max(max(fWidth, fHeight), fDepth) / 2.0f / tan(D3DX_PI / 6.0f);

		if (strcmpi(strExt, ".mesh") == 0)
		{

			vec3Position.z = vec3LookAt.z - offset_position;
			vec3Position.x = vec3LookAt.x + offset_position;
			vec3Position.y = vec3LookAt.y + offset_position;
		}
		else
		{
			vec3LookAt.y = (pModel->m_BBox.A.y + pModel->m_BBox.B.y) / 2.0f + fHeight / 5.0f;
			vec3Position.z = vec3LookAt.z - offset_position * 0.65f;
			vec3Position.x = vec3LookAt.x + offset_position * 0.65f;
			vec3Position.y = vec3LookAt.y + offset_position * 0.65f;
		}		
	}
	else
	{
		vec3Position.z = pModel->m_BBox.A.z - max(fWidth, fHeight) / 2.0f / tan(D3DX_PI / 8);
		vec3Position.x = vec3LookAt.x;
		vec3Position.y = vec3LookAt.y;
	}

	fZFar = vec3Position.z - pModel->m_BBox.B.z;

	/*SetUpDirection(D3DXVECTOR3(0.0f, 1.0f, 0.0f));
	SetPosition(vec3Position);
	SetLookAtPosition(vec3LookAt);*/
	SetPositionLookAtUp(&vec3Position, &vec3LookAt, &D3DXVECTOR3(0,1,0));
	SetPerspective(D3DX_PI / 4, fAspect, 10.0f, fZFar);
	ComputeMatrix(Type);
	D3DXMatrixTranslation(&matTranlation, 0.0f, 0.0f, -(pModel->m_BBox.A.y + pModel->m_BBox.B.y) / 2.0f);
	m_CameraInfo[Type].matView = /*matTranlation * */m_matTransform[Type] * m_CameraInfo[Type].matView;
Exit0:
	;
}
Ejemplo n.º 19
0
BOOL cGraphics::SetMode(HWND hWnd, BOOL Windowed, BOOL UseZBuffer, long Width, long Height, char BPP)
{
  D3DPRESENT_PARAMETERS d3dpp;
  D3DFORMAT             Format, AltFormat;
  RECT                  WndRect, ClientRect;
  long                  WndWidth, WndHeight;
  float                 Aspect;

  // Error checking
  if((m_hWnd = hWnd) == NULL)
    return FALSE;
  if(m_pD3D == NULL)
    return FALSE;

  // Get the current display format
  if(FAILED(m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &m_d3ddm)))
    return FALSE;

  // Configure width
  if(!Width) {
    // Default to screen width if fullscreen
    if(Windowed == FALSE) {
      m_Width = m_d3ddm.Width;
    } else {
      // Otherwise grab from client size
      GetClientRect(m_hWnd, &ClientRect);
      m_Width = ClientRect.right;
    }
  } else {
    m_Width = Width;
  }

  // Configure height
  if(!Height) {
    // Default to screen height if fullscreen
    if(Windowed == FALSE) {
      m_Height = m_d3ddm.Height;
    } else {
      // Otherwise grab from client size
      GetClientRect(m_hWnd, &ClientRect);
      m_Height = ClientRect.bottom;
    }
  } else {
    m_Height = Height;
  }

  // Configure BPP
  if(!(m_BPP = BPP) || Windowed == TRUE) {
    if(!(m_BPP = GetFormatBPP(m_d3ddm.Format)))
      return FALSE;
  }

  // Resize client window if using windowed mode
  if(Windowed == TRUE) {
    GetWindowRect(m_hWnd, &WndRect);
    GetClientRect(m_hWnd, &ClientRect);

    WndWidth  = (WndRect.right  - (ClientRect.right  - m_Width))  - WndRect.left;
    WndHeight = (WndRect.bottom - (ClientRect.bottom - m_Height)) - WndRect.top;

    MoveWindow(m_hWnd, WndRect.left, WndRect.top, WndWidth, WndHeight, TRUE);
  }

  // Clear presentation structure
  ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
  
  // Default to no hardware acceleration detected
  m_HAL = FALSE;

  // Setup Windowed or fullscreen usage
  if((m_Windowed = Windowed) == TRUE) {
    d3dpp.Windowed         = TRUE;
    d3dpp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = m_d3ddm.Format;

    // See if card supports HAL
    if(CheckFormat(m_d3ddm.Format, TRUE, TRUE) == TRUE) {
      m_HAL = TRUE;
    } else {
      // Return error if not emulated
      if(CheckFormat(m_d3ddm.Format, TRUE, FALSE) == FALSE)
        return FALSE;
    }
  } else {
    d3dpp.Windowed   = FALSE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;
  
    d3dpp.BackBufferWidth  = m_Width;
    d3dpp.BackBufferHeight = m_Height;
    d3dpp.FullScreen_RefreshRateInHz      = D3DPRESENT_RATE_DEFAULT;
    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // or D3DPRESENT_INTERVAL_DEFAULT or D3DPRESENT_INTERVAL_IMMEDIATE

    // Figure display format to use
    if(m_BPP == 32) {
      Format    = D3DFMT_X8R8G8B8;
      AltFormat = D3DFMT_X8R8G8B8;
    }
    if(m_BPP == 24) {
      Format    = D3DFMT_R8G8B8;
      AltFormat = D3DFMT_R8G8B8;
    }
    if(m_BPP == 16) {
      Format    = D3DFMT_R5G6B5;
      AltFormat = D3DFMT_X1R5G5B5;
    }
    if(m_BPP == 8) {
      Format    = D3DFMT_P8;
      AltFormat = D3DFMT_P8;
    }

    // Check for HAL device
    if(CheckFormat(Format, FALSE, TRUE) == TRUE) {
      m_HAL = TRUE;
    } else {
      // Check for HAL device in alternate format
      if(CheckFormat(AltFormat, FALSE, TRUE) == TRUE) {
        m_HAL = TRUE;
        Format = AltFormat;
      } else {
        // Check for Emulation device
        if(CheckFormat(Format, FALSE, FALSE) == FALSE) {
          // Check for Emulation device in alternate format
          if(CheckFormat(AltFormat, FALSE, FALSE) == FALSE)
            return FALSE;
          else
            Format = AltFormat;
        }
      }
    }

    d3dpp.BackBufferFormat = Format;
  }

  // Setup Zbuffer format - 16 bit
  if((m_ZBuffer = UseZBuffer) == TRUE) {
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
  } else {
    d3dpp.EnableAutoDepthStencil = FALSE;
  }

  // Create the Direct3D Device object
  if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 
               (m_HAL == TRUE) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, 
               hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
               &d3dpp, &m_pD3DDevice))) {

    // Try to create Direct3D without ZBuffer support 
    // if selected and first call failed.
    if(m_ZBuffer == TRUE) {
      m_ZBuffer = FALSE;
      d3dpp.EnableAutoDepthStencil = FALSE;

      if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 
                   (m_HAL == TRUE) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, 
                   hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                   &d3dpp, &m_pD3DDevice)))
        return FALSE;
    } else                                   
      return FALSE;
  }

	//// create and set the render target surface
 //   // it should be lockable on XP and nonlockable on Vista
 //   if (FAILED(m_pD3DDevice->CreateRenderTarget(m_Width, m_Height, 
 //       D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, 
 //       TRUE, // lockable
 //       &m_pD3DSurface, NULL)))
 //   {
 //       return FALSE;
 //   }
 //   //m_pD3DDevice->SetRenderTarget(0, m_pD3DSurface);

  // Set default rendering states
  EnableLighting(FALSE);
  EnableZBuffer(m_ZBuffer);
  EnableAlphaBlending(FALSE);
  EnableAlphaTesting(FALSE);

  // Enable texture rendering stages and filter types
  m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
  m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );

  m_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
  m_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);

  // Set default ambient color to white
  SetAmbientLight(255,255,255);

  // Calculate the aspect ratio based on window size
  Aspect = (float)m_Height / (float)m_Width;
  SetPerspective(D3DX_PI/4, Aspect, 1.0f, 10000.0f);

  // Create a sprite interface
  if(FAILED(D3DXCreateSprite(m_pD3DDevice, &m_pSprite)))
    return FALSE;

  return TRUE;
}
Ejemplo n.º 20
0
GameSystemImplementation::GameSystemImplementation(Int32 inWidth, Int32 inHeight) : width(inWidth), height(inHeight), camx(0), camy(0), camz(6.0f) {
    resMan.AddResourceLoader<ResourceShader>("glf");
    resMan.AddResourceLoader<ResourceShader>("glv");

    Shader::SetBlendFunc(Shader::BLEND_Transparent);

    std::string vertshader = resMan.Load<ResourceShader>("shaders/default.glv")->string;
    std::string fragshader = resMan.Load<ResourceShader>("shaders/default.glf")->string;
    shader.Initialize(vertshader, fragshader, true);
    SetPerspective(width, height);
    LookAt(glm::vec3(0.0f, 0.0f, camz), glm::vec3(camx, camy, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
    batch.SetShader(shader);

    Vertex verts[] = {
        // front
        {0.0f,  0.0f, 1.0f, 255, 0, 0, 255},
        {-1.0f,  0.0f, 1.0f, 0, 0, 255, 150},
        {-1.0f, -1.0f, 1.0f, 0, 255, 0, 0},
        {0.0f,  0.0f, 1.0f, 255, 0, 0, 255},
        {-1.0f,  -1.0f, 1.0f, 0, 255, 0, 0},
        {0.0f, -1.0f, 1.0f, 0, 0, 255, 150},

        // back
        {0.0f,  -1.0f, 0.0f, 255, 0, 0, 255},
        {-1.0f, -1.0f, 0.0f, 0, 0, 255, 150},
        {-1.0f,  0.0f, 0.0f, 0, 255, 0, 0},
        {0.0f,  -1.0f, 0.0f, 255, 0, 0, 255},
        {-1.0f,  0.0f, 0.0f, 0, 255, 0, 0},
        {0.0f,   0.0f, 0.0f, 0, 0, 255, 150},

        // top
        {0.0f,  0.0f, 0.0f, 255, 0, 0, 255},
        {-1.0f,  0.0f, 0.0f, 0, 0, 255, 150},
        {-1.0f,  0.0f, 1.0f, 0, 255, 0, 0},
        {0.0f,  0.0f, 0.0f, 255, 0, 0, 255},
        {-1.0f,  0.0f, 1.0f, 0, 255, 0, 0},
        {0.0f,  0.0f, 1.0f, 0, 0, 255, 150},

        // bottom
        {0.0f,  -1.0f, 1.0f, 255, 0, 0, 255},
        {-1.0f, -1.0f, 1.0f, 0, 0, 255, 150},
        {-1.0f, -1.0f, 0.0f, 0, 255, 0, 0},
        {0.0f,  -1.0f, 1.0f, 255, 0, 0, 255},
        {-1.0f, -1.0f, 0.0f, 0, 255, 0, 0},
        {0.0f,  -1.0f, 0.0f, 0, 0, 255, 150},

        // left
        {-1.0f,  0.0f, 1.0f, 255, 0, 0, 255},
        {-1.0f,  0.0f, 0.0f, 0, 0, 255, 150},
        {-1.0f, -1.0f, 0.0f, 0, 255, 0, 0},
        {-1.0f,  0.0f, 1.0f, 255, 0, 0, 255},
        {-1.0f, -1.0f, 0.0f, 0, 255, 0, 0},
        {-1.0f, -1.0f, 1.0f, 0, 0, 255, 150},

        // right
        {0.0f,  0.0f, 0.0f, 255, 0, 0, 255},
        {0.0f,  0.0f, 1.0f, 0, 0, 255, 150},
        {0.0f, -1.0f, 1.0f, 0, 255, 0, 0},
        {0.0f,  0.0f, 0.0f, 255, 0, 0, 255},
        {0.0f, -1.0f, 1.0f, 0, 255, 0, 0},
        {0.0f, -1.0f, 0.0f, 0, 0, 255, 150}
    };
    batch.Queue(verts, sizeof(verts)/sizeof(Vertex));
    batch.Upload(RenderBatcher::USAGE_Static);
}