void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos, const TileSpec tiles[]) { // Texture u8 texid = myrand_range(0, 5); video::ITexture *texture; struct TileAnimationParams anim; anim.type = TAT_NONE; // Only use first frame of animated texture if (tiles[texid].material_flags & MATERIAL_FLAG_ANIMATION) texture = tiles[texid].frames[0].texture; else texture = tiles[texid].texture; float size = rand() % 64 / 512.; float visual_size = BS * size; v2f texsize(size * 2, size * 2); v2f texpos; texpos.X = ((rand() % 64) / 64. - texsize.X); texpos.Y = ((rand() % 64) / 64. - texsize.Y); // Physics v3f velocity((rand() % 100 / 50. - 1) / 1.5, rand() % 100 / 35., (rand() % 100 / 50. - 1) / 1.5); v3f acceleration(0,-9,0); v3f particlepos = v3f( (f32) pos.X + rand() %100 /200. - 0.25, (f32) pos.Y + rand() %100 /200. - 0.25, (f32) pos.Z + rand() %100 /200. - 0.25 ); Particle* toadd = new Particle( gamedef, smgr, player, m_env, particlepos, velocity, acceleration, rand() % 100 / 100., // expiration time visual_size, true, false, false, texture, texpos, texsize, anim, 0); addParticle(toadd); }
void UnitTrackingMarker::RenderTrackingMarker(BillboardTextureShape* renderer) { if (_meleeTarget == nullptr) { glm::vec2 destination = DestinationXXX(); glm::vec3 position = _battleView->GetBattleSimulator()->GetBattleMap()->GetHeightMap()->GetPosition(destination, 0); glm::vec2 texsize(0.1875, 0.1875); // 48 / 256 glm::vec2 texcoord = texsize * glm::vec2(_unit->GetTeam() == _battleView->GetCommander()->GetTeam() ? 2 : 0, 2); renderer->AddBillboard(position, 32, affine2(texcoord, texcoord + texsize)); } }
void ParticleManager::addNodeParticle(IGameDef* gamedef, LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f) { // No particles for "airlike" nodes if (f.drawtype == NDT_AIRLIKE) return; // Texture u8 texid = myrand_range(0, 5); const TileLayer &tile = f.tiles[texid].layers[0]; video::ITexture *texture; struct TileAnimationParams anim; anim.type = TAT_NONE; // Only use first frame of animated texture if (tile.material_flags & MATERIAL_FLAG_ANIMATION) texture = (*tile.frames)[0].texture; else texture = tile.texture; float size = (rand() % 8) / 64.0f; float visual_size = BS * size; if (tile.scale) size /= tile.scale; v2f texsize(size * 2.0f, size * 2.0f); v2f texpos; texpos.X = (rand() % 64) / 64.0f - texsize.X; texpos.Y = (rand() % 64) / 64.0f - texsize.Y; // Physics v3f velocity( (rand() % 150) / 50.0f - 1.5f, (rand() % 150) / 50.0f, (rand() % 150) / 50.0f - 1.5f ); v3f acceleration( 0.0f, -player->movement_gravity * player->physics_override_gravity / BS, 0.0f ); v3f particlepos = v3f( (f32)pos.X + (rand() % 100) / 200.0f - 0.25f, (f32)pos.Y + (rand() % 100) / 200.0f - 0.25f, (f32)pos.Z + (rand() % 100) / 200.0f - 0.25f ); video::SColor color; if (tile.has_color) color = tile.color; else n.getColor(f, &color); Particle* toadd = new Particle( gamedef, player, m_env, particlepos, velocity, acceleration, (rand() % 100) / 100.0f, // expiration time visual_size, true, false, false, false, texture, texpos, texsize, anim, 0, color); addParticle(toadd); }
void Texture::beginUse(RenderContext* renderContext) { if (!texName) { glGenTextures(1, &texName); glBindTexture(GL_TEXTURE_2D, texName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minfilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magfilter); GLint internalFormat = 0; GLenum format = 0; GLint ualign; unsigned int bytesperpixel = 0; switch(type) { case ALPHA: internalFormat = GL_ALPHA; break; case LUMINANCE: internalFormat = GL_LUMINANCE; break; case LUMINANCE_ALPHA: internalFormat = GL_LUMINANCE_ALPHA; break; case RGB: internalFormat = GL_RGB; break; case RGBA: internalFormat = GL_RGBA; break; } switch(pixmap->typeID) { case GRAY8: ualign = 1; bytesperpixel = 1; switch(internalFormat) { case GL_LUMINANCE: format = GL_LUMINANCE; break; case GL_ALPHA: format = GL_ALPHA; break; case GL_LUMINANCE_ALPHA: format = GL_LUMINANCE; break; } break; case RGB24: ualign = 1; format = GL_RGB; bytesperpixel = 3; break; case RGB32: ualign = 2; format = GL_RGB; bytesperpixel = 4; break; case RGBA32: ualign = 2; format = GL_RGBA; bytesperpixel = 4; break; default: // INVALID return; } glPixelStorei(GL_UNPACK_ALIGNMENT, ualign); GLenum gl_type = GL_UNSIGNED_BYTE; unsigned int maxSize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, (int*) &maxSize); if (mipmap) { int gluError = gluBuild2DMipmaps(GL_TEXTURE_2D, internalFormat, pixmap->width, pixmap->height, format, gl_type, pixmap->data); if (gluError) printGluErrorMessage(gluError); } else { unsigned int width = texsize(pixmap->width); unsigned int height = texsize(pixmap->height); if ( (width > maxSize) || (height > maxSize) ) { char buf[256]; sprintf(buf, "GL Library : Maximum texture size of %dx%d exceeded.\n(Perhaps enabling mipmapping could help.)", maxSize,maxSize); printMessage(buf); } else if ( (pixmap->width != width) || ( pixmap->height != height) ) { char* data = new char[width * height * bytesperpixel]; int gluError = gluScaleImage(format, pixmap->width, pixmap->height, gl_type, pixmap->data, width, height, gl_type, data); if (gluError) printGluErrorMessage(gluError); glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, gl_type , data); delete[] data; } else { glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, pixmap->width, pixmap->height, 0, format, gl_type , pixmap->data); } } delete pixmap; pixmap = NULL; } glPushAttrib(GL_TEXTURE_BIT|GL_ENABLE_BIT|GL_CURRENT_BIT); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, texName); if (type == ALPHA) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // glBlendFunc(GL_SRC_ALPHA, GL_ONE); } }