//---------------------------------------------------------------------- TexOGL* Textures::createFloatCheck(float base, float incr) { if (data_type != GL_FLOAT) { printf("createBWNoise: data_type should be GL_FLOAT\n"); return 0; } if (nb_internal_channels != 4) { printf("Textures::createFloatCheck, only works for 4-channel textures\n"); exit(0); } TexOGL* t = new TexOGL(); TexOGL& input = *t; Array3D tex(4, nx, ny); for (int j = 0; j < ny; j++) { for (int i = 0; i < nx; i++) { tex(0, i, j) = base + i*incr; tex(1, i, j) = base + j*incr; tex(2, i, j) = 0.; tex(3, i, j) = base + i*incr; } } input.init_targ(nx, ny, target); input.load(internal_format, format, data_type, tex.getDataPtr()); input.clamp(); input.point(); return t; }
TexOGL* Textures::createBWNoise() { // ONLY FOR GL_FLOAT datatype if (data_type != GL_FLOAT) { printf("createBWNoise: data_type should be GL_FLOAT\n"); return 0; } float val, p; TexOGL* t = new TexOGL(); TexOGL& input = *t; Array3D tex(nb_internal_channels, nx, ny); for (int j = 0; j < ny; j++) { for (int i = 0; i < nx; i++) { p = u.rand_float(); val = (p < 0.5) ? 0 : 1.; for (int k = 0; k < nb_internal_channels; k++) { tex(k, i, j) = val; } if (nb_internal_channels == 4) { tex(3, i, j) = 1.0; } }} input.init_targ(nx, ny, target); input.load(internal_format, format, data_type, tex.getDataPtr()); input.clamp(); input.point(); return t; }
TexOGL* Textures::createGrayNoiseRGBA() { // ONLY FOR GL_FLOAT datatype float val, p; TexOGL* t = new TexOGL(); TexOGL& input = *t; Array3D tex(nb_internal_channels, nx, ny); for (int j = 0; j < ny; j++) { for (int i = 0; i < nx; i++) { for (int k=0; k < nb_internal_channels; k++) { tex(k, i, j) = u.rand_float(); } if (nb_internal_channels == 4) { tex(3, i, j) = 1.0; } }} input.init_targ(nx, ny, target); input.load(internal_format, format, data_type, tex.getDataPtr()); input.clamp(); input.point(); return t; }
//---------------------------------------------------------------------- TexOGL* Textures::createOneColor(float r, float g, float b, float a) { if (data_type != GL_FLOAT) { printf("createBWNoise: data_type should be GL_FLOAT\n"); return 0; } if (nb_internal_channels != 4) { printf("Textures::createOneColorNoise, only works for 4-channel textures\n"); exit(0); } float val, p; TexOGL* t = new TexOGL(); TexOGL& input = *t; Array3D tex(4, nx, ny); for (int j = 0; j < ny; j++) { for (int i = 0; i < nx; i++) { tex(0, i, j) = r; tex(1, i, j) = g; tex(2, i, j) = b; tex(3, i, j) = a; } } input.init_targ(nx, ny, target); input.load(internal_format, format, data_type, tex.getDataPtr()); input.clamp(); input.point(); return t; }
void Mesh::render(const vec3b& color, bool texturing, bool selected) const { bool use_texture = texturing && !tex_coord.empty(); glEnable(GL_NORMALIZE); glEnable(GL_LIGHTING); if (use_texture) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture_id); } auto& mesh = *this; auto triangles = mesh.triangles; triangles << top_cover.triangles; triangles << bottom_cover.triangles; glBegin(GL_TRIANGLES); for (auto& tri : triangles) { if (selected) glColor3ub(255, 0, 0); else if (use_texture) glColor3ub(255, 255, 255); else glColor3ubv(color.coords); glNormal3dv(tri.normal.coords); if (use_texture) glTexCoord2dv(tex(tri[0]).coords); glVertex3iv(mesh[tri[0]].coords); glNormal3dv(tri.normal.coords); if (use_texture) glTexCoord2dv(tex(tri[1]).coords); glVertex3iv(mesh[tri[1]].coords); glNormal3dv(tri.normal.coords); if (use_texture) glTexCoord2dv(tex(tri[2]).coords); glVertex3iv(mesh[tri[2]].coords); } glEnd(); if (use_texture) { glDisable(GL_TEXTURE_2D); } glDisable(GL_LIGHTING); glDisable(GL_NORMALIZE); #ifndef NDEBUG if (selected && use_texture) { glLineWidth(5); glColor3d(1, 0, 0); glBegin(GL_LINE_STRIP); for(auto &e: anchor_points) glVertex2iv(e[0].coords); glEnd(); glBegin(GL_LINE_STRIP); for (auto &e: anchor_points) glVertex2iv(e[1].coords); glEnd(); glLineWidth(1); } #endif glColor3d(1, 1, 1); }
void CTextureAtlas::CreateTexture() { const int2 atlasSize = atlasAllocator->GetAtlasSize(); PBO pbo; pbo.Bind(); pbo.Resize(atlasSize.x * atlasSize.y * 4); unsigned char* data = (unsigned char*)pbo.MapBuffer(GL_WRITE_ONLY); { // make spacing between textures black transparent to avoid ugly lines with linear filtering std::memset(data, 0, atlasSize.x * atlasSize.y * 4); for (std::vector<MemTex*>::iterator it = memtextures.begin(); it != memtextures.end(); ++it) { const float4 texCoords = atlasAllocator->GetTexCoords((*it)->names[0]); const float4 absCoords = atlasAllocator->GetEntry((*it)->names[0]); const int xpos = absCoords.x; const int ypos = absCoords.y; AtlasedTexture tex(texCoords); for (size_t n = 0; n < (*it)->names.size(); ++n) { textures[(*it)->names[n]] = tex; } for (int y = 0; y < (*it)->ysize; ++y) { int* dst = ((int*)data) + xpos + (ypos + y) * atlasSize.x; int* src = ((int*)(*it)->data) + y * (*it)->xsize; memcpy(dst, src, (*it)->xsize * 4); } } if (debug) { CBitmap tex(data, atlasSize.x, atlasSize.y); tex.Save(name + "-" + IntToString(atlasSize.x) + "x" + IntToString(atlasSize.y) + ".png"); } } pbo.UnmapBuffer(); const int maxMipMaps = atlasAllocator->GetMaxMipMaps(); glGenTextures(1, &atlasTexID); glBindTexture(GL_TEXTURE_2D, atlasTexID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (maxMipMaps > 0) ? GL_LINEAR_MIPMAP_NEAREST : GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, maxMipMaps); if (maxMipMaps > 0) { glBuildMipmaps(GL_TEXTURE_2D, GL_RGBA8, atlasSize.x, atlasSize.y, GL_RGBA, GL_UNSIGNED_BYTE, pbo.GetPtr()); //FIXME disable texcompression //FIXME 2 PBO!!!! } else { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, atlasSize.x, atlasSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, pbo.GetPtr()); } pbo.Unbind(); initialized = true; }
///output operator ostream& StatSample::print_tex (ostream& os, const string title) const { bool weightMode = _weight->nevents() > 0 ? true : false ; os << "" << endl; os << "% Efficiency table %" << endl; os << "" << endl; os << "\\begin{table}[p]" << endl; os << "\\begin{center}" << endl; os << "\\begin{tabular}{lrrr" ; if (weightMode) os << "r" ; os << "}" << endl; os << " \\hline \\hline" << endl; os << " Selection & Events & Relative & Total " ; if (weightMode) os << "& Total Corrected by Event Weights " ; os << "\\\\ \\hline" << endl; os << tex(eventSelection(0)->name()) << " & " ; os << nevents(0) << " & & " ; if (weightMode) os << " & " ; os << "\\\\ " << endl ; for (unsigned int n = 1; n < size() ; n++) { os << tex(eventSelection(n)->name()) << " & " ; os << nevents(n) << " & "; if (eventSelection(n)->isWeight()) { os << " $\\mathit{ " << eff(n) << " \\pm " << effErr(n) << " }$ & & " ; if (weightMode) os << " & " ; } else { os << " $ " << 100.0*eff(n) << " \\pm " << 100.0*effErr(n) << " ~\\% $ & " ; os << " $ " << 100.0*effGlob(n) << " \\pm " << 100.0*effErrGlob(n) << "~\\% $ " ; if (weightMode) os << " $ " << 100.0*correctedEfficiency(n) << " \\pm " << 100.0*correctedEffErr(n) << "~\\% $ " ; } os << " \\\\ " << endl ; } os << " \\hline " << endl; os << " \\hline" << endl; os << " \\end{tabular}" << endl; os << " \\caption{" << title << " Sample " << name() << " }" << endl; os << " \\label{Table:" << title.c_str() << ":" << name() << "}" << endl; os << "\\end{center}" << endl; os << "\\end{table}" << endl; os << endl; return os ; }
const AnimationData* ResourceLoader::anim(string name) { auto anim = animations.find(name); if (anim == animations.end()) { pugi::xml_document animXml; string path = root + name; animXml.load_file(path.c_str()); if (animXml.begin() == animXml.end()) { // Couldn't open .anim file! std::cerr << "ERROR: couldn't load animation \"" << path << "\"\n"; return &AnimationData::defaultAnim; } pugi::xml_node node = animXml.child("animations"); string sheetName = animXml.first_child().first_attribute().as_string(); const SpriteSheet* sheet = sh(sheetName); if (sheet == nullptr) { std::cerr << "\t(requested by \"" << path << "\")\n"; return &AnimationData::defaultAnim; } AnimationData& aData = animations[name]; if (!loadAnimData(aData, animXml, sheet)) { animations.erase(animations.find(name)); std::cerr << "\t(requested by \"" << path << "\")\n"; return &AnimationData::defaultAnim; } const sf::Texture* texture = tex(sheet->imageName); if (texture == nullptr) { std::cerr << "\t(requested by \"" << path << "\")\n"; return &AnimationData::defaultAnim; } aData.tx = texture; return &aData; } return &anim->second; }
void Q3BSPRep::createTextures(){ int n_texs=header.dir[1].length/sizeof(q3_tex); q3_tex *q3tex=(q3_tex*)header.dir[1].lump; for( int k=0;k<n_texs;++k ){ string t=string(q3tex->name); char fl[32],co[32]; itoa( q3tex->flags,fl,16 ); itoa( q3tex->contents,co,16 ); log( t+", flags=0x"+fl+", contents=0x"+co ); Texture tex( t+".tga",1 ); if( !tex.getCanvas(0) ){ tex=Texture( t+".jpg",1 ); if( !tex.getCanvas(0) ){ tex=Texture( t+".png",1 ); if( !tex.getCanvas(0) ){ tex=Texture( t+".dds",1 ); if( !tex.getCanvas(0) ) log( "Failed!" ); } } } tex.setFlags( 1 ); textures.push_back( tex ); ++q3tex; } }
std::shared_ptr<gge::texture> piece_pattern::make_texture() const { const int width = MAX_PIECE_COLS*BLOCK_SIZE; const int height = MAX_PIECE_ROWS*BLOCK_SIZE; gge::pixmap<gge::pixel_type::GRAY> pm(width, height); uint8_t *bits = &pm.data[0]; for (int r = 0; r < MAX_PIECE_ROWS; r++) { for (int c = 0; c < MAX_PIECE_COLS; c++) { if (pattern[r][c] != '#') continue; bool left = c > 0 && pattern[r][c - 1] == '#'; bool right = c < MAX_PIECE_COLS - 1 && pattern[r][c + 1] == '#'; bool up = r > 0 && pattern[r - 1][c] == '#'; bool down = r < MAX_PIECE_ROWS - 1 && pattern[r + 1][c] == '#'; draw_block(&bits[BLOCK_SIZE*(r*width + c)], width, left, right, up, down); } } std::shared_ptr<gge::texture> tex(new gge::texture); tex->load(pm); return tex; }
//-------------------------------------------------------------- void testApp::draw(){ ofBackground(0, 0, 0); ofSetColor(255, 255, 255); ofPoint ps[4], tps[4]; ps[0].set(0, 100); ps[1].set(600, 0); ps[2].set(600, 300); ps[3].set(300, 400); tps[0].set(0, 100); tps[1].set(600, 0); tps[2].set(600, 300); tps[3].set(300, 400); ofFbo fbo; fbo.allocate(600, 600); fbo.begin(); ofBackground(0, 0, 0); ofSetColor(255, 255, 255); for(int i = 0; i < 20; i++) { ofLine(0, 30 * i, 600, 30 * i); ofLine(30 * i, 0, 30 * i, 600); } fbo.end(); ofxTBTexture tex(fbo.getTextureReference()); // tex.draw(ps[0], ps[1], ps[2], ps[3], ofRectangle(0, 0, 400, 400)); tex.draw(ps, tps); }
void Water::createSimpleWaterStateSet(osg::Node* node, float alpha) { osg::ref_ptr<osg::StateSet> stateset = SceneUtil::createSimpleWaterStateSet(alpha, MWRender::RenderBin_Water); node->setStateSet(stateset); // Add animated textures std::vector<osg::ref_ptr<osg::Texture2D> > textures; int frameCount = mFallback->getFallbackInt("Water_SurfaceFrameCount"); std::string texture = mFallback->getFallbackString("Water_SurfaceTexture"); for (int i=0; i<frameCount; ++i) { std::ostringstream texname; texname << "textures/water/" << texture << std::setw(2) << std::setfill('0') << i << ".dds"; osg::ref_ptr<osg::Texture2D> tex (new osg::Texture2D(mResourceSystem->getImageManager()->getImage(texname.str()))); tex->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); tex->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT); textures.push_back(tex); } if (textures.empty()) return; float fps = mFallback->getFallbackFloat("Water_SurfaceFPS"); osg::ref_ptr<NifOsg::FlipController> controller (new NifOsg::FlipController(0, 1.f/fps, textures)); controller->setSource(boost::shared_ptr<SceneUtil::ControllerSource>(new SceneUtil::FrameTimeSource)); node->setUpdateCallback(controller); stateset->setTextureAttributeAndModes(0, textures[0], osg::StateAttribute::ON); }
BowlingBall::BowlingBall(const vec3& position) { //Setting up renderer KMTexture tex("ball_diffuse.png"); auto ballVertices = KMVertex::loadFromObj("ball.obj"); auto mat = std::make_shared<KMMaterialTextureDiffuse>(tex); _renderer = std::make_shared<KMRendererMesh>(mat, ballVertices); //Setting up physics body btCollisionShape* shape = createShape(); btScalar bodyMass = 10.0f; btVector3 bodyInertia; shape->calculateLocalInertia(bodyMass, bodyInertia); btTransform trasn; trasn.setIdentity(); trasn.setOrigin(btVector3(position.x, position.y, position.z)); btDefaultMotionState *motionState = new btDefaultMotionState(trasn); btRigidBody::btRigidBodyConstructionInfo bodyCI = btRigidBody::btRigidBodyConstructionInfo(bodyMass, motionState, shape, bodyInertia); _physicsBody = std::unique_ptr<btRigidBody>(new btRigidBody(bodyCI)); _physicsBody->setUserPointer(this); _physicsBody->setRestitution(0.6f); _physicsBody->setFriction(.1f); // _physicsBody->setRollingFriction(.2f); // _physicsBody->setAnisotropicFriction(shape->getAnisotropicRollingFrictionDirection(),btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION); }
BowlingPin::BowlingPin(const vec3& position) { //Setting up renderer KMTexture tex("pin_diffuse.png"); auto pinVertices = cachedVertices(); auto mat = std::make_shared<KMMaterialTextureDiffuse>(tex); _renderer = std::make_shared<KMRendererMesh>(mat, pinVertices); //Setting up physics body btCollisionShape* shape = createShape(pinVertices); btScalar bodyMass = 1.6f; btVector3 bodyInertia(0,0,0); shape->calculateLocalInertia(bodyMass, bodyInertia); btTransform trasn; trasn.setIdentity(); trasn.setOrigin(btVector3(position.x, position.y, position.z)); btDefaultMotionState *motionState = new btDefaultMotionState(trasn); btRigidBody::btRigidBodyConstructionInfo bodyCI = btRigidBody::btRigidBodyConstructionInfo(bodyMass, motionState, shape, bodyInertia); bodyCI.m_restitution = 0.7f; bodyCI.m_friction = 0.9f; _physicsBody = std::unique_ptr<btRigidBody>(new btRigidBody(bodyCI)); _physicsBody->setUserPointer(this); //_physicsBody->setDeactivationTime(0.0f); //_physicsBody->setDamping(0.1f, 0.2f); //_physicsBody->setAnisotropicFriction(shape->getAnisotropicRollingFrictionDirection(),btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION); }
int get_tex(t_env *env) { t_img *img; int i; char *tab[10]; int x2; int y2; tex(tab); i = 0; while (i < 10) { x2 = 0; y2 = 0; env->img[i] = (t_img *)malloc(sizeof(t_img)); img = env->img[i]; if (!(img->img = mlx_xpm_file_to_image(env->ptr, tab[i], &x2, &y2))) exit(0); if (!(img->data = mlx_get_data_addr(img->img, &(img->bpp), &(img->sizel), &(img->endian)))) exit(0); i++; } return (0); }
void CheatDrawText() { if(sp_max_start == PlatformInstant_ZERO) return; PlatformDuration elapsed = g_platformTime.frameStart() - sp_max_start; if(sp_max_start != PlatformInstant_ZERO && elapsed < PlatformDurationMs(20000)) { float modi = float(toMs(PlatformDurationMs(20000) - elapsed)) * ( 1.0f / 2000 ) * ( 1.0f / 10 ); float sizX = 16; Vec2f p = Vec2f(g_size.center()); p.x -= sp_max_ch.length() * ( 1.0f / 2 ) * sizX; for(size_t i = 0; i < sp_max_ch.length(); i++) { Vec2f d = p + Vec2f(sizX * i, sp_max_y[i]); sp_max_y[i] = std::sin(d.x + arxtime.now_f() * ( 1.0f / 100 )) * 30.f * modi; std::string tex(1, sp_max_ch[i]); UNICODE_ARXDrawTextCenter(hFontInBook, d + Vec2f(-1,-1), tex, Color::none); UNICODE_ARXDrawTextCenter(hFontInBook, d + Vec2f( 1, 1), tex, Color::none); UNICODE_ARXDrawTextCenter(hFontInBook, d, tex, sp_max_col[i]); } } }
GLuint RendererGL::get_gl(SDL_Surface * surf ) { GLenum format; GLint colors_amount = surf->format->BytesPerPixel; GLuint tex( 0 ); if (colors_amount == 4) { if (surf->format->Rmask == 0x000000ff) format = GL_RGBA; else format = GL_BGRA; } else if (colors_amount == 3) { if (surf->format->Rmask == 0x000000ff) format = GL_RGB; else format = GL_BGR; } else { gCritical("Image is not truecolor"); } glGenTextures( 1, &tex ); glBindTexture( GL_TEXTURE_2D, tex ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D( GL_TEXTURE_2D, 0, colors_amount, surf->w, surf->h, 0, format, GL_UNSIGNED_BYTE, surf->pixels ); return tex; }
std::unique_ptr<DXTexture> DXTexture::Create(const TextureConfig& config) { // Use typeless to create the texture when it's a render target, so we can alias it with an // integer format (for EFB). const DXGI_FORMAT tex_format = D3DCommon::GetDXGIFormatForAbstractFormat(config.format, config.IsRenderTarget()); UINT bindflags = D3D11_BIND_SHADER_RESOURCE; if (config.IsRenderTarget()) bindflags |= IsDepthFormat(config.format) ? D3D11_BIND_DEPTH_STENCIL : D3D11_BIND_RENDER_TARGET; if (config.IsComputeImage()) bindflags |= D3D11_BIND_UNORDERED_ACCESS; CD3D11_TEXTURE2D_DESC desc(tex_format, config.width, config.height, config.layers, config.levels, bindflags, D3D11_USAGE_DEFAULT, 0, config.samples, 0, 0); ComPtr<ID3D11Texture2D> d3d_texture; HRESULT hr = D3D::device->CreateTexture2D(&desc, nullptr, &d3d_texture); if (FAILED(hr)) { PanicAlert("Failed to create %ux%ux%u D3D backing texture", config.width, config.height, config.layers); return nullptr; } std::unique_ptr<DXTexture> tex(new DXTexture(config, d3d_texture.Get())); if (!tex->CreateSRV() || (config.IsComputeImage() && !tex->CreateUAV())) return nullptr; return tex; }
void setup_plastic_with_texture(void) { boost::shared_ptr<shade::shaders::Plastic> specular(new shade::shaders::Plastic(0.7, .3)); boost::shared_ptr<shade::shaders::ObjectSpace> object_space(new shade::shaders::ObjectSpace); boost::shared_ptr<shade::shaders::Texture2D> tex(new shade::shaders::Texture2D); tex->texture_unit.set(example::make_texture("examples/pattern.dds")); boost::shared_ptr<shade::shaders::UVCoord> uvcoord(new shade::shaders::UVCoord); tex->uv = uvcoord; specular->color = tex; specular->coordinate_system = object_space; shader->material = specular; { shaders::IlluminatedMaterial::LightList::Accessor accessor(specular->lights); boost::shared_ptr<shaders::PointLight> light(new shaders::PointLight); light->position.set_value(shade::vec3<>(30., 15., 10.)); light->color.set_value(shade::vec3<>(1., 1., 1.)); accessor->push_back(light); boost::shared_ptr<shaders::PointLight> light2(new shaders::PointLight); light2->position.set_value(shade::vec3<>(-15., -3, 0.)); light2->color.set_value(shade::vec3<>(1., 1., 1.)); accessor->push_back(light2); } }
void MovieGlHap::draw() { updateFrame(); mObj->lock(); if( mObj->mTexture ) { Rectf centeredRect = Rectf( mObj->mTexture->getCleanBounds() ).getCenteredFit( app::getWindowBounds(), true ); gl::color( Color::white() ); auto drawRect = [&]() { gl::ScopedTextureBind tex( mObj->mTexture ); float cw = mObj->mTexture->getCleanWidth(); float ch = mObj->mTexture->getCleanHeight(); float w = mObj->mTexture->getWidth(); float h = mObj->mTexture->getHeight(); gl::drawSolidRect( centeredRect, vec2( 0, 0 ), vec2( cw / w, ch / h ) ); }; if( isHapQ() ) { gl::ScopedGlslProg bind( MovieGlHap::Obj::sHapQShader ); drawRect(); } else { gl::ScopedGlslProg bind( mObj->mDefaultShader ); drawRect(); } } mObj->unlock(); }
bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, SkBitmap* result, SkIPoint* offset) { #if SK_SUPPORT_GPU SkBitmap input; if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &input, offset)) { return false; } GrTexture* source = input.getTexture(); SkIRect rect; src.getBounds(&rect); if (!this->applyCropRect(&rect, ctm)) { return false; } SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext(), source, false, SkRect::Make(rect), true, fSigma.width(), fSigma.height())); offset->fX += rect.fLeft; offset->fY += rect.fTop; return SkImageFilterUtils::WrapTexture(tex, rect.width(), rect.height(), result); #else SkDEBUGFAIL("Should not call in GPU-less build"); return false; #endif }
SpriteSheet::SpriteSheetPtr SpriteSheet::from_json(const char* sprite_sheet_filename, const char* texture_filename) { TexturePtr tex(new sf::Texture()); if( !tex->loadFromFile(texture_filename) ) { return nullptr; } rapidjson::Document d; d.Parse(load_text_file_content(sprite_sheet_filename).c_str()); SpriteSheetPtr ss(new SpriteSheet(tex)); const rapidjson::Value& frames = d["frames"]; for(auto f=frames.Begin(); f != frames.End(); ++f) { auto rotation = (*f)["rotated"].GetBool() ? FrameInfo::Rotation::CW : FrameInfo::Rotation::None; const rapidjson::Value& frame = (*f)["frame"]; auto x = frame["x"].GetInt(); auto y = frame["y"].GetInt(); auto width = frame["w"].GetInt(); auto height = frame["h"].GetInt(); ss->add_frame_rect(sf::IntRect(x, y, width, height), rotation); } return ss; }
void CheatDrawText() { if(sp_max_start == 0) { return; } PlatformDuration elapsed = g_platformTime.frameStart() - sp_max_start; if(elapsed < PlatformDurationMs(20000)) { float modi = (PlatformDurationMs(20000) - elapsed) / PlatformDurationMs(2000) * 0.1f; float sizX = 16; Vec2f p = Vec2f(g_size.center()); p.x -= sp_max_ch.length() * 0.5f * sizX; for(size_t i = 0; i < sp_max_ch.length(); i++) { Vec2f d = p + Vec2f(sizX * i, sp_max_y[i]); sp_max_y[i] = std::sin(d.x + elapsed / PlatformDurationMs(100)) * 30.f * modi; std::string tex(1, sp_max_ch[i]); UNICODE_ARXDrawTextCenter(hFontInGame, d + Vec2f(-1, -1), tex, Color::none); UNICODE_ARXDrawTextCenter(hFontInGame, d + Vec2f(1, 1), tex, Color::none); UNICODE_ARXDrawTextCenter(hFontInGame, d, tex, sp_max_col[i]); } } }
void BlackHole::Draw() { auto l1Factor = math<float>::sin(mElapsed*mV.x*kColorScale); l1Factor = (l1Factor + 1.0f)*0.5f; auto l2Factor = math<float>::cos(mElapsed*mV.y*kColorScale); l2Factor = (l1Factor + 1.0f)*0.5f; auto l3Factor = math<float>::sin(mElapsed*mV.z*kColorScale); l3Factor = (l1Factor + 1.0f)*0.5f; vec3 color1 = lerp<vec3>(mD1.first, mD1.second, l1Factor); vec3 color2 = lerp<vec3>(mD2.first, mD2.second, l2Factor); vec3 color3 = lerp<vec3>(mD3.first, mD3.second, l3Factor); gl::color(Color::white()); { gl::ScopedGlslProg shader(mShader); gl::ScopedTextureBind tex(mTexMain, 0); mShader->uniform("TexOffset", mElapsed*kTimeScale); mShader->uniform("u_Intens",mK); mShader->uniform("u_Scales", mS); mShader->uniform("u_Speeds", mV); mShader->uniform("u_Color1", color1); mShader->uniform("u_Color2", color2); mShader->uniform("u_Color3", color3); gl::draw(mMesh); } }
void Layer::onDraw(const Region& clip) const { Texture tex(mBufferManager.getActiveTexture()); if (tex.name == -1LU) { // the texture has not been created yet, this Layer has // in fact never been drawn into. This happens frequently with // SurfaceView because the WindowManager can't know when the client // has drawn the first time. // If there is nothing under us, we paint the screen in black, otherwise // we just skip this update. // figure out if there is something below us Region under; const SurfaceFlinger::LayerVector& drawingLayers(mFlinger->mDrawingState.layersSortedByZ); const size_t count = drawingLayers.size(); for (size_t i=0 ; i<count ; ++i) { const sp<LayerBase>& layer(drawingLayers[i]); if (layer.get() == static_cast<LayerBase const*>(this)) break; under.orSelf(layer->visibleRegionScreen); } // if not everything below us is covered, we plug the holes! Region holes(clip.subtract(under)); if (!holes.isEmpty()) { clearWithOpenGL(holes, 0, 0, 0, 1); } return; } drawWithOpenGL(clip, tex); }
bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx, SkBitmap* result, SkIPoint* offset) const { #if SK_SUPPORT_GPU SkBitmap input = src; SkIPoint srcOffset = SkIPoint::Make(0, 0); if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) { return false; } SkIRect rect; if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &rect, &input)) { return false; } GrTexture* source = input.getTexture(); SkVector sigma = SkVector::Make(fSigma.width(), fSigma.height()); ctx.ctm().mapVectors(&sigma, 1); sigma.fX = SkMinScalar(sigma.fX, MAX_SIGMA); sigma.fY = SkMinScalar(sigma.fY, MAX_SIGMA); offset->fX = rect.fLeft; offset->fY = rect.fTop; rect.offset(-srcOffset); SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext(), source, false, SkRect::Make(rect), true, sigma.x(), sigma.y())); WrapTexture(tex, rect.width(), rect.height(), result); return true; #else SkDEBUGFAIL("Should not call in GPU-less build"); return false; #endif }
MH_STATUS ApplyQueued() { CriticalSection::ScopedLock lock(*gCS); if (!gIsInitialized) { return MH_ERROR_NOT_INITIALIZED; } std::vector<uintptr_t> oldIPs; std::vector<uintptr_t> newIPs; for (size_t i = 0, count = gHooks.size(); i < count; ++i) { HOOK_ENTRY& hook = gHooks[i]; if (hook.isEnabled != hook.queueEnable) { if (hook.queueEnable) { oldIPs.insert(oldIPs.end(), hook.oldIPs.begin(), hook.oldIPs.end()); newIPs.insert(newIPs.end(), hook.newIPs.begin(), hook.newIPs.end()); } else { oldIPs.insert(oldIPs.end(), hook.newIPs.begin(), hook.newIPs.end()); newIPs.insert(newIPs.end(), hook.oldIPs.begin(), hook.oldIPs.end()); } } } if (oldIPs.size() > 0) { ScopedThreadExclusive tex(oldIPs, newIPs); for (size_t i = 0, count = gHooks.size(); i < count; ++i) { HOOK_ENTRY& hook = gHooks[i]; if (hook.isEnabled != hook.queueEnable) { MH_STATUS status; if (hook.queueEnable) { status = EnableHookLL(&hook); } else { status = DisableHookLL(&hook); } if (status != MH_OK) { return status; } } } } return MH_OK; }
TexOGL* Textures::createGrayNoise() { // ONLY FOR GL_FLOAT datatype //struct timeval *tp; //struct timezone *tzp; //int timeday = gettimeofday(tp, tzp); #ifndef LINUX sranddev(); #else srand(100); #endif if (internal_format != GL_RGBA) { printf("createGrayNoise: internal format should be GL_RGBA\n"); //exit(0); } if (data_type != GL_FLOAT) { printf("createBWNoise: data_type should be GL_FLOAT\n"); return 0; } float val, p; TexOGL* t = new TexOGL(); TexOGL& input = *t; Array3D tex(nb_internal_channels, nx, ny); for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { float p = u.rand_float(); for (int k=0; k < nb_internal_channels; k++) { tex(k, i, j) = p; } if (nb_internal_channels == 4) { tex(3, i, j) = 1.0; } }} input.init_targ(nx, ny, target); input.load(internal_format, format, data_type, tex.getDataPtr()); input.repeat(); input.point(); return t; }
/*! read png texture from disk */ std::shared_ptr<Texture> Texture::load(const FileName& fileName) { if (texture_cache.find(fileName.str()) != texture_cache.end()) return texture_cache[fileName.str()]; std::shared_ptr<Texture> tex(new Texture(loadImage(fileName),fileName)); return texture_cache[fileName.str()] = tex; }
void CubeProxyGeometry::process() { vec3 startDataTexCoord = vec3(0.0f); vec3 extent = vec3(1.0f); //!< will be added to the origin in the parallelepiped() yielding the end position if (inport_.getData()->getMetaData<BoolMetaData>("marginsEnabled", false)) { // volume has margins enabled // adjust start and end texture coordinate accordingly auto marginsBottomLeft = inport_.getData()->getMetaData<FloatVec3MetaData>("marginsBottomLeft", vec3(0.0f)); auto marginsTopRight = inport_.getData()->getMetaData<FloatVec3MetaData>("marginsTopRight", vec3(0.0f)); startDataTexCoord += marginsBottomLeft; // extent needs to be adjusted for both margins extent -= marginsBottomLeft + marginsTopRight; } glm::vec3 pos(0.0f); glm::vec3 p1(1.0f, 0.0f, 0.0f); glm::vec3 p2(0.0f, 1.0f, 0.0f); glm::vec3 p3(0.0f, 0.0f, 1.0f); glm::vec3 tex(startDataTexCoord); glm::vec3 t1(extent.x, 0.0f, 0.0f); glm::vec3 t2(0.0f, extent.y, 0.0f); glm::vec3 t3(0.0f, 0.0f, extent.z); glm::vec4 col(startDataTexCoord, 1.0f); glm::vec4 c1(t1, 0.0f); glm::vec4 c2(t2, 0.0f); glm::vec4 c3(t3, 0.0f); auto dims = inport_.getData()->getDimensions(); if (clippingEnabled_.get()) { pos = pos + p1*static_cast<float>(clipX_.get().x)/static_cast<float>(dims.x) + p2*static_cast<float>(clipY_.get().x)/static_cast<float>(dims.y) + p3*static_cast<float>(clipZ_.get().x)/static_cast<float>(dims.z); p1 = p1*(static_cast<float>(clipX_.get().y)-static_cast<float>(clipX_.get().x))/static_cast<float>(dims.x); p2 = p2*(static_cast<float>(clipY_.get().y)-static_cast<float>(clipY_.get().x))/static_cast<float>(dims.y); p3 = p3*(static_cast<float>(clipZ_.get().y)-static_cast<float>(clipZ_.get().x))/static_cast<float>(dims.z); tex = tex + t1*static_cast<float>(clipX_.get().x)/static_cast<float>(dims.x) + t2*static_cast<float>(clipY_.get().x)/static_cast<float>(dims.y) + t3*static_cast<float>(clipZ_.get().x)/static_cast<float>(dims.z); t1 = t1*(static_cast<float>(clipX_.get().y)-static_cast<float>(clipX_.get().x))/static_cast<float>(dims.x); t2 = t2*(static_cast<float>(clipY_.get().y)-static_cast<float>(clipY_.get().x))/static_cast<float>(dims.y); t3 = t3*(static_cast<float>(clipZ_.get().y)-static_cast<float>(clipZ_.get().x))/static_cast<float>(dims.z); col = col + c1*static_cast<float>(clipX_.get().x)/static_cast<float>(dims.x) + c2*static_cast<float>(clipY_.get().x)/static_cast<float>(dims.y) + c3*static_cast<float>(clipZ_.get().x)/static_cast<float>(dims.z); c1 = c1*(static_cast<float>(clipX_.get().y)-static_cast<float>(clipX_.get().x))/static_cast<float>(dims.x); c2 = c2*(static_cast<float>(clipY_.get().y)-static_cast<float>(clipY_.get().x))/static_cast<float>(dims.y); c3 = c3*(static_cast<float>(clipZ_.get().y)-static_cast<float>(clipZ_.get().x))/static_cast<float>(dims.z); } // Create parallelepiped and set it to the outport. The outport will own the data. auto geom = SimpleMeshCreator::parallelepiped(pos, p1, p2, p3, tex, t1, t2, t3, col, c1, c2, c3); geom->setModelMatrix(inport_.getData()->getModelMatrix()); geom->setWorldMatrix(inport_.getData()->getWorldMatrix()); outport_.setData(geom); }