void D3D7Canvas::DrawBitmap(Bitmap & bmp_info, const Rect & dest) { if (NULL == back_buffer_) return; HRESULT hr = device7_->SetRenderTarget(back_buffer_, 0); if(FAILED(hr)) return; DDSURFACEDESC2 surfaceDesc; ::ZeroMemory(&surfaceDesc, sizeof(surfaceDesc)); surfaceDesc.dwSize = sizeof(surfaceDesc); back_buffer_->GetSurfaceDesc(&surfaceDesc); D3DVIEWPORT7 port = {0, 0, surfaceDesc.dwWidth, surfaceDesc.dwHeight, 0.0f, 1.0f}; hr = device7_->SetViewport(&port); if(FAILED(hr)) return; //set state SetTextureState(); uint32_t width = 0; uint32_t height = 0; GetTextureWH(width, height); //create or update if (bmp_info.width > width || bmp_info.height > height) { //delete texture if (texture_) SAFE_RELEASE(texture_); //recreate texture CreateTexture(bmp_info.width, bmp_info.height); } // if (!UpdateTexture(bmp_info)) return; GetTextureWH(width, height); if(width == 0 || height == 0) return; //update vertex data float max_u = (float)(bmp_info.width) / width; float max_v = (float)(bmp_info.height) / height; SimpleVertex vertex_buffer[4]; vertex_buffer[0] = SimpleVertex(-0.5f + dest.left() + rect_.left(), -0.5f + dest.top() + rect_.top(), 0.0f, 1.0f, 0.0f, 0.0f); vertex_buffer[1] = SimpleVertex(-0.5f + dest.right() + rect_.left(), -0.5f + dest.top() + rect_.top(), 0.0f, 1.0f, max_u, 0.0f); vertex_buffer[2] = SimpleVertex(-0.5f + dest.left() + rect_.left(), -0.5f + dest.bottom() + rect_.top(), 0.0f, 1.0f, 0.0f, max_v); vertex_buffer[3] = SimpleVertex(-0.5f + dest.right() + rect_.left(), -0.5f + dest.bottom() + rect_.top(), 0.0f, 1.0f, max_u, max_v); //draw device7_->SetTexture(0, texture_); device7_->DrawPrimitive(D3DPT_TRIANGLESTRIP, SimpleVertex::GetFVF(), (LPVOID)vertex_buffer, 4, 0); }
// Functions used to maintain the states above. StateStackClass::StateStackClass() { stackDepth = 0; XformedPosPoolNext = XformedPosPoolBuffer; IntensityPoolNext = IntensityPoolBuffer; ClipInfoPoolNext = ClipInfoPoolBuffer; LODBiasInv = 1.0f; SetTextureState(TRUE); SetFog(1.f,NULL); }
void Druid::walk(int** walkMap , int index , int action) { if ( action == 1){ //indicheranno dove si muove il player nel display source.y = Down; SetTextureState(); if(walkMap[position.x-1][position.y] != 1){ playersprite.setPosition((position.y)*32, (position.x)*32 - index); if(index % 8 == 0){ updateFrame = true; SetTextureState(); } if(index == 32){ position.x--; updateFrame = true; source.x = 0; SetTextureState(); } } } else if(action == 2){ source.y=Left; SetTextureState(); if(walkMap[position.x+1][position.y] != 1){ playersprite.setPosition((position.y)*32, (position.x)*32 + index); if(index % 8 == 0){ updateFrame = true; SetTextureState(); } if(index == 32){ position.x++; updateFrame = true; source.x = 0; SetTextureState(); } } } else if(action == 3){ source.y=Up; SetTextureState(); if(walkMap[position.x][position.y+1] != 1){ playersprite.setPosition((position.y)*32 +index, (position.x)*32); if(index % 8 == 0){ updateFrame = true; SetTextureState(); } if(index == 32){ position.y++; updateFrame = true; source.x = 0; SetTextureState(); } } } else if(action == 4){ source.y=Right; SetTextureState(); if(walkMap[position.x][position.y-1] != 1){ playersprite.setPosition((position.y)*32 -index, (position.x)*32); if(index % 8 == 0){ updateFrame = true; SetTextureState(); } if(index == 32){ position.y--; updateFrame = true; source.x = 0; SetTextureState(); } } } notify(); }