void Stretch(ConstImageBuffer src) { Stretch(0, 0, GetWidth(), GetHeight(), src, 0, 0, src.width, src.height); }
GeometryTerrain::GeometryTerrain(int size, int patch_size, int num_hills, float smoothness, int smooth_passes ) : m_Width(size), m_Length(size), m_patchSize(patch_size) { if(patch_size < 2) patch_size = 2; if(patch_size > size) patch_size = size; m_pHeight = new float*[m_Width+1]; m_fOffsetX = 1.0f; m_fOffsetY = 1.0f; m_fOffsetZ = 1.0f; for(int i = 0; i <= m_Length; i++) { m_pHeight[i] = new float[m_Width+1]; memset(m_pHeight[i], 0, sizeof(float)*(m_Length+1)); } m_pVertices = NULL; m_nVertexCount = ((unsigned int)GetWidth()+1)*((unsigned int)GetLength()+1); //memset(m_pVertices, 0, m_nVertexCount); //memset(m_pNormals, 0, m_nVertexCount); m_pVertices = new flx_Vertex[m_nVertexCount]; m_pTexCoords = new flx_TexCoord[m_nVertexCount]; m_pNormals = new flx_Normal[m_nVertexCount]; //Add some random Hills and smooth it generateTerrain(num_hills); for(int i = 0; i < smooth_passes; ++i) smoothTerrain(smoothness); int deg_x = 0, deg_z = 0; for(int z = 0; z <= GetLength(); z++) { for(int x = 0; x <= GetWidth(); x++) { //fill Vertex array with data m_pVertices[x + z * (GetWidth()+1)].x = (float)x * m_fOffsetX; m_pVertices[x + z * (GetWidth()+1)].y = getHeight(x, z); m_pVertices[x + z * (GetWidth()+1)].z = (float)z * m_fOffsetZ; //fill TexCoord array with data m_pTexCoords[x + z * (GetWidth()+1)].u = (float)((float)x/(GetWidth()+1)); m_pTexCoords[x + z * (GetWidth()+1)].v = (float)((float)z/(GetWidth()+1)); } } //Create Indices for(int z = 0; z < GetLength()-1; z++) { //Even rows move left to right if(z % 2 == 0) { int x; for(x = 0; x < GetWidth(); x++) { m_Indices.push_back( x + (z * GetWidth()) ); m_Indices.push_back( x + (z * GetWidth()) + GetWidth() ); } if(z != GetLength() - 2 ) m_Indices.push_back( --x + (z * GetWidth()) ); } else { //odd rows move right to left int x; for(x = GetWidth() -1; x >= 0; x--) { m_Indices.push_back( x + (z * GetWidth()) ); m_Indices.push_back( x + (z * GetWidth()) + GetWidth() ); } if(z != GetLength() - 2 ) m_Indices.push_back( ++x + (z * GetWidth()) ); } } //Fill the buffers with data //VertexBuffer.setElementList(m_pVertices, m_nVertexCount); //TexCoordBuffer.setElementList(m_pTexCoords, m_nVertexCount); //...and calculate the Normals computeNormals(); //Buffers ready to bind! //NormalBuffer.build(GL_ARRAY_BUFFER, GL_NORMAL_ARRAY); //VertexBuffer.build(GL_ARRAY_BUFFER, GL_VERTEX_ARRAY); //TexCoordBuffer.build(GL_ARRAY_BUFFER, GL_TEXTURE_COORD_ARRAY); buildPatches(0); //delete [] m_pVertices; m_pVertices = NULL; //delete [] m_pTexCoords; m_pTexCoords = NULL; //delete [] m_pNormals; m_pNormals = NULL; }
long ImageLoader::GetBytesPerLine () { return getBytesRequired(GetWidth(), _myEncoding); }
void GeometryTerrain::computeLightmap(Vector3 _vlightSource, bool update) { bool bIntegrateNormals = false; std::vector<GLubyte> shadowMapTexture(GetWidth()*GetWidth()*4); float maxHeight = -99999.0f; for(int z =0; z <= GetLength(); ++z) for(int x = 0; x <= GetWidth(); ++x) maxHeight = max(getHeight(x,z), maxHeight); for(int z =0; z <= GetLength(); ++z) { for(int x = 0; x <= GetWidth(); ++x) { float ambientLight = 255; Ray lightRay(Vector3(x, getHeight(x, z), z), _vlightSource ); Vector3 current_ray_pos(Vector3(x, getHeight(x, z), z)); Vector3 direction_to_sun = lightRay.m_v3Direction.normalize(); int numRayHits = 0; while(!(current_ray_pos.x <= 0 || current_ray_pos.x >= GetWidth() || current_ray_pos.z <= 0 || current_ray_pos.z >= GetWidth() )) { if(current_ray_pos.y > maxHeight) break; // Is the terrain blocking the ray at this point? if(getHeight((int)floor(current_ray_pos.x), (int)floor(current_ray_pos.z)) > current_ray_pos.y) { numRayHits++; break; } //light still traveling... current_ray_pos += direction_to_sun; } float ambientLightNormals = 0; if(bIntegrateNormals) { Vector3 n( m_pNormals[x+z * (GetWidth()+1)].x, m_pNormals[x+z * (GetWidth()+1)].y, m_pNormals[x+z * (GetWidth()+1)].z ); ambientLightNormals = 0.5*( 1.0f + dot(n.normalize(), direction_to_sun) ); if(ambientLightNormals > 1.0f) ambientLightNormals = 1.0f; if(ambientLightNormals < 0.0f) ambientLightNormals = 0.0f; } if(numRayHits > 0) { //ambientLight = (current_ray_pos - Vector3(x,getHeight(x,z),z)).magnitude() - ambientLightNormals * 255; ambientLight = 170; if(ambientLight > 255) ambientLight = 255; if(ambientLight < 170) ambientLight = 170; } int index = (x + z * GetWidth()) * 3; for (int i = 0; i < 3; ++i) { shadowMapTexture[index + i] = (GLubyte)ambientLight; } } } for(int z =0; z <= GetLength(); ++z) { for(int x = 0; x <= GetWidth(); ++x) { int factor = 2; ColorOGL colCurrent; colCurrent.m_fRed = shadowMapTexture[(x + z * GetWidth()) * 3 + 0]; colCurrent.m_fGreen = shadowMapTexture[(x + z * GetWidth()) * 3 + 1]; colCurrent.m_fBlue = shadowMapTexture[(x + z * GetWidth()) * 3 + 2]; ColorOGL colT; ColorOGL colD; ColorOGL colL; ColorOGL colR; if(shadowMapTexture.size() > ((x + (z+factor) * GetWidth()) * 3 + 0) && shadowMapTexture.size() > ((x + (z+factor) * GetWidth()) * 3 + 1) && shadowMapTexture.size() > ((x + (z+factor) * GetWidth()) * 3 + 2) ) { colT.m_fRed = shadowMapTexture[(x + (z+factor) * GetWidth()) * 3 + 0]; colT.m_fGreen = shadowMapTexture[(x + (z+factor) * GetWidth()) * 3 + 1]; colT.m_fBlue = shadowMapTexture[(x + (z+factor) * GetWidth()) * 3 + 2]; } if(shadowMapTexture.size() > ((x + (z-factor) * GetWidth()) * 3 + 0) && shadowMapTexture.size() > ((x + (z-factor) * GetWidth()) * 3 + 1) && shadowMapTexture.size() > ((x + (z-factor) * GetWidth()) * 3 + 2) ) { colD.m_fRed = shadowMapTexture[(x + (z-factor) * GetWidth()) * 3 + 0]; colD.m_fGreen = shadowMapTexture[(x + (z-factor) * GetWidth()) * 3 + 1]; colD.m_fBlue = shadowMapTexture[(x + (z-factor) * GetWidth()) * 3 + 2]; } if(shadowMapTexture.size() > ( (x+factor + z * GetWidth()) * 3 + 0) && shadowMapTexture.size() > ((x+factor + z * GetWidth()) * 3 + 1) && shadowMapTexture.size() > ((x+factor + z * GetWidth()) * 3 + 2) ) { colL.m_fRed = shadowMapTexture[(x+factor + z * GetWidth()) * 3 + 0]; colL.m_fGreen = shadowMapTexture[(x+factor + z * GetWidth()) * 3 + 1]; colL.m_fBlue = shadowMapTexture[(x+factor + z * GetWidth()) * 3 + 2]; } if(shadowMapTexture.size() > (( x-factor + z * GetWidth()) * 3 + 0) && shadowMapTexture.size() > ((x-factor + z * GetWidth()) * 3 + 1) && shadowMapTexture.size() > ((x-factor + z * GetWidth()) * 3 + 2) ) { colR.m_fRed = shadowMapTexture[(x-factor + z * GetWidth()) * 3 + 0]; colR.m_fGreen = shadowMapTexture[(x-factor + z * GetWidth()) * 3 + 1]; colR.m_fBlue = shadowMapTexture[(x-factor + z * GetWidth()) * 3 + 2]; } shadowMapTexture[(x + z * GetWidth()) * 3 + 0] = (colT.m_fRed+colD.m_fRed+colR.m_fRed+colL.m_fRed+colCurrent.m_fRed)/5; shadowMapTexture[(x + z * GetWidth()) * 3 + 1] = (colT.m_fGreen+colD.m_fGreen+colR.m_fGreen+colL.m_fGreen+colCurrent.m_fGreen)/5; shadowMapTexture[(x + z * GetWidth()) * 3 + 2] = (colT.m_fBlue+colD.m_fBlue+colR.m_fBlue+colL.m_fBlue+colCurrent.m_fBlue)/5; } } if(update) { ResourceManager::getInstance()->getTexture2D("resources/textures/lightmap.tga")->bind(2); glTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, GetWidth(), GetWidth(), GL_RGBA, GL_UNSIGNED_BYTE, &shadowMapTexture[0]); } else { ilTexImage(GetWidth(),GetWidth(), 1, 3, IL_RGB, IL_UNSIGNED_BYTE, &shadowMapTexture[0]); ilSetData(&shadowMapTexture[0]); ilSetInteger(IL_IMAGE_BITS_PER_PIXEL,32); ilEnable(IL_FILE_OVERWRITE); ilSave(IL_TGA, "resources/textures/lightmap.tga"); } }
Vector3 GeometryTerrain::getNormal(int x, int z) { return Vector3(m_pNormals[x+z * (GetWidth()+1)].x,m_pNormals[x+z * (GetWidth()+1)].y,m_pNormals[x+z * (GetWidth()+1)].z); }
void CUIQuestRestore::ResetPosition( PIX pixMinI, PIX pixMinJ, PIX pixMaxI, PIX pixMaxJ ) { SetPos( ( pixMaxI + pixMinI - GetWidth() ) / 2 , ( pixMaxJ + pixMinJ - GetHeight() ) / 2 ); }
void CEarthBoss::Update(float fElapsedTime) { CEnemy::Update(fElapsedTime); if (m_pEState->GetState() == EntityState::DEAD) { return; } m_fUpdateOldPos += fElapsedTime; if(m_nCoolDown > 0) m_nCoolDown -= fElapsedTime; if( m_fPunchCoolDown > 0.0f && m_bPunching == true) m_fPunchCoolDown -= fElapsedTime; else { m_fPunchCoolDown = 2.5f; m_bPunching = false; } if (m_fSpecialTimer > 0.0f) m_fSpecialTimer -= fElapsedTime; else { CCreate_Rock_Fall_Message* pMsg = new CCreate_Rock_Fall_Message(); CSGD_MessageSystem::GetInstance()->SendMsg(pMsg); pMsg = nullptr; m_fSpecialTimer = 15.0f; } //if not rushing do basic path finding to the player if(GetTarget() != nullptr) { float tar_pos_x = GetTarget()->GetPosX(); float tar_pos_y = GetTarget()->GetPosY(); if(tar_pos_x > GetPosX()) { //set Grunt's animation's facing to the right SetFlipped(true); } else { SetFlipped(false); } if(m_fMoveAway <= 0) { // tar_pos_x += (m_bFlipped) ? -236 : 236; //Simple Pathing twards the player if(tar_pos_y != GetPosY())//Above the Player { float min_Distance = (float)(GetTarget()->GetWidth()/2 + GetWidth()/2); if(GetPosX() + min_Distance > tar_pos_x && GetPosX() - min_Distance < tar_pos_x) { if( tar_pos_x < GetPosX()) SetVelX(speed * fElapsedTime); else SetVelX(-speed * fElapsedTime); } else { if( tar_pos_y < GetPosY()) SetVelY(-speed * fElapsedTime); else SetVelY(speed * fElapsedTime); if( tar_pos_x < GetPosX()) SetVelX(-speed * fElapsedTime); else SetVelX(speed * fElapsedTime); if( tar_pos_x > (GetPosX() - 64) && tar_pos_x < (GetPosX() + 64) ) { if( tar_pos_y > (GetPosY() - 32) && tar_pos_y < (GetPosY() + 32) && m_bPunching == false) { GetAnimInfo()->SetAnimationName("Boss1_Attack_Animation"); m_bPunching = true; //dynamic_cast<CPlayer*>(GetTarget())->SetState(CEntityState::KNOCKED_DOWN); } } } } else { SetVelY(0); if( tar_pos_x < GetPosX()) SetVelX(-speed * fElapsedTime); else SetVelX(speed * fElapsedTime); } //if the player can be shot at. if(m_nCoolDown <= 0 && GetPosX() - tar_pos_x < 128 && GetPosX() - tar_pos_x > -128 ) { if(GetPosY() - tar_pos_y < 5 && GetPosY() - tar_pos_y > -5 && m_bPunching == false) { //GetAnimInfo()->SetAnimationName("Boss1_Shoot_Animation"); ////if in range rushing starts //CCreate_Projectile_Message* c_pProjectMSG = new CCreate_Projectile_Message(ENT_ENEMY, IsFlipped()); //c_pProjectMSG->SetPosX(this->GetPosX()); //c_pProjectMSG->SetPosY(this->GetPosY()); //CSGD_MessageSystem::GetInstance()->SendMsg(c_pProjectMSG); m_nCoolDown += 5; } } //stop 'bouncing' int threshold = 5; if(tar_pos_x - GetPosX() < threshold && tar_pos_x - GetPosX() > -1 * threshold) SetVelX(0); if(tar_pos_y - GetPosY() < threshold && tar_pos_y - GetPosY() > -1 * threshold) SetVelY(0); } else //update move away { m_fMoveAway -= fElapsedTime; if(m_bEvadeUp) SetVelY(-speed * fElapsedTime); else SetVelY(speed * fElapsedTime); } } //Check Colider if(TileManager::GetInstance()->CheckBlockedTiles(GetPosX(), GetPosY(), GetVelX(), 0)) { SetPosX(GetPosX() + GetVelX()); if(TileManager::GetInstance()->CheckBlockedTiles(GetPosX(), GetPosY(), 0, GetVelY())) { SetPosY(GetPosY() + GetVelY()); } } else { if( GetPosY() >= 600 ) SetPosY( (GetPosY() - (GetPosY() - 599)) ); else SetPosY(GetPosY() + 1); SetVelX(0); SetVelY(0); } if(GetPosX() < 0) SetPosX(0); //Set/use Move out of the way if(m_fUpdateOldPos >= 1.0f) { if(m_fPosXOld + 5 > GetPosX() && m_fPosXOld - 5 < GetPosX()) { if(m_fPosYOld + 5 > GetPosY() && m_fPosYOld - 5 < GetPosY()) { if(m_nCoolDown <= 0) { m_bEvadeUp = !m_bEvadeUp; if(m_fMoveAway <= 0) m_fMoveAway = 4.0f; } } } m_fPosXOld = GetPosX(); m_fPosYOld = GetPosY(); m_fUpdateOldPos = 0.0f; } }
void CTargetMenu::Update( POINT ptMouse ) { if( !IsVision()) return; CTDialog::Update( ptMouse ); if( m_iTargetAvatarID ) { CObjCHAR *pObj = (CObjCHAR*)g_pObjMGR->Get_CharOBJ( m_iTargetAvatarID, true ); /// 유효하지 않은 타겟이다.. 마우스 컴맨드 초기화 if( pObj == NULL ) { Hide(); } else { if( g_pAVATAR->Get_DISTANCE( pObj ) >= 1200 ) Hide(); else { D3DVECTOR PosSCR; POINT ptNew; pObj->GetScreenPOS (PosSCR); ptNew.x = (int)PosSCR.x - GetWidth() / 2; ptNew.y = (int)PosSCR.y - ( GetHeight() * 2 / 3 ); MoveWindow( ptNew ); } } } WINCTRL_LIST_ITOR iter; CWinCtrl* pCtrl; for( iter = m_listChild.begin(); iter != m_listChild.end(); ++iter) { pCtrl = *iter; if( pCtrl->GetControlType() == CTRL_IMAGE ) continue; if( pCtrl->IsInside(ptMouse.x, ptMouse.y ) ) { // g_itMGR.DrawToolTip( (short)ptMouse.x, (short)ptMouse.y, GetDialogType(), pCtrl->GetControlID()); break; } } /* int iTargetID = g_pAVATAR->m_iServerTarget; if( iTargetID ) { CObjCHAR *pObj = (CObjCHAR*)g_pObjMGR->Get_CharOBJ( g_CommandState.GetCurrentTarget(), true ); /// 유효하지 않은 타겟이다.. 마우스 컴맨드 초기화 if( pObj == NULL ) { g_CommandState.ClearMouseState(); Hide(); return; } ///Target이 아바타일경우에만 현재 스크린 좌표에 따라서 윈도우의 위치 조정 if( pObj->Get_TYPE() == OBJ_AVATAR ) { D3DVECTOR PosSCR; POINT ptNew; pObj->GetScreenPOS (PosSCR); ptNew.x = (int)PosSCR.x - GetWidth() / 2; ptNew.y = (int)PosSCR.y - ( GetHeight() * 2 / 3 ); MoveWindow( ptNew ); m_iTargetAvatarID = iTargetID; // Show(); } else { Hide(); } } else Hide(); */ }
void PlayScene::Start() { const auto fitsH = static_cast<int32_t>(std::ceil(static_cast<float>(GGame.GetWidth()) / kSpriteWidth)) + 1; const auto fitsV = static_cast<int32_t>(std::ceil(static_cast<float>(GGame.GetHeight()) / kSpriteOddYOffset)) + 1; _columns = fitsH; _rows = fitsV; SpriteParams params; params.persistant = false; params.texture = nullptr; params.z = 5; for (int32_t i = 0; i < kMap.size(); i++) { params.textureName = kMap[i]; auto sprite = GGame.Create<Sprite>(params); assert(kSpriteWidth == sprite->GetWidth()); assert(kSpriteHeight == sprite->GetHeight()); auto pos = VectorIndexToXY(i); sprite->SetCenterPosition(pos.first, pos.second); _backgroundSprites.push_back(sprite); } params.z = 6; params.textureName = "landingPlatform"; _landingPlatform = GGame.Create<Sprite>(params); auto pos = VectorIndexToXY(RowColumnToVectorIndex(3, 5)); _landingPlatform->SetCenterPosition(pos.first, pos.second); _landingPlatform->SetAlpha(0.0f); params.z = 7; params.textureName = "spaceCraft"; _spacecraft = GGame.Create<Sprite>(params); pos = VectorIndexToXY(RowColumnToVectorIndex(3, 5)); pos.first += kLandingOffset.first; pos.second += kLandingOffset.second - 150; _spacecraft->SetCenterPosition(pos.first, pos.second); ResourceBarParams resourceBarParams; resourceBarParams.persistant = false; resourceBarParams.initialWood = 150; resourceBarParams.initialCrystal = 20; resourceBarParams.z = 100; _resourceBar = GGame.Create<ResourceBar>(resourceBarParams); BuildingPanelParams buildingPanelParams; buildingPanelParams.persistant = false; buildingPanelParams.z = 100; _buildingPanel = GGame.Create<BuildingPanel>(buildingPanelParams); _buildingPanel->SetPosition(GGame.GetWidth() - _buildingPanel->GetWidth(), GGame.GetHeight()); _landingTimer = 0.0f; _landingFinished = false; _landingDestination = VectorIndexToXY(RowColumnToVectorIndex(3, 5)); _landingDestination.first += kLandingOffset.first; _landingDestination.second += kLandingOffset.second; _uiSlideTimer = 0.0f; _uiSlideFinished = false; }
// Returns true if given co-ordinate is in this area BOOL CSectionHandler::HasPoint(int iX,int iY) { return (iX>=m_iX && iY>=m_iY && iX<m_iX+GetWidth()+GetWidthOffset() && iY<m_iY+GetHeight()+GetHeightOffset()); }
//---------------------------------------------------------------------------- void ShadowMaps::CreateShaders () { // Create the shader constants. Some of these are shared. // Create the light projector. Projector* projector = new0 Projector(Camera::PM_DEPTH_ZERO_TO_ONE); projector->SetFrustum(60.0f, 1.0f, 0.1f, 100.0f); APoint projPosition(4.0f, 4.0f, 4.0f); AVector projDVector(-1.0f, -1.0f, -1.0f); projDVector.Normalize(); AVector projUVector(-1.0f, -1.0f, 2.0f); projUVector.Normalize(); AVector projRVector = projDVector.Cross(projUVector); projector->SetFrame(projPosition, projDVector, projUVector, projRVector); // For SMSceneEffect and SMUnlitEffect. ProjectorMatrixConstant* lightPVMatrix = new0 ProjectorMatrixConstant(projector, false, 0); ShaderFloat* lightBSMatrixUnlit = new0 ShaderFloat(4); ShaderFloat* lightBSMatrixScene = new0 ShaderFloat(4); ShaderFloat* screenBSMatrix = new0 ShaderFloat(4); const float* src; if (VertexShader::GetProfile() == VertexShader::VP_ARBVP1) { src = (const float*)Projector::BiasScaleMatrix[1]; memcpy(lightBSMatrixUnlit->GetData(), src, 16*sizeof(float)); memcpy(lightBSMatrixScene->GetData(), src, 16*sizeof(float)); memcpy(screenBSMatrix->GetData(), src, 16*sizeof(float)); } else { src = (const float*)Projector::BiasScaleMatrix[0]; memcpy(lightBSMatrixUnlit->GetData(), src, 16*sizeof(float)); memcpy(screenBSMatrix->GetData(), src, 16*sizeof(float)); src = (const float*)Projector::BiasScaleMatrix[1]; memcpy(lightBSMatrixScene->GetData(), src, 16*sizeof(float)); } // For SMSceneEffect. ProjectorWorldPositionConstant* lightWorldPosition = new0 ProjectorWorldPositionConstant(projector); ShaderFloat* lightColor = new0 ShaderFloat(1); (*lightColor)[0] = 1.0f; (*lightColor)[1] = 1.0f; (*lightColor)[2] = 1.0f; (*lightColor)[3] = 1.0f; // For SMUnlitEffect. ShaderFloat* depthBiasConstant = new0 ShaderFloat(1); (*depthBiasConstant)[0] = 0.1f; ShaderFloat* texelSizeConstant = new0 ShaderFloat(1); (*texelSizeConstant)[0] = 1.0f/(float)mScreenTargetSize; (*texelSizeConstant)[1] = 1.0f/(float)mScreenTargetSize; // For SMBlurEffect. const int numRegisters = 11; ShaderFloat* weights = new0 ShaderFloat(numRegisters); ShaderFloat* hOffsets = new0 ShaderFloat(numRegisters); ShaderFloat* vOffsets = new0 ShaderFloat(numRegisters); // Compute the weights. They must sum to 1. Float4* weightsData = (Float4*)weights->GetData(); const float stdDev = 1.0f; const float invTwoVariance = 1.0f/(2.0f*stdDev*stdDev); float totalWeight = 0.0f; int i, j; for (i = 0, j = -numRegisters/2; i < numRegisters; ++i, ++j) { float weight = Mathf::Exp(-j*j*invTwoVariance); weightsData[i] = Float4(weight, weight, weight, 0.0f); totalWeight += weight; } float invTotalWeight = 1.0f/totalWeight; for (i = 0; i < numRegisters; ++i) { weightsData[i][0] *= invTotalWeight; weightsData[i][1] *= invTotalWeight; weightsData[i][2] *= invTotalWeight; } // Compute the horizontal and vertical offsets. Float4* hOffsetsData = (Float4*)hOffsets->GetData(); Float4* vOffsetsData = (Float4*)vOffsets->GetData(); float uDelta = 1.0f/(float)GetWidth(); float vDelta = 1.0f/(float)GetHeight(); for (i = 0, j = -numRegisters/2; i < numRegisters; ++i, ++j) { hOffsetsData[i] = Float4(j*uDelta, 0.0f, 0.0f, 0.0f); vOffsetsData[i] = Float4(0.0f, j*vDelta, 0.0f, 0.0f); } // Create the scene effect. std::string effectFile = Environment::GetPathR("SMScene.wmfx"); SMSceneEffect* sceneEffect = new0 SMSceneEffect(effectFile); std::string stoneName = Environment::GetPathR("Stone.wmtf"); Texture2D* stoneTexture = Texture2D::LoadWMTF(stoneName); std::string ballName = Environment::GetPathR("BallTexture.wmtf"); Texture2D* ballTexture = Texture2D::LoadWMTF(ballName); std::string projectedName = Environment::GetPathR("Magician.wmtf"); Texture2D* projectedTexture = Texture2D::LoadWMTF(projectedName); mPlaneSceneInstance = sceneEffect->CreateInstance(lightWorldPosition, lightPVMatrix, lightBSMatrixScene, screenBSMatrix, lightColor, stoneTexture, mVBlurTarget->GetColorTexture(0), projectedTexture); mSphereSceneInstance = sceneEffect->CreateInstance(lightWorldPosition, lightPVMatrix, lightBSMatrixScene, screenBSMatrix, lightColor, ballTexture, mVBlurTarget->GetColorTexture(0), projectedTexture); // Create the shadow effect. effectFile = Environment::GetPathR("SMShadow.wmfx"); mShadowEffect = new0 SMShadowEffect(effectFile, lightPVMatrix); // Create the unlit effect. effectFile = Environment::GetPathR("SMUnlit.wmfx"); mUnlitEffect = new0 SMUnlitEffect(effectFile, lightPVMatrix, lightBSMatrixUnlit, depthBiasConstant, texelSizeConstant, mShadowTarget->GetColorTexture(0)); // Create the blur effect and instantiate for horizontal and vertical // blurring. effectFile = Environment::GetPathR("SMBlur.wmfx"); SMBlurEffect* blurEffect = new0 SMBlurEffect(effectFile); mHBlurInstance = blurEffect->CreateInstance(weights, hOffsets, mUnlitTarget->GetColorTexture(0)); mVBlurInstance = blurEffect->CreateInstance(weights, vOffsets, mHBlurTarget->GetColorTexture(0)); }
/* Automatic type deduction, and placement ----------------------------------------------------------------------------------------------------*/ void TableSystemWidget::Insert( Widget *pwidget ) { /* Try for IWTable interface ----------------------------------------------------------------------------------------------------*/ if ( IWTable *pi_tb = dynamic_cast<IWTable*>(pwidget) ) { TableWidget *ptw = &pi_tb->Table(); if ( _p_main_table ) { APP_ERROR( Error("Insert: Table allready exists"), "TableSystemWidget"); } _p_table_scroller->AttachWidget( (_p_main_table=pi_tb)->AtomPtr() ); _pri_tbl_width = pi_tb->Atom().GetWidth(); _pri_tbl_height= pi_tb->Atom().GetHeight(); pi_tb->Atom().OnResize.TieVoid( this, &TableSystemWidget::UpdateTableSizes ); if ( _p_caption_sizer ) { _p_caption_sizer->Atom().Posses( new ResizeRelation( _p_caption_sizer->Atom(), _p_main_table->Atom(), true, false ) ); } } /* Try for IWSizer interface ----------------------------------------------------------------------------------------------------*/ else if ( IWSizer *pi_siz = dynamic_cast<IWSizer *>(pwidget) ) { SizerWidget *psw = &pi_siz->Sizer(); if ( _p_caption_sizer ) { APP_ERROR( Error("Insert: Caption sizer allready exists"), "TableSystemWidget"); } _p_caption_scroller->AttachWidget( (_p_caption_sizer=pi_siz)->AtomPtr() ); _cs_height = _p_caption_sizer->Atom().GetHeight(); if ( _p_main_table ) { _p_caption_sizer->Atom().Posses( new ResizeRelation( _p_caption_sizer->Atom(), _p_main_table->Atom(), true, false ) ); } } /* Try for IWScrollbar interface ----------------------------------------------------------------------------------------------------*/ else if ( IWScrollbar *pi_sb = dynamic_cast<IWScrollbar*>(pwidget) ) { ScrollbarWidget *psbw = &pi_sb->Scroller(); if ( psbw->IsHorizontal() ) { if (_p_horiz_scrollbar ) { APP_ERROR( Error("Insert: H Scrollbar allready exists"), "TableSystemWidget"); } HubWidget::Insert( (_p_horiz_scrollbar = pi_sb)->AtomPtr() ); _sb_height = _p_horiz_scrollbar->Atom().GetHeight(); assert(_p_main_table); _p_table_scroller->Posses( new AdvScrollRelation( *_p_table_scroller, *_p_horiz_scrollbar, false ) ); _p_horiz_scrollbar->Atom().OnVisible.TieVoid( this, &TableSystemWidget::UpdateScrollbarSizes ); } else { if ( _p_verti_scrollbar ) { APP_ERROR( Error("Insert: V Scrollbar allready exists"), "TableSystemWidget"); } HubWidget::Insert( (_p_verti_scrollbar = pi_sb)->AtomPtr() ); _sb_width = _p_verti_scrollbar->Atom().GetWidth(); assert(_p_main_table); // if top gadget was inserted then relation type is disable-scrollbar relation if ( _p_top_gadget ) { _vertical_scroll_rel = new AdvScrollRelation2( *_p_table_scroller, *_p_verti_scrollbar, true ); _p_verti_scrollbar->Atom().Show(); } // else it is hide scrollbar-relation else { _vertical_scroll_rel = new AdvScrollRelation( *_p_table_scroller, *_p_verti_scrollbar, true ); } _p_verti_scrollbar->Atom().OnVisible.TieVoid( this, &TableSystemWidget::UpdateScrollbarSizes ); } } /* Check if it's supposed to be a surrounding frame ----------------------------------------------------------------------------------------------------*/ else if ( FrameWidget *pfw = dynamic_cast<FrameWidget*>(pwidget) ) { HubWidget::Retrieve( _p_table_scroller ); HubWidget::Retrieve( _p_caption_scroller ); HubWidget::Insert( _p_table_frame = pfw ); _p_table_frame->Insert( _p_table_scroller ); _p_table_frame->Insert( _p_caption_scroller ); } /* We can place two small gadgets ----------------------------------------------------------------------------------------------------*/ else if ( !_p_bottom_gadget ) { // if top gadget is beig inserted then change relation type to disable-scrollbar relation if (!_p_top_gadget && _p_verti_scrollbar) { assert( _vertical_scroll_rel.Unique() ); _vertical_scroll_rel = new AdvScrollRelation2( *_p_table_scroller, *_p_verti_scrollbar, true ); _p_verti_scrollbar->Atom().Show(); } HubWidget::Insert( (_p_top_gadget ? _p_bottom_gadget : _p_top_gadget) = pwidget, 0,0,0 ); } /* We don't know where to place this weird widget ----------------------------------------------------------------------------------------------------*/ else { APP_ERROR( Error("Insert: Wrong widget type"), "TableSystemWidget"); } Resize( GetWidth(), GetHeight() ); }
void TableSystemWidget::Fit() { int w = GetWidth(), h=GetHeight(); int sb_width = _sb_width; int sb_height = _sb_height; if (_p_verti_scrollbar && _p_verti_scrollbar->Atom().IsVisible() ) { _ResizePositive( _p_verti_scrollbar->AtomPtr(), sb_width, h-(_cs_height+sb_height) ); _p_verti_scrollbar->Atom().SetPosition ( Pos( w-sb_width, _cs_height) ); } if (_p_horiz_scrollbar && _p_horiz_scrollbar->Atom().IsVisible() ) { _ResizePositive( _p_horiz_scrollbar->AtomPtr(), w-sb_width, sb_height ); _p_horiz_scrollbar->Atom().SetPosition ( Pos( 0, h-sb_height ) ); } if (_p_table_frame) { int frame_w = w-sb_width; int frame_h = h-sb_height; _p_table_frame->Fill( Rect( 0, 0, frame_w, frame_h )); Rect c = _p_table_frame->GetClientRect( _p_caption_scroller ); _p_caption_scroller->Resize( c.GetW(), _cs_height ); _p_caption_scroller->SetPosition( c.GetPos() ); _ResizePositive( _p_table_scroller, c.GetW(), c.GetH()-_cs_height ); _p_table_scroller->SetPosition( c.GetPos() + Pos( 0, _cs_height) ); } else { if (_p_caption_scroller) { _p_caption_scroller->Resize( w-sb_width, _cs_height ); _p_caption_scroller->SetPosition( Pos(0,0) ); } if (_p_table_scroller) { _ResizePositive( _p_table_scroller, w-sb_width, h-(_cs_height+sb_height) ); _p_table_scroller->SetPosition ( Pos(0,_cs_height) ); } } if ( _p_top_gadget ) { _p_top_gadget->SetPosition( Pos( w-_p_top_gadget->GetWidth(), 0) ); HubWidget::BringOnTop( _p_top_gadget ); } if ( _p_bottom_gadget ) { if ( sb_width && sb_height ) { _p_bottom_gadget->SetPosition( Pos( w-sb_width, h-sb_height) ); if ( !_p_bottom_gadget->Atom().IsVisible() ) { _p_bottom_gadget->Atom().Show(); } } else if ( _p_bottom_gadget->Atom().IsVisible() ) { _p_bottom_gadget->Atom().Hide(); } } if ( _auto_cover ) { int pri_tbl_width = _pri_tbl_width; int pri_tbl_height= _pri_tbl_height; int table_w = pri_tbl_width; int table_h = pri_tbl_height; int client_w = _p_table_scroller->GetWidth(); int client_h = _p_table_scroller->GetHeight(); // try to cover all client area by table (if table is smaller than area) if ( client_w > table_w ) { _p_main_table->Atom().Resize( client_w, table_h ); } else if ( client_w < pri_tbl_width ) { _p_main_table->Atom().Resize( pri_tbl_width, table_h ); } table_w = _p_main_table->Atom().GetWidth(); if ( client_h > table_h ) { _p_main_table->Atom().Resize( table_w, client_h ); } else if ( client_h < pri_tbl_height ) { _p_main_table->Atom().Resize( table_w, pri_tbl_height ); } table_h = _p_main_table->Atom().GetHeight(); // right scrollbar dissappears only if top-gadget does not exist if ( !_p_top_gadget ) { // Check if full table would be visible if we hide both scrollbars bool would_fit_width = client_w + sb_width >= table_w; bool would_fit_height= client_h + sb_height >= table_h; if ( would_fit_width && would_fit_height ) { _p_main_table->Atom().Resize( client_w + sb_width, client_h + sb_height); _sb_width = _sb_height = 0; } } _pri_tbl_width = pri_tbl_width; _pri_tbl_height= pri_tbl_height; } // Make sure that scrollbar sizes have not been changed, and if so try again if ( _sb_width!=sb_width || _sb_height!=sb_height ) { Fit(); } }
void CopyOr(const Bitmap &src) { CopyOr(0, 0, GetWidth(), GetHeight(), src, 0, 0); }
void vfeDisplay::DrawPixel(unsigned int x, unsigned int y, const RGBA8& colour) { assert (x < GetWidth() && y < GetHeight()); m_Pixels[y * GetHeight() + x] = colour; }
void DiRenderWindow::OnDeviceReset() { if (mSceneManager) mSceneManager->GetCamera()->SetAspectRatio(float(GetWidth())/float(GetHeight())); }
void RabidEngine::OnIdle() { g_timer.Update(); const float dt = g_timer.GetTimeChange(); g_console->Update(dt); Transformation view; view.Rotate().FromEulerXYZ(cl_camrotx.GetFloat(), cl_camroty.GetFloat(), cl_camrotz.GetFloat()); // move const Vector3f forward = -view.Rotate().GetColumn(2); const Vector3f right = view.Rotate().GetColumn(0); const float vel = 50.0 * dt; if(keyState[B_FORWARD]) { cl_camx.SetFloat(cl_camx.GetFloat() + forward.x * vel); cl_camy.SetFloat(cl_camy.GetFloat() + forward.y * vel); cl_camz.SetFloat(cl_camz.GetFloat() + forward.z * vel); } if(keyState[B_BACKWARD]) { cl_camx.SetFloat(cl_camx.GetFloat() + -forward.x * vel); cl_camy.SetFloat(cl_camy.GetFloat() + -forward.y * vel); cl_camz.SetFloat(cl_camz.GetFloat() + -forward.z * vel); } if(keyState[B_RIGHT]) { cl_camx.SetFloat(cl_camx.GetFloat() + right.x * vel); cl_camy.SetFloat(cl_camy.GetFloat() + right.y * vel); cl_camz.SetFloat(cl_camz.GetFloat() + right.z * vel); } if(keyState[B_LEFT]) { cl_camx.SetFloat(cl_camx.GetFloat() + -right.x * vel); cl_camy.SetFloat(cl_camy.GetFloat() + -right.y * vel); cl_camz.SetFloat(cl_camz.GetFloat() + -right.z * vel); } if(keyState[B_RENDER]) { done.Set("0"); keyState[B_RENDER] = 0; } if(keyState[B_LIGHT_MODE]) { if(r_resid.GetBool()) r_resid.Set("0"); else r_resid.Set("1"); keyState[B_LIGHT_MODE] = 0; } if(keyState[B_TOGGLE_BRIGHTEST]) { if(r_showbrightest.GetBool()) r_showbrightest.Set("0"); else r_showbrightest.Set("1"); keyState[B_TOGGLE_BRIGHTEST] = 0; } static int pass; static int surf = -1; static int brightest; static int patches; if(done.GetBool()) { } else { if(pass == 0) { // clear accumulation buffers for(unsigned int i = 0; i < surfaces.Size(); i++) { // if(surfaces[i]->GetType() != S_LIGHT) // surfaces[i]->ClearAccum(); } } if(surf >= (int)surfaces.Size()) { surf = -2; pass++; done.Set("1"); } else if(surf == -1) { // Find Brightest Surface float maxPower = 0.0; for(unsigned int i = 0; i < surfaces.Size(); i++) { float p = surfaces[i]->GetPower(); if(p > maxPower) { brightest = i; maxPower = p; } } for(int i = 0; i < lights.Size(); i++) delete lights[i]; lights.Resize(0); surfaces[brightest]->CreateLights(lights); } else { Surface* lsurf = surfaces[surf]; bool skip = false; // lights can't receive light if(lsurf->GetType() == S_LIGHT) skip = true; // surface can light itself if(!skip && surf == brightest) { if(r_resid.GetBool()) lsurf->CopyResidualToLightMap(); skip = true; } if(!skip) { // Render each sub-light's contribution for(unsigned int l = 0; l < lights.Size(); l++) { Vector3f& p = lights[l]->p; Vector3f& d = lights[l]->d; float I = lights[l]->I; // light is on wrong side of surface if(Dot(p - lsurf->c, lsurf->N) < 0.1) continue; g_renderer->SetLight(0, p.x, p.y, p.z); g_renderer->SetLightDir(0, d.x, d.y, d.z); g_renderer->SetLightIntensity(0, I); g_renderer->SetLightFraction(0, 1.0 / (float)lights.Size()); lsurf->Frame(p); lsurf->CreateLightMap(p, d, surfaces); lsurf->AccumulateResidualLight(); lsurf->AccumulateLight(); g_renderer->SetViewMatrix(0); patches += lsurf->GetNumPatches(); } r_resid.Set(r_resid.GetBool() ? "1" : "0"); } } surf++; } if(r_resid.Changed()) { for(int i = 0; i < surfaces.Size(); i++) { Surface* lsurf = surfaces[i]; lsurf->Frame(lsurf->c + lsurf->N*10.0); if(r_resid.GetBool()) lsurf->CopyResidualToLightMap(); else lsurf->CopyAccumToLightMap(); } } // Render normal view view.Translate() = Vector3f(cl_camx.GetFloat(), cl_camy.GetFloat(), cl_camz.GetFloat()); view = view.Inverse(); g_renderer->SetViewport(0,0, GetWidth(),GetHeight()); g_renderer->SetViewMatrix(view); g_renderer->SetProjectionMatrix(0); g_renderer->SetClearColor(0.25f, 0.25f, 0.35f, 1.0f); g_renderer->BindMaterial(0); g_renderer->Clear(R_COLOR_BUFFER | R_DEPTH_BUFFER); g_renderer->SetColor(1,1,1); int bsurf = 0; float maxPower = 0.0; for(unsigned int i = 0; i < surfaces.Size(); i++) { float p = surfaces[i]->GetPower(); if(p > maxPower) { bsurf = i; maxPower = p; } } // draw all surfaces normally for(unsigned int i = 0; i < surfaces.Size(); i++) { if(r_showbrightest.GetBool()) { if(i == bsurf) g_renderDevice->SetColor(1.0, 1.0, 0.7); else g_renderDevice->SetColor(1,1,1); } surfaces[i]->Render(); } g_console->Draw(g_renderer); g_renderer->DrawTextP(15, 50, 16, r_resid.GetBool() ? "Residual" : "Accumulation"); g_renderer->DrawTextP(15, 30, 16, "Step: %d", pass); g_renderer->DrawTextP(15, 10, 16, "Patches: %d", patches); g_materialSystem->BindMaterial(logo); g_renderer->DrawRect(GetWidth()-200, 0, 200, 50, 0,0,1,1); g_renderer->Flip(); }
void Canvas::Copy(const Canvas &src, int src_x, int src_y) { Copy(0, 0, GetWidth(), GetHeight(), src, src_x, src_y); }
void CUIQuestRestore::AdjustPosition( PIX pixMinI, PIX pixMinJ, PIX pixMaxI, PIX pixMaxJ ) { if( m_nPosX < pixMinI || m_nPosX + GetWidth() > pixMaxI || m_nPosY < pixMinJ || m_nPosY + GetHeight() > pixMaxJ ) ResetPosition( pixMinI, pixMinJ, pixMaxI, pixMaxJ ); }
static void RB_GLSL_SubmitDrawInteractions(const viewLight_t& vLight, const InteractionList& interactionList) { if (interactionList.IsEmpty()) return; // perform setup here that will be constant for all interactions GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHMASK | backEnd.depthFunc ); GL_UseProgram( interactionProgram ); fhRenderProgram::SetShading( r_shading.GetInteger() ); fhRenderProgram::SetSpecularExp( r_specularExp.GetFloat() ); fhRenderProgram::SetAmbientLight( vLight.lightDef->lightShader->IsAmbientLight() ? 1 : 0 ); if (vLight.lightDef->ShadowMode() == shadowMode_t::ShadowMap) { const idVec4 globalLightOrigin = idVec4( vLight.globalLightOrigin, 1 ); fhRenderProgram::SetGlobalLightOrigin( globalLightOrigin ); const float shadowBrightness = vLight.lightDef->ShadowBrightness(); const float shadowSoftness = vLight.lightDef->ShadowSoftness(); fhRenderProgram::SetShadowParams( idVec4( shadowSoftness, shadowBrightness, vLight.nearClip[0], vLight.farClip[0] ) ); if(vLight.lightDef->parms.parallel) { //parallel light fhRenderProgram::SetShadowMappingMode( 3 ); fhRenderProgram::SetPointLightProjectionMatrices( vLight.viewProjectionMatrices[0].ToFloatPtr() ); fhRenderProgram::SetShadowCoords( vLight.shadowCoords, 6 ); fhRenderProgram::SetCascadeDistances( r_smCascadeDistance0.GetFloat(), r_smCascadeDistance1.GetFloat(), r_smCascadeDistance2.GetFloat(), r_smCascadeDistance3.GetFloat(), r_smCascadeDistance4.GetFloat()); idVec4 shadowmapSizes[6] = { idVec4(vLight.nearClip[0], vLight.farClip[0], vLight.width[0], vLight.height[0]), idVec4(vLight.nearClip[1], vLight.farClip[1], vLight.width[1], vLight.height[1]), idVec4(vLight.nearClip[2], vLight.farClip[2], vLight.width[2], vLight.height[2]), idVec4(vLight.nearClip[3], vLight.farClip[3], vLight.width[3], vLight.height[3]), idVec4(vLight.nearClip[4], vLight.farClip[4], vLight.width[4], vLight.height[4]), idVec4(vLight.nearClip[5], vLight.farClip[5], vLight.width[5], vLight.height[5]) }; fhRenderProgram::SetShadowMapSize(shadowmapSizes, 6); } else if (vLight.lightDef->parms.pointLight) { //point light fhRenderProgram::SetShadowMappingMode( 1 ); fhRenderProgram::SetPointLightProjectionMatrices( vLight.viewProjectionMatrices[0].ToFloatPtr() ); fhRenderProgram::SetShadowCoords(vLight.shadowCoords, 6); { const idMat3 axis = vLight.lightDef->parms.axis; float viewerMatrix[16]; viewerMatrix[0] = axis[0][0]; viewerMatrix[4] = axis[0][1]; viewerMatrix[8] = axis[0][2]; viewerMatrix[12] = 0; viewerMatrix[1] = axis[1][0]; viewerMatrix[5] = axis[1][1]; viewerMatrix[9] = axis[1][2]; viewerMatrix[13] = 0; viewerMatrix[2] = axis[2][0]; viewerMatrix[6] = axis[2][1]; viewerMatrix[10] = axis[2][2]; viewerMatrix[14] = 0; viewerMatrix[3] = 0; viewerMatrix[7] = 0; viewerMatrix[11] = 0; viewerMatrix[15] = 1; fhRenderProgram::SetInverseLightRotation( viewerMatrix ); } } else { //projected light fhRenderProgram::SetShadowMappingMode( 2 ); fhRenderProgram::SetSpotLightProjectionMatrix( vLight.viewProjectionMatrices[0].ToFloatPtr() ); fhRenderProgram::SetShadowCoords(vLight.shadowCoords, 1); } } else { //no shadows fhRenderProgram::SetShadowMappingMode( 0 ); } //make sure depth hacks are disabled //FIXME(johl): why is (sometimes) a depth hack enabled at this point? RB_LeaveDepthHack(); fhRenderProgram::SetProjectionMatrix( backEnd.viewDef->projectionMatrix ); fhRenderProgram::SetPomMaxHeight( -1 ); const viewEntity_t* currentSpace = nullptr; stageVertexColor_t currentVertexColor = (stageVertexColor_t)-1; bool currentPomEnabled = false; idScreenRect currentScissor; bool depthHackActive = false; bool currentHasBumpMatrix = false; bool currentHasDiffuseMatrix = false; bool currentHasSpecularMatrix = false; idVec4 currentDiffuseColor = idVec4( 1, 1, 1, 1 ); idVec4 currentSpecularColor = idVec4( 1, 1, 1, 1 ); fhRenderProgram::SetDiffuseColor( currentDiffuseColor ); fhRenderProgram::SetSpecularColor( currentSpecularColor ); fhRenderProgram::SetBumpMatrix( idVec4::identityS, idVec4::identityT ); fhRenderProgram::SetSpecularMatrix( idVec4::identityS, idVec4::identityT ); fhRenderProgram::SetDiffuseMatrix( idVec4::identityS, idVec4::identityT ); glDepthRange(0, 1); if (r_useScissor.GetBool()) { auto fb = fhFramebuffer::GetCurrentDrawBuffer(); glScissor( 0, 0, fb->GetWidth(), fb->GetHeight() ); currentScissor.x1 = 0; currentScissor.y1 = 0; currentScissor.x2 = fb->GetWidth(); currentScissor.y2 = fb->GetHeight(); } const int num = interactionList.Num(); for (int i = 0; i < num; ++i) { const auto& din = interactionList[i]; const auto offset = vertexCache.Bind( din.surf->geo->ambientCache ); GL_SetupVertexAttributes( fhVertexLayout::Draw, offset ); if (currentSpace != din.surf->space) { fhRenderProgram::SetModelMatrix( din.surf->space->modelMatrix ); fhRenderProgram::SetModelViewMatrix( din.surf->space->modelViewMatrix ); if (din.surf->space->modelDepthHack) { RB_EnterModelDepthHack( din.surf->space->modelDepthHack ); fhRenderProgram::SetProjectionMatrix( GL_ProjectionMatrix.Top() ); depthHackActive = true; } else if (din.surf->space->weaponDepthHack) { RB_EnterWeaponDepthHack(); fhRenderProgram::SetProjectionMatrix( GL_ProjectionMatrix.Top() ); depthHackActive = true; } else if (depthHackActive) { RB_LeaveDepthHack(); fhRenderProgram::SetProjectionMatrix( GL_ProjectionMatrix.Top() ); depthHackActive = false; } // change the scissor if needed if (r_useScissor.GetBool() && !currentScissor.Equals( din.surf->scissorRect )) { currentScissor = din.surf->scissorRect; glScissor( backEnd.viewDef->viewport.x1 + currentScissor.x1, backEnd.viewDef->viewport.y1 + currentScissor.y1, currentScissor.x2 + 1 - currentScissor.x1, currentScissor.y2 + 1 - currentScissor.y1 ); } currentSpace = din.surf->space; } fhRenderProgram::SetLocalLightOrigin( din.localLightOrigin ); fhRenderProgram::SetLocalViewOrigin( din.localViewOrigin ); fhRenderProgram::SetLightProjectionMatrix( din.lightProjection[0], din.lightProjection[1], din.lightProjection[2] ); fhRenderProgram::SetLightFallOff( din.lightProjection[3] ); if (din.hasBumpMatrix) { fhRenderProgram::SetBumpMatrix( din.bumpMatrix[0], din.bumpMatrix[1] ); currentHasBumpMatrix = true; } else if (currentHasBumpMatrix) { fhRenderProgram::SetBumpMatrix( idVec4::identityS, idVec4::identityT ); currentHasBumpMatrix = false; } if (din.hasDiffuseMatrix) { fhRenderProgram::SetDiffuseMatrix( din.diffuseMatrix[0], din.diffuseMatrix[1] ); currentHasDiffuseMatrix = true; } else if (currentHasDiffuseMatrix) { fhRenderProgram::SetDiffuseMatrix( idVec4::identityS, idVec4::identityT ); currentHasDiffuseMatrix = false; } if (din.hasSpecularMatrix) { fhRenderProgram::SetSpecularMatrix( din.specularMatrix[0], din.specularMatrix[1] ); currentHasSpecularMatrix = true; } else if (currentHasSpecularMatrix) { fhRenderProgram::SetSpecularMatrix( idVec4::identityS, idVec4::identityT ); currentHasSpecularMatrix = false; } if (currentVertexColor != din.vertexColor) { switch (din.vertexColor) { case SVC_IGNORE: fhRenderProgram::SetColorModulate( idVec4::zero ); fhRenderProgram::SetColorAdd( idVec4::one ); break; case SVC_MODULATE: fhRenderProgram::SetColorModulate( idVec4::one ); fhRenderProgram::SetColorAdd( idVec4::zero ); break; case SVC_INVERSE_MODULATE: fhRenderProgram::SetColorModulate( idVec4::negOne ); fhRenderProgram::SetColorAdd( idVec4::one ); break; } currentVertexColor = din.vertexColor; } if (din.diffuseColor != currentDiffuseColor) { fhRenderProgram::SetDiffuseColor( din.diffuseColor ); currentDiffuseColor = din.diffuseColor; } if (din.specularColor != currentSpecularColor) { fhRenderProgram::SetSpecularColor( din.specularColor ); currentSpecularColor = din.specularColor; } const bool pomEnabled = r_pomEnabled.GetBool() && din.specularImage->hasAlpha; if (pomEnabled != currentPomEnabled) { if (pomEnabled) { fhRenderProgram::SetPomMaxHeight( r_pomMaxHeight.GetFloat() ); } else { fhRenderProgram::SetPomMaxHeight( -1 ); } } fhRenderProgram::SetNormalMapEncoding( RB_GetNormalEncoding( din.bumpImage ) ); din.bumpImage->Bind( 1 ); din.lightFalloffImage->Bind( 2 ); din.lightImage->Bind( 3 ); din.diffuseImage->Bind( 4 ); din.specularImage->Bind( 5 ); // draw it backEnd.stats.groups[backEndGroup::Interaction].drawcalls += 1; backEnd.stats.groups[backEndGroup::Interaction].tris += din.surf->geo->numIndexes / 3; RB_DrawElementsWithCounters( din.surf->geo ); } if (depthHackActive) { RB_LeaveDepthHack(); fhRenderProgram::SetProjectionMatrix( GL_ProjectionMatrix.Top() ); } if (r_useScissor.GetBool()) { auto fb = fhFramebuffer::GetCurrentDrawBuffer(); glScissor( 0, 0, fb->GetWidth(), fb->GetHeight() ); backEnd.currentScissor.x1 = 0; backEnd.currentScissor.y1 = 0; backEnd.currentScissor.x2 = fb->GetWidth(); backEnd.currentScissor.y2 = fb->GetHeight(); } }
void Brush::Send() { if (m_IsActive) POST_MESSAGE(Brush, (GetWidth(), GetHeight(), GetData())); }
#ifdef __WXGTK__ EVT_WINDOW_CREATE(frmSplash::OnWindowCreate) #endif END_EVENT_TABLE() frmSplash::frmSplash(wxFrame *parent) #ifndef __WXDEBUG__ : wxFrame((wxFrame *)NULL, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(100, 100), 0 | wxFRAME_SHAPED | wxSIMPLE_BORDER | wxFRAME_NO_TASKBAR | wxSTAY_ON_TOP) #else : wxFrame((wxFrame *)NULL, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(100, 100), 0 | wxFRAME_SHAPED | wxSIMPLE_BORDER | wxFRAME_NO_TASKBAR) #endif { appearanceFactory->SetIcons(this); splash = appearanceFactory->GetSplashImage(); SetClientSize(splash.GetWidth(), splash.GetHeight()); #ifndef __WXGTK__ SetWindowShape(); #endif CenterOnScreen(); } void frmSplash::SetWindowShape() { wxRegion region(splash); SetShape(region); } void frmSplash::OnPaint(wxPaintEvent &WXUNUSED(event))
void GeometryTerrain::setHeight(int x, int z, float y) { if(x <= (GetWidth()+1) && z <= (GetWidth()+1) && x >= 0 && z >= 0) m_pHeight[z][x] = y; }
bool HierarchyTreePlatformNode::Save(YamlNode* node, bool saveAll) { YamlNode* platform = new YamlNode(YamlNode::TYPE_MAP); platform->Set(WIDTH_NODE, GetWidth()); platform->Set(HEIGHT_NODE, GetHeight()); MultiMap<String, YamlNode*> &platformsMap = node->AsMap(); platformsMap.erase(GetName().toStdString()); platformsMap.insert(std::pair<String, YamlNode*>(GetName().toStdString(), platform)); ActivatePlatform(); MultiMap<String, YamlNode*> &platformMap = platform->AsMap(); YamlNode* screens = new YamlNode(YamlNode::TYPE_ARRAY); platformMap.erase(SCREENS_NODE); platformMap.insert(std::pair<String, YamlNode*>(SCREENS_NODE, screens)); YamlNode* aggregators = new YamlNode(YamlNode::TYPE_MAP); platformMap.erase(AGGREGATORS_NODE); platformMap.insert(std::pair<String, YamlNode*>(AGGREGATORS_NODE, aggregators)); // Add the Localization info - specific for each Platform. SaveLocalization(platform); QString platformFolder = GetPlatformFolder(); QDir dir; dir.mkpath(platformFolder); bool result = true; //save aggregators node before save screens for (HIERARCHYTREENODESCONSTITER iter = GetChildNodes().begin(); iter != GetChildNodes().end(); ++iter) { HierarchyTreeAggregatorNode* node = dynamic_cast<HierarchyTreeAggregatorNode*>(*iter); if (!node) continue; QString path = QString(SCREEN_PATH).arg(platformFolder).arg(node->GetName()); MultiMap<String, YamlNode*> &aggregatorsMap = aggregators->AsMap(); YamlNode* aggregator = new YamlNode(YamlNode::TYPE_MAP); result &= node->Save(aggregator, path, saveAll); aggregatorsMap.erase(node->GetName().toStdString()); aggregatorsMap.insert(std::pair<String, YamlNode*>(node->GetName().toStdString(), aggregator)); } for (HIERARCHYTREENODESCONSTITER iter = GetChildNodes().begin(); iter != GetChildNodes().end(); ++iter) { HierarchyTreeAggregatorNode* node = dynamic_cast<HierarchyTreeAggregatorNode*>(*iter); if (node) continue; //skip aggregators HierarchyTreeScreenNode* screenNode = dynamic_cast<HierarchyTreeScreenNode*>(*iter); if (!screenNode) continue; QString screenPath = QString(SCREEN_PATH).arg(platformFolder).arg(screenNode->GetName()); result &= screenNode->Save(screenPath, saveAll); screens->AddValueToArray(screenNode->GetName().toStdString()); } return result; }
void GeometryTerrain::computeNormals() { for(unsigned int z = 0; z < (GetWidth()+1)-1; ++z) { for(unsigned int x = 0; x < (GetWidth()+1); ++x) { Vector3 sum(0.0f, 0.0f, 0.0f); Vector3 out; if (z > 0) { out = Vector3(0.0f, m_pHeight[z - 1][x] - m_pHeight[z][x], -1.0f); } Vector3 in; if (z < (GetWidth()+1) - 1) { in = Vector3(0.0f, m_pHeight[z + 1][x] - m_pHeight[z][x], 1.0f); } Vector3 left; if (x > 0) { left = Vector3(-1.0f, m_pHeight[z][x - 1] - m_pHeight[z][x], 0.0f); } Vector3 right; if (x < (GetWidth()+1) - 1) { right = Vector3(1.0f, m_pHeight[z][x + 1] - m_pHeight[z][x], 0.0f); } if (x > 0 && z > 0) { sum += out.cross(left); } if (x > 0 && z < (GetWidth()+1) - 1) { sum += left.cross(in); } if (x < (GetWidth()+1) - 1 && z < (GetWidth()+1) - 1) { sum += in.cross(right); } if (x < (GetWidth()+1) - 1 && z > 0) { sum += right.cross(out); } m_pNormals[x+z * (GetWidth()+1)].x = sum.x; m_pNormals[x+z * (GetWidth()+1)].y = sum.y; m_pNormals[x+z * (GetWidth()+1)].z = sum.z; } } //Fill the Normal Buffer with Data NormalBuffer.setElementList(m_pNormals, m_nVertexCount); }
void CLCDProgressBar::OnDraw(CLCDGfx &rGfx) { HPEN hOldPen; rGfx.ClearScreen(); // draw the border RECT r = { 0, 0, GetWidth(), GetHeight() }; FrameRect(rGfx.GetHDC(), &r, m_hBrush); // draw the progress switch(m_eStyle) { case STYLE_CURSOR: { int nCursorPos = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax, (float)1, (float)(GetWidth() - m_nCursorWidth-1), m_Pos); r.left = nCursorPos; r.right = r.left + m_nCursorWidth; FillRect(rGfx.GetHDC(), &r, m_hBrush); } break; case STYLE_FILLED_V: case STYLE_FILLED_H: { int nBar = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax, 0.0f, (m_eStyle == STYLE_FILLED_H ? (float)GetWidth() : (float)GetHeight())-4, m_Pos); r.left = r.left+2; r.bottom = r.bottom-2; if (m_eStyle == STYLE_FILLED_H) { r.right = nBar+2; r.top = r.top+2; } else { r.right = r.right-2; r.top = r.bottom-nBar; } FillRect(rGfx.GetHDC(), &r, m_hBrush); } break; case STYLE_DASHED_CURSOR: { int nCursorPos = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax, (float)1, (float)(GetWidth() - m_nCursorWidth-1), m_Pos); r.left = nCursorPos; r.right = r.left + m_nCursorWidth; FillRect(rGfx.GetHDC(), &r, m_hBrush); hOldPen = (HPEN)::SelectObject(rGfx.GetHDC(), m_hPen); ::MoveToEx(rGfx.GetHDC(), 0, (r.bottom - r.top)/2, NULL); ::LineTo(rGfx.GetHDC(), nCursorPos, (r.bottom - r.top)/2); ::SelectObject(rGfx.GetHDC(), hOldPen); } break; default: break; } }
void GeometryTerrain::buildPatches(bool update) { int currentPatchIndex = 0; //Iterate through the base grid and divide it into chunks for(unsigned int patchZ = 0; patchZ < GetWidth(); patchZ += m_patchSize) { for(unsigned int patchX = 0; patchX < GetWidth(); patchX += m_patchSize) { TerrainPatch new_patch; new_patch.m_vertexCount = (m_patchSize+1)*(m_patchSize+1); flx_Vertex *patchVertices = new flx_Vertex[new_patch.m_vertexCount]; flx_TexCoord *patchTexCoords = new flx_TexCoord[new_patch.m_vertexCount]; flx_Normal *patchNormals = new flx_Normal[new_patch.m_vertexCount]; Vector3 tmax = Vector3(-999999,-999999,-999999); Vector3 tmin = Vector3(999999,999999,999999); //Fill vertex, texcoord and normal arrays for their buffers for(unsigned int z = 0; z < m_patchSize+1; ++z) { unsigned int x; for(x = 0; x < m_patchSize+1; ++x) { patchVertices[x + z * (m_patchSize+1)].x = m_pVertices[(x + patchX) + (z + patchZ) * (GetWidth()+1)].x; patchVertices[x + z * (m_patchSize+1)].y = m_pVertices[(x + patchX) + (z + patchZ) * (GetWidth()+1)].y; patchVertices[x + z * (m_patchSize+1)].z = m_pVertices[(x + patchX) + (z + patchZ) * (GetWidth()+1)].z; if(!update) { patchTexCoords[x + z * (m_patchSize+1)].u = (float)((float)((x + patchX) * m_fOffsetX) / (GetWidth()+1)); patchTexCoords[x + z * (m_patchSize+1)].v = (float)((float)((z + patchZ) * m_fOffsetZ) / (GetWidth()+1)); } patchNormals[x + z * (m_patchSize+1)].x = m_pNormals[(x + patchX) + (z + patchZ) * (GetWidth()+1)].x; patchNormals[x + z * (m_patchSize+1)].y = m_pNormals[(x + patchX) + (z + patchZ) * (GetWidth()+1)].y; patchNormals[x + z * (m_patchSize+1)].z = m_pNormals[(x + patchX) + (z + patchZ) * (GetWidth()+1)].z; //Find the corners for the AABB tmin.x = min(patchVertices[x + z * (m_patchSize+1)].x, tmin.x); tmin.y = min(patchVertices[x + z * (m_patchSize+1)].y, tmin.y); tmin.z = min(patchVertices[x + z * (m_patchSize+1)].z, tmin.z); tmax.x = max(patchVertices[x + z * (m_patchSize+1)].x, tmax.x); tmax.y = max(patchVertices[x + z * (m_patchSize+1)].y, tmax.y); tmax.z = max(patchVertices[x + z * (m_patchSize+1)].z, tmax.z); } } //Set the corners of AABB new_patch.m_aabb.vecMax = tmax; new_patch.m_aabb.vecMin = tmin; //Create the indices and degenerates unsigned int nvert = m_patchSize+1; int z; if(!update) { for(int lod_level = 1; lod_level <= 1; ++lod_level) { int offset = lod_level; for(z = 0; z < nvert-1; z++) { if(z % 2) { //move right to left int x; for(x = nvert-1; x > 0; x--) { new_patch.m_Indices[lod_level-1].push_back(x + (z + 1) * nvert); new_patch.m_Indices[lod_level-1].push_back(x + (z ) * nvert -1); } //put in some degenerates new_patch.m_Indices[lod_level-1].push_back( (z + 1) * nvert ); new_patch.m_Indices[lod_level-1].push_back( (z + 1) * nvert ); } else { //move from the left to the right int x; for(x = 0; x < nvert; x++) { new_patch.m_Indices[lod_level-1].push_back(x + (z ) * nvert ); new_patch.m_Indices[lod_level-1].push_back(x + (z + 1) * nvert ); } //put in some degenerates new_patch.m_Indices[lod_level-1].push_back( (z + 2) * nvert - 1 ); new_patch.m_Indices[lod_level-1].push_back( (z + 2) * nvert - 1 ); } } } } //new_patch.m_Indices.push_back(new_patch.m_Indices[new_patch.m_Indices.size()-1]); //Tell the buffers to use the data we've just created if(!update) { new_patch.VertexBuffer.setElementList(patchVertices, new_patch.m_vertexCount); new_patch.TexCoordBuffer.setElementList(patchTexCoords, new_patch.m_vertexCount); new_patch.NormalBuffer.setElementList(patchNormals, new_patch.m_vertexCount); new_patch.VertexBuffer.build(GL_ARRAY_BUFFER, GL_VERTEX_ARRAY); new_patch.TexCoordBuffer.build(GL_ARRAY_BUFFER, GL_TEXTURE_COORD_ARRAY); new_patch.NormalBuffer.build(GL_ARRAY_BUFFER, GL_NORMAL_ARRAY); } if(update) { m_vTerrainPatches[currentPatchIndex].m_aabb = new_patch.m_aabb; m_vTerrainPatches[currentPatchIndex].VertexBuffer.update(patchVertices, new_patch.m_vertexCount); m_vTerrainPatches[currentPatchIndex].NormalBuffer.update(patchNormals, new_patch.m_vertexCount); } if(!update) m_vTerrainPatches.push_back(new_patch); //Get back my memory! We don't use those arrays anymore... delete [] patchVertices; patchVertices = NULL; delete [] patchTexCoords; patchTexCoords = NULL; delete [] patchNormals; patchNormals = NULL; currentPatchIndex++; } } }
void vfeDisplay::Initialise() { m_Pixels.clear(); m_Pixels.resize(GetWidth() * GetHeight()); }
void ImageLoader::ensurePowerOfTwo(const std::string & theResizeMode, unsigned theDepth, const asl::Vector2i * theTile) { // limit texture size int myTextureSizeLimit = 0; if (asl::Ptr<ITextureManager> myTextureManager = _myTextureManager.lock()) { myTextureSizeLimit = myTextureManager->getMaxTextureSize( theDepth = 1 ? 2 : 3 ); AC_INFO << "Texture size limit set to " << myTextureSizeLimit; } else { myTextureSizeLimit = ITextureManager::getTextureSizeLimit(); } AC_DEBUG << "Texture size limit = " << myTextureSizeLimit; if (theResizeMode == IMAGE_RESIZE_NONE && (!myTextureSizeLimit || (GetWidth() <= myTextureSizeLimit && GetHeight() <= myTextureSizeLimit))) { return; } if (!powerOfTwo(theDepth)) { throw ImageLoaderException( string("ensurePowerOfTwo: third dimension (depth) must be power of two for now"), PLUS_FILE_LINE); } bool myIsCubemapFlag = false; if (theTile) { unsigned myNumTiles = (*theTile)[0] * (*theTile)[1]; myIsCubemapFlag = (myNumTiles == 6 ? true : false); } try { int myWidthFactor = 1, myHeightFactor = theDepth; if (myIsCubemapFlag) { myWidthFactor *= (*theTile)[0]; myHeightFactor *= (*theTile)[1]; AC_DEBUG << "tile=" << *theTile << " factor=" << myWidthFactor << "x" << myHeightFactor << " size=" << GetWidth() << "x" << GetHeight(); } unsigned myPreScaleWidth = GetWidth(); unsigned myPreScaleHeight = GetHeight(); if ((myPreScaleWidth % myWidthFactor) != 0) { throw ImageLoaderException( string("ensurePowerOfTwo: '" + _myFilename + "' texture strip width must be a multiple of ")+ as_string(myWidthFactor), PLUS_FILE_LINE); } if ((myPreScaleHeight % myHeightFactor) != 0) { throw ImageLoaderException( string("ensurePowerOfTwo: '" + _myFilename + "' texture strip height must be a multiple of ")+ as_string(myHeightFactor), PLUS_FILE_LINE); } AC_DEBUG << "GetWidth() = " << GetWidth(); AC_DEBUG << "GetHeight() = " << GetHeight(); AC_DEBUG << "myWidthFactor = " << myWidthFactor; AC_DEBUG << "myHeightFactor = " << myHeightFactor; int myTargetWidth = GetWidth(); int myTargetHeight = GetHeight(); if (!powerOfTwo(GetWidth() / myWidthFactor) || !powerOfTwo(GetHeight() / myHeightFactor)) { myTargetWidth = nextPowerOfTwo(GetWidth() / myWidthFactor) * myWidthFactor; myTargetHeight = nextPowerOfTwo(GetHeight() / myHeightFactor) * myHeightFactor; } AC_DEBUG << "myTargetWidth = " << myTargetWidth; AC_DEBUG << "myTargetHeight = " << myTargetHeight; while (myTextureSizeLimit && ((myTargetWidth / myWidthFactor) > myTextureSizeLimit || (myTargetHeight / myHeightFactor) > myTextureSizeLimit) ) { myTargetWidth = (myTargetWidth / myWidthFactor)/2 * myWidthFactor; myTargetHeight = (myTargetHeight / myHeightFactor)/2 * myHeightFactor; } AC_DEBUG << "GetWidth() = " << myTargetWidth; AC_DEBUG << "GetHeight() = " << myTargetHeight; AC_DEBUG << "myTargetWidth = " << myTargetWidth; AC_DEBUG << "myTargetHeight = " << myTargetHeight; if (myTextureSizeLimit && (myTargetWidth != GetWidth() || myTargetHeight != GetHeight())) { AC_WARNING << "Texture size exceeds "<<Y60_TEXTURE_SIZE_LIMIT_ENV<<"="<< myTextureSizeLimit<<", resizing to "<< myTargetWidth<<"x"<<myTargetHeight<<endl; ApplyFilter(PLFilterResizeBilinear(myTargetWidth, myTargetHeight)); } if (!powerOfTwo(GetWidth() / myWidthFactor) || !powerOfTwo(GetHeight() / myHeightFactor)) { unsigned myWidth = nextPowerOfTwo(GetWidth() / myWidthFactor) * myWidthFactor; unsigned myHeight = nextPowerOfTwo(GetHeight() / myHeightFactor) * myHeightFactor; if (theResizeMode == IMAGE_RESIZE_SCALE) { AC_INFO << "Resizing bitmap " << _myFilename << " to next power of two: " << myWidth << "x" << myHeight << "."; ApplyFilter(PLFilterResizeBilinear(myWidth, myHeight)); } else if (theResizeMode == IMAGE_RESIZE_PAD) { //TODO: make padding for for cube maps and 3D texture strips AC_INFO << "Padding bitmap '" << _myFilename << "' to next power of two: " << myWidth << "x" << myHeight << "."; ApplyFilter(PLFilterResizePadded(myWidth, myHeight)); _myImageMatrix.scale(Vector3f(float(myPreScaleWidth) / GetWidth(), float(myPreScaleHeight) / GetHeight(), 1.0f)); } else { throw ImageLoaderException(string("ensurePowerOfTwo: Unknown resize mode: ") + theResizeMode, PLUS_FILE_LINE); } } // convert paletted textures } catch (PLTextException & ex) { throw ImageLoaderException(std::string("Paintlib exception ")+std::string(ex), PLUS_FILE_LINE); } }
void Clear(const Brush &brush) { DrawFilledRectangle(0, 0, GetWidth(), GetHeight(), brush); }