// ********************************************************************************************************* void CDisplayerVisualShape::onPostRender() { //H_AUTO(R2_CDisplayerVisualShape_onPostRender) if (!_Active || !getActualVisibility()) return; if (_BadShapeName) return; if (!_Instance.empty()) { if (getDisplayFlag(FlagSelected)) { //visualSnapToGround(); drawBBox(CRGBA::Green); setEmissive(_Instance, getBlinkColor(CV_SelectedInstanceColor.get())); } else if (getDisplayFlag(FlagHasFocus)) { //visualSnapToGround(); drawBBox(CRGBA::White); setEmissive(_Instance, getBlinkColor(CV_FocusedInstanceColor.get())); } else { CRGBA color = getDisplayModeColorInScene(); setEmissive(_Instance, color); ::makeInstanceTransparent(_Instance, color.A, color.A != 255); } } CDisplayerVisual::onPostRender(); }
void EntitiesEditor::drawBoxHelpers(Renderer2D &out, const IBox &box) const { int3 pos = box.min, bbox = box.max - box.min; int3 tsize = asXZY(m_tile_map.dimensions(), 32); drawLine(out, int3(0, pos.y, pos.z), int3(tsize.x, pos.y, pos.z), Color(0, 255, 0, 127)); drawLine(out, int3(0, pos.y, pos.z + bbox.z), int3(tsize.x, pos.y, pos.z + bbox.z), Color(0, 255, 0, 127)); drawLine(out, int3(pos.x, pos.y, 0), int3(pos.x, pos.y, tsize.z), Color(0, 255, 0, 127)); drawLine(out, int3(pos.x + bbox.x, pos.y, 0), int3(pos.x + bbox.x, pos.y, tsize.z), Color(0, 255, 0, 127)); int3 tpos(pos.x, 0, pos.z); drawBBox(out, IBox(tpos, tpos + int3(bbox.x, pos.y, bbox.z)), Color(0, 0, 255, 127)); drawLine(out, int3(0, 0, pos.z), int3(tsize.x, 0, pos.z), Color(0, 0, 255, 127)); drawLine(out, int3(0, 0, pos.z + bbox.z), int3(tsize.x, 0, pos.z + bbox.z), Color(0, 0, 255, 127)); drawLine(out, int3(pos.x, 0, 0), int3(pos.x, 0, tsize.z), Color(0, 0, 255, 127)); drawLine(out, int3(pos.x + bbox.x, 0, 0), int3(pos.x + bbox.x, 0, tsize.z), Color(0, 0, 255, 127)); }
void TileSelector::drawContents(Renderer2D &out) const { int2 offset = innerOffset(); IRect clip_rect(int2(0, 0), clippedRect().size()); for(int n = 0; n < (int)m_tile_list.size(); n++) { const Tile *tile = m_tile_list[n].tile; IRect tile_rect = tile->rect(); int2 pos = m_tile_list[n].pos - tile_rect.min - offset; if(areOverlapping(clip_rect, tile_rect + pos)) tile->draw(out, pos); } if(m_selection) { int2 pos = m_selection->pos - offset; out.setViewPos(-clippedRect().min - pos + m_selection->tile->rect().min); IBox box(int3(0, 0, 0), m_selection->tile->bboxSize()); drawBBox(out, box); // out.addFilledRect(IRect(pos, pos + m_selection->size)); } }
void GroupEditor::drawContents(Renderer2D &out) const { int2 offset = innerOffset(); for(int n = 0; n < m_tile_group->entryCount(); n++) m_tile_group->entryTile(n)->m_temp = n; IRect clip_rect(int2(0, 0), clippedRect().size()); for(int n = 0; n < (int)m_tile_list.size(); n++) { const ui::TileList::Entry &entry = m_tile_list[n]; entry.is_selected = m_mode == mAddRemove? m_tile_group->isValidEntryId(entry.tile->m_temp, entry.tile) : entry.group_id == m_selected_group_id; IRect tile_rect = entry.tile->rect(); int2 pos = entry.pos - tile_rect.min - offset; if(areOverlapping(clip_rect, tile_rect + pos)) entry.tile->draw(out, pos); } DTexture::unbind(); for(int n = 0; n < (int)m_tile_list.size(); n++) { const ui::TileList::Entry &entry = m_tile_list[n]; if(!entry.is_selected) continue; Color col = m_tile_group->isEntryDirty(entry.tile->m_temp)? ColorId::red : ColorId::white; int2 pos = entry.pos - offset; out.addRect(IRect(pos, pos + entry.size), col); } if(m_mode == mModify && m_selected_group_id != -1) { IRect edit_rect(clippedRect().max - int2(280, 250), clippedRect().max - int2(5, 0)); int2 center = edit_rect.center(); out.setViewPos(-center); int2 half_size = edit_rect.size() / 2; out.addFilledRect(IRect(-half_size, half_size), FColor(0.3f, 0.3f, 0.3f)); drawBBox(out, IBox({-9, 0, -9}, {9, 1, 9}), ColorId::white); auto font = res::getFont(WindowStyle::fonts[0]); for(int n = 0; n < TileGroup::Group::side_count; n++) { out.setViewPos(-center - worldToScreen(TileGroup::Group::s_side_offsets[n] * 9)); font->draw(out, float2(0, 0), {ColorId::white}, format("%d", m_tile_group->groupSurface(m_selected_group_id, n))); } out.setViewPos(-center +edit_rect.size() / 2); font->draw(out, float2(0, 0), {ColorId::white}, format("setting surface: %d", m_selected_surface_id)); /* const char *names[] = { "", "snow", "gravel", "dirt", "grass", "mud", "mud_cracked", "sand", "green goo", }; out.setViewPos(-int2(bottom_rect.max.x - 200, bottom_rect.min.y)); for(int n = 0; n < arraySize(names); n++) font->draw(int2(0, 10), ColorId::white, m_selected_surface_id == n? "%d: [%s]\n" : "%d: %s\n", n, names[n]); */ out.setViewPos(-clippedRect().min); } if(m_current_entry) m_font->draw(out, float2(5, height() - 20), {ColorId::white, ColorId::black}, format("%s", m_current_entry->tile->resourceName().c_str())); }
void ExternalRenderer::blockDrawingFunction( const MC2BoundingBox& box, TileMapContainer& tileMapCont, TileMapFormatDesc& formatDesc, bool skipOutlines) { typedef std::vector<TriStorageBlock> BlockVec; MapsToDrawIt endIt = tileMapCont.endMapsToDraw(); OverlapDetector<MC2BoundingBox> overlapDetector; int numTileMapsDrawn = 0; for( int pass = 0; pass < 2; ++pass ) { for( int level = formatDesc.getMinLevel(); level <= formatDesc.getMaxLevel(); ++level ) { for( MapsToDrawIt mIt = tileMapCont.beginMapsToDraw(); mIt != endIt; ++mIt ) { TileMap* tileMap = *mIt; if ( tileMap == NULL ) { continue; } if (!m_impl->mapHandler->isTileMapVisible(tileMap)){ // Consult tilemaphandler to see if this tileMap should be drawn // or not. continue; } numTileMapsDrawn++; bool inPerspective = false; TriStorage& tris = tileMap->getGeometryData(level); for (BlockVec::iterator bIt = tris.blocks.begin(); bIt != tris.blocks.end(); bIt++) { TriStorageBlock& block = *bIt; switch(block.type) { case TilePrimitiveFeature::line: if (!inPerspective){ setupPerspectiveProjection(); offsetPerspective(tileMap->getReferenceCoord()); inPerspective = true; } drawLineBlock(block, pass, tileMap->getTriangleData(), box, tileMapCont, formatDesc, skipOutlines); break; case TilePrimitiveFeature::polygon: if (!inPerspective){ setupPerspectiveProjection(); offsetPerspective(tileMap->getReferenceCoord()); inPerspective = true; } drawPolygonBlock(block, pass, tileMap->getTriangleData(), box, tileMapCont, formatDesc, skipOutlines); break; case TilePrimitiveFeature::bitmap: if (inPerspective){ resetOffsetPerspective(); inPerspective = false; } setupOrthographicProjection(); drawBitmapBlock(block, pass, tileMap->getTriangleData(), box, overlapDetector, tileMapCont, formatDesc, skipOutlines); break; } } if (inPerspective){ resetOffsetPerspective(); } #ifdef DRAW_TILE_BOUNDS setupPerspectiveProjection(); MC2BoundingBox tBox; tileMap->getBoundingBox(tBox, formatDesc); drawBBox(tBox); #endif } } } // std::cout << "Num tile-maps drawn: " << numTileMapsDrawn << std::endl; // setupPerspectiveProjection(); // The following call to drawBBox draws the bounding box supplied from // TileMapHandler::plotWhatWeGotUsingExternal. Use this when working on // horizon image etc. in 3d mode. // drawBBox( box ); // drawBBox( m_impl->projection->getCenterBox() ); // drawBBox( projection.getOldSchoolBoundingBox() ); // drawBBox( newBox ); // // std::cout << "oldBox: " << box << std::endl; // std::cout << "newWidth: " << newBox.getWidth() // << " newHeight: " << newBox.getHeight() << std::endl; // std::cout << "oldWidth: " << box.getWidth() // << " oldHeight: " << box.getHeight() << std::endl; // std::pair<float,float> wah = projection.getWidthAndHeight(); // std::cout << "proj.width: " << static_cast<int>( wah.first ) // << " proj.height: " << static_cast<int>( wah.second ) << // std::endl; setupOrthographicProjection(); }
void GraphicEngine::renderWorld() { glMatrixMode(GL_MODELVIEW); // set modelview matrix glLoadIdentity(); // clear the current matrix // Offsets glTranslatef(masterPositionOffset.x, masterPositionOffset.y, masterPositionOffset.z); glRotatef(masterOrientationOffset.x, 1.0f, 0.0f, 0.0f); glRotatef(masterOrientationOffset.y, 0.0f, 1.0f, 0.0f); glRotatef(masterOrientationOffset.z, 0.0f, 0.0f, 1.0f); gluLookAt(game->camera->position.x, game->camera->position.y, game->camera->position.z, game->camera->lookAt.x + game->camera->position.x, game->camera->lookAt.y + game->camera->position.y, game->camera->lookAt.z + game->camera->position.z, game->camera->up.x, game->camera->up.y, game->camera->up.z); writeDebugText("Camera position: %0.0f %0.0f %0.0f ", game->camera->position.x, game->camera->position.y, game->camera->position.z); //writeDebugText("Camera look: %0.2f %0.2f %0.2f ", game->camera->lookAt.x, game->camera->lookAt.y, game->camera->lookAt.z); static vector<GameObject*> objects_for_drawing; static vector<GOLight*> lights; static vector<GameObject*> opaque_objects; static vector<GameObject*> transparent_objects; static vector<GameObject*> _2d_objects; objects_for_drawing.clear(); lights.clear(); opaque_objects.clear(); transparent_objects.clear(); _2d_objects.clear(); for (unsigned int i = 0; i < game->objects.size(); i++ ) { if (game->objects.at(i)->getNeedDraw()) { objects_for_drawing.push_back(game->objects.at(i)); } } if (Game::instance->drawBBoxes) { if (renderFilter) { renderFilter->debugDraw(); for (unsigned int i = 0; i < objects_for_drawing.size(); i++ ) { GameObject* o = objects_for_drawing.at(i); renderFilter->debugObjectDraw(o); } } else { for (unsigned int i = 0; i < objects_for_drawing.size(); i++ ) { drawBBox(objects_for_drawing.at(i)->getBBox()); } } } for (unsigned int i = 0; i < objects_for_drawing.size(); i++ ) { if (objects_for_drawing.at(i)->type == GO_LIGHT) { lights.push_back((GOLight*)objects_for_drawing.at(i)); } else if (objects_for_drawing.at(i)->is2D) { _2d_objects.push_back(objects_for_drawing.at(i)); } else if (objects_for_drawing.at(i)->opaque) { opaque_objects.push_back(objects_for_drawing.at(i)); } else { transparent_objects.push_back(objects_for_drawing.at(i)); } } if (renderFilter && !Game::instance->editorMode) { opaque_objects = renderFilter->doFilter(opaque_objects); transparent_objects = renderFilter->doFilter(transparent_objects); } game->drawnObjectsCount = opaque_objects.size(); game->drawnObjectsCount += transparent_objects.size(); game->drawnObjectsCount += _2d_objects.size(); sort(transparent_objects.begin(), transparent_objects.end(), sortTransparent); for (unsigned int i = 0; i < lights.size(); i++ ) { lights.at(i)->draw(); } for (unsigned int i = 0; i < opaque_objects.size(); i++ ) { opaque_objects.at(i)->draw(); //writeDebugText("Type: %i, id: %s, z:%f", opaque_objects.at(i)->type, opaque_objects.at(i)->id.c_str(), opaque_objects.at(i)->position.z); } game->transparentObjectsCount = transparent_objects.size(); for (unsigned int i = 0; i < transparent_objects.size(); i++ ) { transparent_objects.at(i)->draw(); //writeDebugText("Type: %i, id: %s, z:%f", transparent_objects.at(i)->type, transparent_objects.at(i)->id.c_str(), (transparent_objects.at(i)->position - game->camera->position).Length()); } if (game->debugPhysDraw) { if (game->debugPhysDrawIn2D) start2D(); game->dynamicsWorld->debugDrawWorld(); if (game->debugPhysDrawIn2D) end2D(); } // Ligt reset for (unsigned int i = 0; i < lights.size(); i++ ) { lights.at(i)->cancel(); } #ifndef OPENGL_ES // for drawibg texts glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); #endif // save previous state of lighting bool lightingEnabled = glIsEnabled(GL_LIGHTING); glDisable(GL_LIGHTING); // Write 2D stuff start2D(); // sort Z sort(_2d_objects.begin(), _2d_objects.end(), sort2D); game->_2dObjectsCount = _2d_objects.size(); for (unsigned int i = 0; i < _2d_objects.size(); i++ ) { _2d_objects.at(i)->draw(); //writeDebugText("Type: %i, id: %s, z:%f", opaque_objects.at(i)->type, opaque_objects.at(i)->id.c_str(), opaque_objects.at(i)->position.z); } // Draw debug texts for (unsigned int i = 0; i < debugStrings.size(); i++ ) { if (game->drawDebugText && !game->console->isOpened()) { std::pair <float, float>* size = new std::pair <float, float>(); standart14Normal->GetStringSize(debugStrings.at(i).c_str(), size); static GOPlate* p = new GOPlate(); p->setPositioningMode(GOPositioningModeTopLeft); p->color = MGColor(0.0f,0.0f,0.0f,0.4f); int h = (int)(size->second * 1.00); p->setSize(CVector(size->first, h)); p->setPosition(CVector(5.0f, game->osAdapter->getScreenHeight() - (h * i))); p->draw(); writeText(debugStrings.at(i), CVector(5.0f, game->osAdapter->getScreenHeight() - (h * i), 0.0f), STANDART_14_NORMAL, MGColor(0.0f, 1.0f, 0.0f, 1.0f)); } } debugStrings.clear(); game->luaVM->doString("_onDraw2D()"); end2D(); if (lightingEnabled) { glEnable(GL_LIGHTING); } else { glDisable(GL_LIGHTING); } }