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); }
ShapeQuad::ShapeQuad(HString name): Shape(name) { _verticesCount = 4; _vertices = new SimpleVertex[_verticesCount]; std::memset(_vertices, 0, sizeof(WORD) * _verticesCount); _vertices[0] = SimpleVertex( XMFLOAT3( -1.0f, -1.0f, 0.0f ), XMFLOAT3( 0.0f, 1.0f, 0.0f ), XMFLOAT2( 0.0f, 1.0f )); _vertices[1] = SimpleVertex( XMFLOAT3( -1.0f , 1.0f, 0.0f ), XMFLOAT3( 0.0f, 1.0f, 0.0f ), XMFLOAT2( 0.0f, 0.0f )); _vertices[2] = SimpleVertex( XMFLOAT3( 1.0f, -1.0f, 0.0f ), XMFLOAT3( 0.0f, 1.0f, 0.0f ), XMFLOAT2( 1.0f, 1.0f )); _vertices[3] = SimpleVertex( XMFLOAT3( 1.0f, 1.0f, 0.0f ), XMFLOAT3( 0.0f, 1.0f, 0.0f ), XMFLOAT2( 1.0f, 0.0f )); }
void D3D7Canvas::DrawLine(const Point & p1, const Point & p2, const Paint & paint) { SimpleVertex cv_buffer[2]; cv_buffer[0] = SimpleVertex(p1, paint.color); cv_buffer[1] = SimpleVertex(p2, paint.color); SetDiffuseState(); device7_->DrawPrimitive(D3DPT_LINELIST, SimpleVertex::GetFVF(), (LPVOID)cv_buffer, 2, 0); }
void LoadEffectResources(IDirect3DDevice9 *m_pDevice) { //Calculate sight mesh (a simple quad) D3DXCreateMeshFVF(2, 4, D3DXMESH_MANAGED, SimpleVertex::FVF, m_pDevice, &billboardMesh); //Create 4 vertices SimpleVertex* v = 0; billboardMesh->LockVertexBuffer(0,(void**)&v); v[0] = SimpleVertex(D3DXVECTOR3(-0.5f, 0.0f, 0.5f), D3DXVECTOR3(0.0f, 1.0f, 0.0f), D3DXVECTOR2(0, 0)); v[1] = SimpleVertex(D3DXVECTOR3( 0.5f, 0.0f, 0.5f), D3DXVECTOR3(0.0f, 1.0f, 0.0f), D3DXVECTOR2(1, 0)); v[2] = SimpleVertex(D3DXVECTOR3(-0.5f, 0.0f, -0.5f),D3DXVECTOR3(0.0f, 1.0f, 0.0f), D3DXVECTOR2(0, 1)); v[3] = SimpleVertex(D3DXVECTOR3( 0.5f, 0.0f, -0.5f),D3DXVECTOR3(0.0f, 1.0f, 0.0f), D3DXVECTOR2(1, 1)); billboardMesh->UnlockVertexBuffer(); //Create 2 faces WORD* indices = 0; billboardMesh->LockIndexBuffer(0,(void**)&indices); indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 1; indices[4] = 3; indices[5] = 2; billboardMesh->UnlockIndexBuffer(); //Set Attributes for the 2 faces DWORD *att = 0; billboardMesh->LockAttributeBuffer(0,&att); att[0] = 0; att[1] = 0; billboardMesh->UnlockAttributeBuffer(); //Sight MTRL memset(&whiteMtrl, 0, sizeof(D3DMATERIAL9)); whiteMtrl.Diffuse = whiteMtrl.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); //Load Shaders effectVertexShader.Init(m_pDevice, "shaders/effect.vs", VERTEX_SHADER); effectPixelShader.Init(m_pDevice, "shaders/effect.ps", PIXEL_SHADER); //Get constants effectMatW = effectVertexShader.GetConstant("matW"); effectMatVP = effectVertexShader.GetConstant("matVP"); effectVCol = effectVertexShader.GetConstant("vertexColor"); //Create Sprite D3DXCreateSprite(m_pDevice, &sprite); //Load textures D3DXCreateTextureFromFile(m_pDevice, "textures/runes.dds", &runesTexture); D3DXCreateTextureFromFile(m_pDevice, "textures/cloud.dds", &cloudTexture); D3DXCreateTextureFromFile(m_pDevice, "textures/fireball.dds", &fireballTexture); D3DXCreateTextureFromFile(m_pDevice, "textures/lensflare.dds", &lensflareTexture); }
void AddQuad(XMFLOAT3 p0, XMFLOAT3 p1, XMFLOAT3 p2, XMFLOAT3 p3, XMFLOAT4 color) { int n = Vertices.size(); Vertices.push_back(SimpleVertex(p3, color)); Vertices.push_back(SimpleVertex(p2, color)); Vertices.push_back(SimpleVertex(p1, color)); Vertices.push_back(SimpleVertex(p0, color)); Indices.push_back(n + 0); Indices.push_back(n + 1); Indices.push_back(n + 2); Indices.push_back(n + 2); Indices.push_back(n + 3); Indices.push_back(n + 0); }
void D3D7Canvas::DrawRect(const Rect & rect, const Paint & paint) { SimpleVertex cv_buffer[4]; cv_buffer[0] = SimpleVertex((float)rect.left(), (float)rect.top(), 0.5f, paint.color); cv_buffer[1] = SimpleVertex((float)rect.right(), (float)rect.top(), 0.5f, paint.color); cv_buffer[2] = SimpleVertex((float)rect.left(), (float)rect.bottom(), 0.5f, paint.color); cv_buffer[3] = SimpleVertex((float)rect.right(), (float)rect.bottom(), 0.5f, paint.color); SetDiffuseState(); device7_->DrawPrimitive(D3DPT_TRIANGLESTRIP, SimpleVertex::GetFVF(), (LPVOID)cv_buffer, 4, 0); }
VOID AEResource::addToRenderBuffer(AEBiasRect paintArea, AERect texClip, FLOAT alpha, FLOAT zValue) { XMFLOAT4 color = XMFLOAT4(1.0f, 1.0f, 1.0f, alpha); vertexBuffer.push_back(SimpleVertex(XMFLOAT3(paintArea.x4, paintArea.y4, zValue), XMFLOAT2(texClip.x1, texClip.y1), color)); vertexBuffer.push_back(SimpleVertex(XMFLOAT3(paintArea.x3, paintArea.y3, zValue), XMFLOAT2(texClip.x2, texClip.y1), color)); vertexBuffer.push_back(SimpleVertex(XMFLOAT3(paintArea.x1, paintArea.y1, zValue), XMFLOAT2(texClip.x1, texClip.y2), color)); vertexBuffer.push_back(SimpleVertex(XMFLOAT3(paintArea.x1, paintArea.y1, zValue), XMFLOAT2(texClip.x1, texClip.y2), color)); vertexBuffer.push_back(SimpleVertex(XMFLOAT3(paintArea.x3, paintArea.y3, zValue), XMFLOAT2(texClip.x2, texClip.y1), color)); vertexBuffer.push_back(SimpleVertex(XMFLOAT3(paintArea.x2, paintArea.y2, zValue), XMFLOAT2(texClip.x2, texClip.y2), color)); }
ShapeCircle::ShapeCircle(HString name): Shape(name) { _verticesCount = 2056; _vertices = new SimpleVertex[_verticesCount]; std::memset(_vertices, 0, sizeof(WORD) * _verticesCount); float dx = 1.0f / (_verticesCount-1); // Create vertex buffer for(int i = 0; i < _verticesCount; i++) { float angle = PI_2 / (_verticesCount-1) * i; _vertices[i] = SimpleVertex( XMFLOAT3( cos(angle), 0.0f, sin(angle) ), XMFLOAT3( 0.0f, 1.0f, 0.0f ), XMFLOAT2( dx * i, 0 )); } }
ShapeAssimp::ShapeAssimp(const char* path): Shape(path) { _vertices = nullptr; _indices = nullptr; // the global Assimp scene object (mesh loader) const struct aiScene* scene; scene = aiImportFile(path,aiProcessPreset_TargetRealtime_MaxQuality /*| aiProcess_MakeLeftHanded | aiProcess_FlipUVs */ ); if(scene && scene->mRootNode) { //unsigned int i; unsigned int n = 0, t; struct aiNode* nd = scene->mRootNode; if(nd && nd->mNumChildren > 0) nd = nd->mChildren[0]; // struct aiMatrix4x4 m = nd->mTransformation; if(nd) { // draw all meshes assigned to this node for (; n < nd->mNumMeshes && n <= 1; ++n) { const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]]; _verticesCount = mesh->mNumVertices; _indicesCount = mesh->mNumFaces * 3; _vertices = new SimpleVertex[_verticesCount]; std::memset(_vertices, 0, sizeof(WORD) * _verticesCount); _indices = new WORD[_indicesCount]; std::memset(_indices, 0, sizeof(WORD) * _indicesCount); for (t = 0; t < mesh->mNumVertices; ++t) { const aiVector3D* vertice = &mesh->mVertices[t]; const aiVector3D* normal = &mesh->mNormals[t]; const aiVector3D* uvCoord = &mesh->mTextureCoords[0][t]; if(vertice && normal && uvCoord) _vertices[t] = SimpleVertex( XMFLOAT3( vertice->x, -vertice->z, vertice->y ), XMFLOAT3( normal->x, -normal->z, normal->y ) , XMFLOAT2( uvCoord->x, uvCoord->y ) ); else _vertices[t] = SimpleVertex( XMFLOAT3( 0, 0, 0 ), XMFLOAT3( 0, 0, 0), XMFLOAT2( 0, 0) ); } for (t = 0; t < mesh->mNumFaces; ++t) { const struct aiFace* face = &mesh->mFaces[t]; if(face->mNumIndices != 3) break; //only triangles supported _indices[3*t] = face->mIndices[0]; _indices[3*t+1] = face->mIndices[1]; _indices[3*t+2] = face->mIndices[2]; } } } } aiReleaseImport(scene); scene = nullptr; }
void GeometryGenerator::CreateBox(float width, float height, float depth, SimpleMesh& mesh) { // // Create the vertices. // SimpleVertex v[24]; float w2 = 0.5f*width; float h2 = 0.5f*height; float d2 = 0.5f*depth; // Fill in the front face SimpleVertex data. v[0] = SimpleVertex(-w2, -h2, -d2, 0.0f, 0.0f, -1.0f); v[1] = SimpleVertex(-w2, +h2, -d2, 0.0f, 0.0f, -1.0f); v[2] = SimpleVertex(+w2, +h2, -d2, 0.0f, 0.0f, -1.0f); v[3] = SimpleVertex(+w2, -h2, -d2, 0.0f, 0.0f, -1.0f); // Fill in the back face SimpleVertex data. v[4] = SimpleVertex(-w2, -h2, +d2, 0.0f, 0.0f, 1.0f); v[5] = SimpleVertex(+w2, -h2, +d2, 0.0f, 0.0f, 1.0f); v[6] = SimpleVertex(+w2, +h2, +d2, 0.0f, 0.0f, 1.0f); v[7] = SimpleVertex(-w2, +h2, +d2, 0.0f, 0.0f, 1.0f); // Fill in the top face SimpleVertex data. v[8] = SimpleVertex(-w2, +h2, -d2, 0.0f, 1.0f, 0.0f); v[9] = SimpleVertex(-w2, +h2, +d2, 0.0f, 1.0f, 0.0f); v[10] = SimpleVertex(+w2, +h2, +d2, 0.0f, 1.0f, 0.0f); v[11] = SimpleVertex(+w2, +h2, -d2, 0.0f, 1.0f, 0.0f); // Fill in the bottom face SimpleVertex data. v[12] = SimpleVertex(-w2, -h2, -d2, 0.0f, -1.0f, 0.0f); v[13] = SimpleVertex(+w2, -h2, -d2, 0.0f, -1.0f, 0.0f); v[14] = SimpleVertex(+w2, -h2, +d2, 0.0f, -1.0f, 0.0f); v[15] = SimpleVertex(-w2, -h2, +d2, 0.0f, -1.0f, 0.0f); // Fill in the left face SimpleVertex data. v[16] = SimpleVertex(-w2, -h2, +d2, -1.0f, 0.0f, 0.0f); v[17] = SimpleVertex(-w2, +h2, +d2, -1.0f, 0.0f, 0.0f); v[18] = SimpleVertex(-w2, +h2, -d2, -1.0f, 0.0f, 0.0f); v[19] = SimpleVertex(-w2, -h2, -d2, -1.0f, 0.0f, 0.0f); // Fill in the right face SimpleVertex data. v[20] = SimpleVertex(+w2, -h2, -d2, 1.0f, 0.0f, 0.0f); v[21] = SimpleVertex(+w2, +h2, -d2, 1.0f, 0.0f, 0.0f); v[22] = SimpleVertex(+w2, +h2, +d2, 1.0f, 0.0f, 0.0f); v[23] = SimpleVertex(+w2, -h2, +d2, 1.0f, 0.0f, 0.0f); mesh.Vertices.assign(&v[0], &v[24]); // // Create the indices. // UINT i[36]; // Fill in the front face index data i[0] = 0; i[1] = 1; i[2] = 2; i[3] = 0; i[4] = 2; i[5] = 3; // Fill in the back face index data i[6] = 4; i[7] = 5; i[8] = 6; i[9] = 4; i[10] = 6; i[11] = 7; // Fill in the top face index data i[12] = 8; i[13] = 9; i[14] = 10; i[15] = 8; i[16] = 10; i[17] = 11; // Fill in the bottom face index data i[18] = 12; i[19] = 13; i[20] = 14; i[21] = 12; i[22] = 14; i[23] = 15; // Fill in the left face index data i[24] = 16; i[25] = 17; i[26] = 18; i[27] = 16; i[28] = 18; i[29] = 19; // Fill in the right face index data i[30] = 20; i[31] = 21; i[32] = 22; i[33] = 20; i[34] = 22; i[35] = 23; mesh.Indices.assign(&i[0], &i[36]); }