CameraInstance* CreateDefaultCamera(EditableScene *es, const char *camTag, const char *nodeTag, const char *instTag) { Camera *pCamera = es->CreateCamera(); pCamera->SetTag(camTag); Node *pNode = es->CreateNode(NULL); pNode->SetTag(nodeTag); CameraInstance *pCI = es->CreateCameraInstance(pNode, pCamera); pCI->SetTag(instTag); Property* pTransform = pNode->AppendTransform(Transform::MATRIX, Zero)->GetDelegate(NULL); AutoPtr<AccessProviderLocal> providerLocal; CreateAccessProviderLocal(&providerLocal); float3 aabb(es->GetSceneAABB(-1, 0, providerLocal)); float3 center(es->GetSceneCenter(-1, 0, providerLocal)); float4x4 ypr; MatrixRotationYawPitchRoll(&ypr, 3.141692f/4, -3.141692f/4, 0); float4x4 t0; MatrixTranslation(&t0, center.x, center.y, center.y); float4x4 t1; float bbD = Vec3Length(&aabb); MatrixTranslation(&t1, 0, 0, bbD*2); float4x4 up = es->GetUpAxis(); float4x4 upI; MatrixInverse(&upI, 0, &up); float4x4 minusZ; MatrixScaling(&minusZ, 1,1,-1); float4x4 m = t1*ypr*t0*minusZ*upI; MatrixTranspose(&m, &m); pTransform->SetValue(m); pCamera->SetFar(10*bbD); return pCI; }
void XGraphicsOpenGL::DrawTexture( GLint idTexture, float xpos, float ypos, float width, float height, BOOL bBlendAdd ) { CHECK_GL_ERROR(); GLfloat tex[8] = { 0, 1.0f, 1.0f, 1.0f, 0, 0, 1.0f, 0 }; GLfloat pos[8] = { xpos, ypos + height, xpos + width, ypos + height, xpos, ypos, xpos + width, ypos }; GLfloat col[16] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; MATRIX mTrans, mScale, mMVP; MatrixTranslation( mTrans, xpos, ypos, 0 ); MatrixScaling( mScale, 1.f, 1.f, 1.f ); MatrixIdentity( mMVP ); MatrixMultiply( mMVP, mMVP, mScale ); MatrixMultiply( mMVP, mMVP, mTrans ); MatrixMultiply( mMVP, mMVP, XE::x_mViewProjection ); // 8픽셀 크기로 블러가 되게 하려고 8픽셀 여유를 뒀다. // 현재 쉐이더를 얻어온다 GRAPHICS_GL->sSetShader( GRAPHICS_GL->GetpShaderColTex() ); XShader *pShader = XGraphicsOpenGL::sGetShader(); pShader->SetUniformMVP( mMVP ); pShader->SetUniformColor( 1.0f, 1.0f, 1.0f, 1.0f ); // pShader->SetShader( mMVP, 1.0f, 1.0f, 1.0f, 1.0f ); // GRAPHICS_GL->GetpBaseShader()->SetShader( mMVP, 1.0f, 1.0f, 1.0f, 1.0f ); // GRAPHICS_GL->GetpBaseShader()->SetShader( XE::x_mViewProjection, 1.0f, 1.0f, 1.0f, 1.0f ); CHECK_GL_ERROR(); glEnable( GL_BLEND ); if( bBlendAdd ) glBlendFunc( GL_SRC_ALPHA, GL_ONE ); else glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); #ifdef _XVAO glBindVertexArrayOES( 0 ); #endif CHECK_GL_ERROR(); glBindBuffer( GL_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); glEnableVertexAttribArray( XE::ATTRIB_POS ); glEnableVertexAttribArray( XE::ATTRIB_COLOR ); glEnableVertexAttribArray( XE::ATTRIB_TEXTURE ); glVertexAttribPointer( XE::ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, pos ); glVertexAttribPointer( XE::ATTRIB_TEXTURE, 2, GL_FLOAT, GL_FALSE, 0, tex ); glVertexAttribPointer( XE::ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, col ); glEnableVertexAttribArray( XE::ATTRIB_SIZE ); CHECK_GL_ERROR(); // bind texture XGraphicsOpenGL::sBindTexture( idTexture ); CHECK_GL_ERROR(); glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 ); CHECK_GL_ERROR(); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); CHECK_GL_ERROR(); }