void Font::SetText(const string& text, const Vector2& position) { if (text == m_current_text) return; auto pen = position; m_current_text = text; m_vertices.clear(); // Draw each letter onto a quad. for (auto text_char : m_current_text) { auto glyph = m_glyphs[text_char]; if (text_char == ASCII_TAB) { const auto space_offset = m_glyphs[ASCII_SPACE].horizontalOffset; const auto space_count = 8; // spaces in a typical terminal const auto tab_spacing = space_offset * space_count; const auto column_header = int(pen.x - position.x); // -position.x because it has to be zero based so we can do the mod below const auto offset_to_next_tab_stop = tab_spacing - (column_header % (tab_spacing != 0 ? tab_spacing : 1)); pen.x += offset_to_next_tab_stop; continue; } if (text_char == ASCII_NEW_LINE) { pen.y = pen.y - m_char_max_height; pen.x = position.x; continue; } if (text_char == ASCII_SPACE) { pen.x += glyph.horizontalOffset; continue; } // First triangle in quad. m_vertices.emplace_back(pen.x, pen.y - glyph.descent, 0.0f, glyph.uvXLeft, glyph.uvYTop); // Top left m_vertices.emplace_back((pen.x + glyph.width), (pen.y - glyph.height - glyph.descent), 0.0f, glyph.uvXRight, glyph.uvYBottom); // Bottom right m_vertices.emplace_back(pen.x, (pen.y - glyph.height - glyph.descent), 0.0f, glyph.uvXLeft, glyph.uvYBottom); // Bottom left // Second triangle in quad. m_vertices.emplace_back(pen.x, pen.y - glyph.descent, 0.0f, glyph.uvXLeft, glyph.uvYTop); // Top left m_vertices.emplace_back((pen.x + glyph.width), pen.y - glyph.descent, 0.0f, glyph.uvXRight, glyph.uvYTop); // Top right m_vertices.emplace_back((pen.x + glyph.width), (pen.y - glyph.height - glyph.descent), 0.0f, glyph.uvXRight, glyph.uvYBottom); // Bottom right // Update the x location for drawing by the size of the letter and one pixel. pen.x = pen.x + glyph.width; } m_vertices.shrink_to_fit(); m_indices.clear(); for (unsigned int i = 0; i < m_vertices.size(); i++) { m_indices.emplace_back(i); } UpdateBuffers(m_vertices, m_indices); }
void COggStream::Update() { if (stopped) { return; } unsigned tick = SDL_GetTicks(); if (!paused) { if (UpdateBuffers()) { if (!IsPlaying()) { // source state changed if (!StartPlaying()) { // stream stopped ReleaseBuffers(); } else { // stream interrupted ReleaseBuffers(); } } } else if (!IsPlaying()) { // EOS and all chunks processed by OpenALs ReleaseBuffers(); } msecsPlayed += (tick - lastTick); } lastTick = tick; }
bool DirectX10Renderer::RenderSpriteRange(SpriteVector* sprites) { UpdateBuffers(sprites); //ID3D10RasterizerState* WireFrame; //D3D10_RASTERIZER_DESC wfdesc; //ZeroMemory(&wfdesc, sizeof(D3D10_RASTERIZER_DESC)); //wfdesc.FillMode = D3D10_FILL_WIREFRAME; //wfdesc.CullMode = D3D10_CULL_BACK; //wfdesc.FrontCounterClockwise = false; //HRESULT hr = pD3DDevice->CreateRasterizerState(&wfdesc, &WireFrame); //pD3DDevice->RSSetState(WireFrame); // Set vertex buffer UINT stride = sizeof(SpriteVertex); UINT offset = 0; pD3DDevice->IASetVertexBuffers(0, 1, &m_SpriteBuffer, &stride, &offset); for(UINT p = 0; p < m_SpriteTechDesc.Passes; p++) { //apply technique m_SpriteTechnique->GetPassByIndex(p)->Apply(0); //draw pD3DDevice->Draw(sprites->size(), 0); } return true; }
void JohanCity::BuildType(POINT from,POINT to,MenuType type) { switch(type) { case mtResidential: { BuildZone(from,to,ttResidential); break; } case mtCommercial: { BuildZone(from,to,ttCommercial); break; } case mtIndustrial: { BuildZone(from,to,ttIndustrial); break; } case mtRoad: { BuildRoad(from,to,ttRoad); break; } case mtBulldoze: { Bulldoze(from,to); break; } case mtPowerPlant: { AddBuilding(new Building(from.x,from.y,2,2,0,0,btPowerPlant)); break; } case mtPowerLine: { AddBuilding(new Building(from.x,from.y,1,1,0,0,btPowerLine)); break; } } UpdateBuffers(); }
void JohanCity::BuildZone(POINT from,POINT to,TileType type) { SortClampPoints(&from,&to); switch(type) { case ttResidential: case ttCommercial: case ttIndustrial: { if(to.x - from.x > 3 && to.y - from.y > 3) {// add roads when size is more than 4x4 for(int x = from.x;x <= to.x;x++) { for(int y = from.y;y <= to.y;y++) { if((x - from.x) % 5 == 0 || (y - from.y) % 5 == 0) { tiles[x][y]->SetType(ttRoad); } else { tiles[x][y]->SetType(type); } } } } else { for(int x = from.x;x <= to.x;x++) { for(int y = from.y;y <= to.y;y++) { tiles[x][y]->SetType(type); } } } break; } } UpdateBuffers(); }
void Rectangle2DClass::Render(ID3D11Device *device, ID3D11DeviceContext * context,int positionX,int positionY) { HRESULT hr; UINT stride = sizeof(VertexClass); UINT offset = 0; Propertys *dptr; Factors *dptr2; Propertys Combine; D3D11_MAPPED_SUBRESOURCE myresource; D3DXMatrixTranspose(&Combine.TranslationMatrix, &propertys.TranslationMatrix); D3DXMatrixTranspose(&Combine.ScalingMatrix, &propertys.ScalingMatrix); D3DXMatrixTranspose(&Combine.RotationMatrix, &propertys.RotationMatrix); hr = context->Map(m_BlockProperty, 0, D3D11_MAP_WRITE_DISCARD, 0, &myresource); dptr = (Propertys *)myresource.pData; *dptr = Combine; context->Unmap(m_BlockProperty, 0); context->VSSetConstantBuffers(2, 1, &m_BlockProperty); SetTransparency(device, context, factors.transparent); hr = UpdateBuffers(context, positionX, positionY); if (FAILED(hr)) return ; context->IASetVertexBuffers(0, 1, &m_BlockBuffer, &stride, &offset); context->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0); context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context->DrawIndexed(m_indexCount, 0, 0); }
bool BitmapClass::Render(ID3D11DeviceContext* deviceContext, int positionX, int positionY, int bitmapWidth, int bitmapHeight, float angle){ bool result = UpdateBuffers(deviceContext, positionX, positionY, bitmapWidth, bitmapHeight, -angle); if (!result){ return false; } RenderBuffers(deviceContext); return true; }
void SkeletonClass::Render(ID3D10Device* device) { UpdateBuffers(device); // Put the vertex and index buffers on the graphics pipeline to prepare them for drawing. RenderBuffers(device); return; }
bool lcMesh::FileLoad(lcFile& File) { if (File.ReadU32() != LC_FILE_ID || File.ReadU32() != LC_MESH_FILE_ID || File.ReadU32() != LC_MESH_FILE_VERSION) return false; lcuint32 NumVertices, NumTexturedVertices, NumIndices; lcuint16 NumSections; if (!File.ReadU16(&NumSections, 1) || !File.ReadU32(&NumVertices, 1) || !File.ReadU32(&NumTexturedVertices, 1) || !File.ReadU32(&NumIndices, 1)) return false; Create(NumSections, NumVertices, NumTexturedVertices, NumIndices); for (int SectionIdx = 0; SectionIdx < mNumSections; SectionIdx++) { lcMeshSection& Section = mSections[SectionIdx]; lcuint32 ColorCode, IndexOffset; lcuint16 Triangles, Length; if (!File.ReadU32(&ColorCode, 1) || !File.ReadU32(&IndexOffset, 1) || !File.ReadU32(&NumIndices, 1) || !File.ReadU16(&Triangles, 1)) return false; Section.ColorIndex = lcGetColorIndex(ColorCode); Section.IndexOffset = IndexOffset; Section.NumIndices = NumIndices; Section.PrimitiveType = Triangles ? GL_TRIANGLES : GL_LINES; if (!File.ReadU16(&Length, 1)) return false; if (Length) { if (Length >= LC_TEXTURE_NAME_LEN) return false; char FileName[LC_TEXTURE_NAME_LEN]; File.ReadBuffer(FileName, Length); FileName[Length] = 0; Section.Texture = lcGetPiecesLibrary()->FindTexture(FileName); } else Section.Texture = NULL; } File.ReadFloats((float*)mVertexBuffer.mData, 3 * mNumVertices + 5 * mNumTexturedVertices); if (mIndexType == GL_UNSIGNED_SHORT) File.ReadU16((lcuint16*)mIndexBuffer.mData, mIndexBuffer.mSize / 2); else File.ReadU32((lcuint32*)mIndexBuffer.mData, mIndexBuffer.mSize / 4); UpdateBuffers(); return true; }
bool Bitmap::Render(ID3D11DeviceContext* deviceContext){ if (!UpdateBuffers(deviceContext, xPosition, yPosition)){ return false; } RenderBuffers(deviceContext); return true; }
void JohanCity::BuildRoad(POINT from,POINT to,TileType type) { SortClampPoints(&from,&to); for(int x = from.x;x <= to.x;x++) { // TODO: bocht toevoegen? for(int y = from.y;y <= to.y;y++) { tiles[x][y]->SetType(ttRoad); } } UpdateBuffers(); }
void JohanCity::Bulldoze(POINT from,POINT to) { SortClampPoints(&from,&to); for(int x = from.x;x <= to.x;x++) { for(int y = from.y;y <= to.y;y++) { tiles[x][y]->SetType(ttGround); tiles[x][y]->Bulldoze(); } } UpdateBuffers(); }
void JohanCity::UpdateTime(float dt) { clock->Start(); // Optimized version of power checking... CheckPower(); // crawls from power plant outward... // Optimized version of water checking... CheckWater(); // crawls from water source outward... // TODO: optimize? CheckConnection(); checktilems = clock->Reset() * 1000.0f; // Then apply tile info to buildings CheckBuildingRequisites(); checkbuildingms = clock->Reset() * 1000.0f; // Done checking for required items? Spend the RCI for(int i = 0;i < tiles.size();i++) { for(int j = 0;j < tiles[i].size();j++) { TileType type = tiles[i][j]->type; if(type == ttResidential || type == ttCommercial || type == ttIndustrial) { tiles[i][j]->UpdateTime(dt); } // Undo checks (so they won't get invalid)? tiles[i][j]->checkid = -1; // tiles[i][j]->powered = false; // tiles[i][j]->watered = false; // tiles[i][j]->connected = false; } } updatetilems = clock->Reset() * 1000.0f; for(std::list<Building*>::iterator i = buildings.begin();i != buildings.end();i++) { Building* building = *i; building->UpdateTime(dt); } updatebuildingms = clock->Reset() * 1000.0f; snprintf(timingreport,256, "Check tile time: %.2f ms\r\nCheck building time: %.2f ms\r\nUpdate tile time: %.2f ms\r\nUpdate building time: %.2f ms\r\n", checktilems, checkbuildingms, updatetilems, updatebuildingms); UpdateBuffers(); }
bool MouseCursor::Render(ID3D11DeviceContext* deviceContext) { bool result; // Re-build the dynamic vertex buffer for rendering to possibly a different location on the screen. result = UpdateBuffers(deviceContext, m_pos); if(!result) return false; // Put the vertex and index buffers on the graphics pipeline to prepare them for drawing. RenderBuffers(deviceContext); return true; }
bool HexMapClass::Render(ID3D11DeviceContext* deviceContext, int positionX, int positionY, int* terrain){ bool result; // Re-build the dynamic vertex buffer for rendering to possibly a different location on the screen. result = UpdateBuffers(deviceContext, positionX, positionY, terrain); if (!result){ return false; } // Put the vertex and index buffers on the graphics pipeline to prepare them for drawing. RenderBuffers(deviceContext); return true; }
bool CBitmapClass::Render(ID3D11DeviceContext* deciveContext, int positionX, int positionY) { bool result; //Recreamos el buffer dinamico para rendear una nueva ubicacion del objetos, si se necesita result = UpdateBuffers(deciveContext, positionX, positionY); if (!result) { return false; } //Creamos el vertex y pixel buffer para renderear RenderBuffers(deciveContext); return true; }
void JohanCity::Resize(int gridsize,float edgelen) { // nicely remove old tiles and batches Clear(); // Change parameters this->gridsize = gridsize; this->edgelen = edgelen; this->batchsize = gridsize/8; // Create new grid and recreate batches ResizeGrid(); ResizeBatches(); // creates smaller piles of tiles to reduce draw calls // Look exactly at the center of our grid float3 focus = float3(gridsize*edgelen/2-300,0,gridsize*edgelen/2-300); camera->SetPos(focus + float3(-500,700,-500)); camera->SetLookAt(focus); // Assign batches and objects to tiles for(int i = 0;i < tiles.size();i++) { for(int j = 0;j < tiles[i].size();j++) { // Determine where in the current batch we are int tilei = i % batchsize; int tilej = j % batchsize; Batch* batch = batches[i / batchsize][j / batchsize]; // batch this tile belongs to Model* plane = batch->plane->GetDetailLevel(0)->model; // model this tile is owner of tiles[i][j]->batch = batch; // Determine vertex index in batch int index = 4 * tilei + 4 * batchsize * tilej; tiles[i][j]->plane = &plane->localvertexbuffer[index]; // offset inside batch } } // Set default tile type for(int i = 0;i < tiles.size();i++) { for(int j = 0;j < tiles[i].size();j++) { tiles[i][j]->SetType(ttGround); } } UpdateBuffers(); // send all batches to the GPU }
bool DebugWindow::Render(ID3D10Device* device, int positionX, int positionY) { bool result; // Re-build the dynamic vertex buffer for rendering to possibly a different location on the screen. result = UpdateBuffers(positionX, positionY); if(!result) { return false; } // Put the vertex and index buffers on the graphics pipeline to prepare them for drawing. RenderBuffers(device); return true; }
bool ParticleSystemClass::Frame(float frameTime, ID3D11DeviceContext* deviceContext, D3DXVECTOR3 emitterPosition, D3DXVECTOR3 camPos) { bool result; KillParticles(); EmitParticles(frameTime, emitterPosition); UpdateParticles(frameTime, camPos); result = UpdateBuffers(deviceContext); //updating dynamic vertex buffer with new position of each particle if(!result) { return false; } return true; }
bool Bitmap::Render(ID3D11DeviceContext* deviceContext, int positionX, int positionY , int bitmapWidth, int bitmapHeight, float depth) { bool result; m_bitmapWidth = bitmapWidth; m_bitmapHeight = bitmapHeight; // Re-build the dynamic vertex buffer for rendering to possibly a different location on the screen. result = UpdateBuffers(deviceContext, positionX, positionY, bitmapWidth, bitmapHeight, depth); if(!result) { return false; } // Put the vertex and index buffers on the graphics pipeline to prepare them for drawing. RenderBuffers(deviceContext); return true; }
void COggStream::Update() { if (stopped) { return; } spring_time tick = spring_gettime(); if (!paused) { UpdateBuffers(); if (!IsPlaying()) { ReleaseBuffers(); } msecsPlayed += (tick - lastTick); } lastTick = tick; }
bool CBitmap::Render(ID3D11DeviceContext* deviceContext, int posX, int posY) { bool result; // Rebuild the dynamic vertex buffer for rendering to a different location // Only if posX != previousPosX if (posX != previousPosX ||posY != previousPosY) { result = UpdateBuffers(deviceContext, posX, posY); if (!result) { CLog::Write("CBitmap::Render : could not update the dynamic vertex buffers"); return false; } } RenderBuffers(deviceContext); return true; }
void VolumetricFog::handleResize(VolumetricFogRTManager *RTM, bool resize) { if (resize) { mResizing = true; RTM->FogAnswered(); } else mResizing = false; if (mIsTextured) { F32 width = (F32)mPlatformWindow->getClientExtent().x; F32 height = (F32)mPlatformWindow->getClientExtent().y; mTexScale.x = 2.0f - ((F32)mTexture.getWidth() / width); mTexScale.y = 2.0f - ((F32)mTexture.getHeight() / height); } UpdateBuffers(0,true); }
void DecalEngine::Draw() { UpdateBuffers(); if( mDecals.empty() ) { return; } mVAO.Bind(); ShaderManager& ShaderMgr( ShaderManager::Get() ); ShaderMgr.ActivateShader( "decals" ); glActiveTexture( GL_TEXTURE0 + 3 ); for( render::Counts_t::const_iterator i = mCounts.begin(), e = mCounts.end(); i != e; ++i ) { render::CountByTexId const& Part = *i; GLuint CurrentAttribIndex = 0; glVertexAttribPointer( CurrentAttribIndex, 4, GL_FLOAT, GL_FALSE, 0, ( GLvoid* )( mTexIndex + sizeof( glm::vec4 )*Part.Start ) ); glVertexAttribDivisor( CurrentAttribIndex, 1 ); ++CurrentAttribIndex; glVertexAttribPointer( CurrentAttribIndex, 2, GL_FLOAT, GL_FALSE, 0, ( GLvoid* )( mPosIndex + sizeof( glm::vec2 )*Part.Start ) ); glVertexAttribDivisor( CurrentAttribIndex, 1 ); ++CurrentAttribIndex; glVertexAttribPointer( CurrentAttribIndex, 1, GL_FLOAT, GL_FALSE, 0, ( GLvoid* )( mHeadingIndex + sizeof( GLfloat )*Part.Start ) ); glVertexAttribDivisor( CurrentAttribIndex, 1 ); ++CurrentAttribIndex; glVertexAttribPointer( CurrentAttribIndex, 1, GL_FLOAT, GL_FALSE, 0, ( GLvoid* )( mAlphaIndex + sizeof( GLfloat )*Part.Start ) ); glVertexAttribDivisor( CurrentAttribIndex, 1 ); ++CurrentAttribIndex; glVertexAttribPointer( CurrentAttribIndex, 1, GL_FLOAT, GL_FALSE, 0, ( GLvoid* )( mRadiusIndex + sizeof( GLfloat )*Part.Start ) ); glVertexAttribDivisor( CurrentAttribIndex, 1 ); if( Part.TexId != GLuint( -1 ) ) { glBindTexture( GL_TEXTURE_2D, Part.TexId ); } glDrawArraysInstanced( GL_TRIANGLE_STRIP, 0, 4, Part.Count ); } glActiveTexture( GL_TEXTURE0 ); mVAO.Unbind(); }
bool ParticleSystemClass::Frame(float frameTime, ID3D11DeviceContext* deviceContext) { bool result; // Release old particles. KillParticles(); // Emit new particles. EmitParticles(frameTime); // Update the position of the particles. UpdateParticles(frameTime); // Update the dynamic vertex buffer with the new position of each particle. result = UpdateBuffers(deviceContext); if(!result) { return false; } return true; }
void COggStream::Update() { if (!stopped) { UpdateTimer(); if (!paused) { if (UpdateBuffers()) { if (!IsPlaying()) { // source state changed if (!StartPlaying()) { // stream stopped ReleaseBuffers(); } else { // stream interrupted ReleaseBuffers(); } } } else { // EOS, nothing left to do ReleaseBuffers(); } } } }
//Frame Particle System bool CParticleSystem::Frame(ID3D11DeviceContext* deviceContext, float frameTime, CCamera* mainCamera) { bool result; //Release previous Particles KillParticles(); //Emit new Particles EmitParticles(frameTime); //Update positions of Particles UpdateParticles(frameTime); //Update Buffers (Dynamic) result = UpdateBuffers(deviceContext, mainCamera); if (!result) { return false; } return true; }
bool DynamicBitmapClass::UpdatePosition(int positionX, int positionY, float scale) { return UpdateBuffers(positionX, positionY, scale); }
void VolumetricFog::handleCanvasResize(GuiCanvas* canvas) { UpdateBuffers(0,true); }
void lcMesh::CreateBox() { Create(2, 8, 0, 36 + 24); lcVector3 Min(-10.0f, -10.0f, -24.0f); lcVector3 Max(10.0f, 10.0f, 4.0f); float* Verts = (float*)mVertexBuffer.mData; lcuint16* Indices = (lcuint16*)mIndexBuffer.mData; *Verts++ = Min[0]; *Verts++ = Min[1]; *Verts++ = Min[2]; *Verts++ = Min[0]; *Verts++ = Max[1]; *Verts++ = Min[2]; *Verts++ = Max[0]; *Verts++ = Max[1]; *Verts++ = Min[2]; *Verts++ = Max[0]; *Verts++ = Min[1]; *Verts++ = Min[2]; *Verts++ = Min[0]; *Verts++ = Min[1]; *Verts++ = Max[2]; *Verts++ = Min[0]; *Verts++ = Max[1]; *Verts++ = Max[2]; *Verts++ = Max[0]; *Verts++ = Max[1]; *Verts++ = Max[2]; *Verts++ = Max[0]; *Verts++ = Min[1]; *Verts++ = Max[2]; lcMeshSection* Section = &mSections[0]; Section->ColorIndex = gDefaultColor; Section->IndexOffset = 0; Section->NumIndices = 36; Section->PrimitiveType = GL_TRIANGLES; Section->Texture = NULL; *Indices++ = 0; *Indices++ = 1; *Indices++ = 2; *Indices++ = 0; *Indices++ = 2; *Indices++ = 3; *Indices++ = 7; *Indices++ = 6; *Indices++ = 5; *Indices++ = 7; *Indices++ = 5; *Indices++ = 4; *Indices++ = 0; *Indices++ = 1; *Indices++ = 5; *Indices++ = 0; *Indices++ = 5; *Indices++ = 4; *Indices++ = 2; *Indices++ = 3; *Indices++ = 7; *Indices++ = 2; *Indices++ = 7; *Indices++ = 6; *Indices++ = 0; *Indices++ = 3; *Indices++ = 7; *Indices++ = 0; *Indices++ = 7; *Indices++ = 4; *Indices++ = 1; *Indices++ = 2; *Indices++ = 6; *Indices++ = 1; *Indices++ = 6; *Indices++ = 5; Section = &mSections[1]; Section->ColorIndex = gEdgeColor; Section->IndexOffset = 36 * 2; Section->NumIndices = 24; Section->PrimitiveType = GL_LINES; Section->Texture = NULL; *Indices++ = 0; *Indices++ = 1; *Indices++ = 1; *Indices++ = 2; *Indices++ = 2; *Indices++ = 3; *Indices++ = 3; *Indices++ = 0; *Indices++ = 4; *Indices++ = 5; *Indices++ = 5; *Indices++ = 6; *Indices++ = 6; *Indices++ = 7; *Indices++ = 7; *Indices++ = 4; *Indices++ = 0; *Indices++ = 4; *Indices++ = 1; *Indices++ = 5; *Indices++ = 2; *Indices++ = 6; *Indices++ = 3; *Indices++ = 7; UpdateBuffers(); }