首页 文章 精选 留言 我的

精选列表

搜索[es],共3893篇文章
优秀的个人博客,低调大师

Android OpenGL ES 应用(二) 纹理

上一篇讲了基础入门OpenGL (一),这一次主要学习OpenGL 纹理基本学习总结 要是做复杂的OpenGL应用程序,一定会用到纹理技术。纹理说白了就是把图片或者视频图像绘制到OpenGL空间中。 因此纹理也有坐标系,称ST坐标。或者UV 上面是纹理坐标空间。但没有固定的方向 以下演示载入一张image作为纹理贴图。 public class TextureUtils { public static int createTexture(InputStream ins) { int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0);//生成一个纹理 int textureId = textures[0]; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,GLES20.GL_NEAREST); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_MAG_FILTER,GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,GLES20.GL_CLAMP_TO_EDGE); //上面是纹理贴图的取样方式,包含拉伸方式,取临近值和线性值 Bitmap bitmap = BitmapFactory.decodeStream(ins); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);//让图片和纹理关联起来。载入到OpenGl空间中 Log.d("OPENGL","bitmap:" + bitmap); bitmap.recycle();//不须要。能够释放 return textureId; } } public class MyRenderer implements Renderer { public static float[] projMatrix = new float[16];// 投影 public static float[] viewMatrix = new float[16];// 相机 public static float[] mViewPjMatrix;// 总变换矩阵 public static float[] matrixs = new float[16]; public static int textureId = -1; Context context; MyDrawModel drawModel; public MyRenderer(Context context) { this.context = context; } @Override public void onDrawFrame(GL10 arg0) { GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); Log.e("", "textureId:" + textureId); drawModel.drawFrame(textureId); } @Override public void onSurfaceChanged(GL10 arg0, int w, int h) { GLES20.glViewport(0, 0, w, h); float ratio = (float) w / h; Matrix.frustumM(projMatrix, 0, -ratio, ratio, -1, 1, 1, 10);//投影矩阵设置 Matrix.setLookAtM(viewMatrix, 0, 0, 0, 3, 0, 0, 0, 0.0f, 1.0f, 0.0f);//摄像机坐标设置 } @Override public void onSurfaceCreated(GL10 g, EGLConfig eglConfig) { GLES20.glClearColor(0.5f,0.5f,0.5f, 1.0f); GLES20.glEnable(GLES20.GL_DEPTH_TEST); InputStream ins = null; drawModel = new MyDrawModel(); drawModel.init(); try { ins = context.getAssets().open("house.jpg"); textureId = TextureUtils.createTexture(ins); Log.e("", "textureId:" + textureId); } catch (IOException e) { e.printStackTrace(); } finally { try { ins.close(); } catch (IOException e) { e.printStackTrace(); } } GLES20.glDisable(GLES20.GL_CULL_FACE); } } public class MyDrawModel { private int programId; private int mVPMatrixHandle; // 总变换矩阵引用id private int positionHandle; // 顶点位置id private int texCoorHandle; // 顶点纹理坐标id private FloatBuffer vertexBuffer; private FloatBuffer texCoorBuffer; public MyDrawModel() { } public void init() { initData(); int vertexsharder = GLHelper.compileScript(GLES20.GL_VERTEX_SHADER, GLScript.vertex2); int fragmentsharder = GLHelper.compileScript(GLES20.GL_FRAGMENT_SHADER, GLScript.fragment2); programId = GLHelper.linkAttach(vertexsharder, fragmentsharder); boolean isOK = GLHelper.checkProgram(programId); positionHandle = GLES20.glGetAttribLocation(programId, "aPosition"); texCoorHandle = GLES20.glGetAttribLocation(programId, "aTexCoor"); mVPMatrixHandle = GLES20.glGetUniformLocation(programId, "uMVPMatrix"); Log.d("OPENGL", "positionHandle:" + positionHandle + ";texCoorHandle:" + texCoorHandle + ";mVPMatrixHandle:" + mVPMatrixHandle + ";" + isOK); } private void initData() { //X,Y,Z,绘画的顶点 float vertices[] = new float[] { 0, 0, 0, -1.8f, -1f, 0, 1.8f, -1f, 0, 1.8f, 1f, 0, -1.8f, 1f, 0, -1.8f, -1f, 0 }; ByteBuffer vb = ByteBuffer.allocateDirect(vertices.length * 4); vb.order(ByteOrder.nativeOrder()); vertexBuffer = vb.asFloatBuffer(); vertexBuffer.put(vertices); vertexBuffer.position(0); //纹理空间坐标 S,T float texCoor[] = new float[] { 0.5f, 0.5f, 0f, 1f, 1f, 1f, 1f, 0f, 0f, 0f, 0f, 1f }; ByteBuffer cb = ByteBuffer.allocateDirect(texCoor.length * 4); cb.order(ByteOrder.nativeOrder()); texCoorBuffer = cb.asFloatBuffer(); texCoorBuffer.put(texCoor); texCoorBuffer.position(0); } public void drawFrame(int textureId) { GLES20.glUseProgram(programId); // // 初始化矩阵 Matrix.setRotateM(MyRenderer.matrixs, 0, 0, 1, 0, 0); Matrix.translateM(MyRenderer.matrixs, 0, 0, 0, 1); //矩阵转换 ,投影矩阵,摄像机矩阵。模型矩阵 MyRenderer.mViewPjMatrix = new float[16]; Matrix.multiplyMM(MyRenderer.mViewPjMatrix, 0, MyRenderer.viewMatrix,0, MyRenderer.matrixs, 0); Matrix.multiplyMM(MyRenderer.mViewPjMatrix, 0, MyRenderer.projMatrix,0, MyRenderer.mViewPjMatrix, 0); GLES20.glUniformMatrix4fv(mVPMatrixHandle, 1, false, MyRenderer.mViewPjMatrix, 0); GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 3 * 4, vertexBuffer); GLES20.glVertexAttribPointer(texCoorHandle, 2, GLES20.GL_FLOAT, false, 2 * 4, texCoorBuffer); GLES20.glEnableVertexAttribArray(positionHandle); GLES20.glEnableVertexAttribArray(texCoorHandle); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, 6);//六个定点,绘制三角形 } } OpenGL须要把设备的坐标归一化到[-1,-1]空间中。所以这里涉及到矩阵相乘的理论,包含世界坐标,物体坐标,摄像机坐标的转换。以后会具体介绍。 public class GLScript { public GLScript() { } public static final String vertex1 = "attribute vec4 mPosition;\n" + "void main()\n" + "{\n" + "gl_Position=mPosition;\n " + "}\n"; public static final String fragment1 = "precision mediump float;\n" + "uniform vec4 mColor;\n" + "void main(){ gl_FragColor=mColor;\n}"; public static final String vertex2 = "uniform mat4 uMVPMatrix;\n" + "attribute vec3 aPosition;\n" + "attribute vec2 aTexCoor;\n" + "varying vec2 vTextureCoord;\n" + "void main() { \n" + "gl_Position = uMVPMatrix * vec4(aPosition,1);\n" + "vTextureCoord = aTexCoor;\n" + "}\n" ; public static final String fragment2 = "precision mediump float;\n" + "varying vec2 vTextureCoord;\n" + "uniform sampler2D sTexture;\n" + "void main() { \n" + "vec2 coord = vTextureCoord;\n" + "coord.s = coord.s * 0.5;\n" //事实上是去图像的一半,向量缩小了 + "gl_FragColor = texture2D(sTexture, coord); \n" + "}\n" ; } coord.s = coord.s * 0.5; 这样是取纹理图像的一半,显示到界面上也就是图片的前半部分内容 其他的工具类和上一篇文章一样。 内容显示 原图: 本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5095000.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

ES禁用_source不会影响聚合

From Elasticsearch's website: The _source field contains the original JSON document body that was passed at index time. The _source field itself is not indexed (and thus is not searchable), but it is stored so that it can be returned when executing fetch requests, like get or search Disabling the source will prevent Elasticsearch from displaying it in the resultset. However, filtering, querying and aggregations will not be affected. So these two queries will not generate any results in terms of the actual body: GET mq-body-local/body/_search GET mq-body-local/body/1 However, you could run this aggregation that will include some of the source, for example: POST mq-body-local/body/_search { "aggs": { "test": { "terms": { "field": "body" } } } } Will produce this result set (I've created some test records): "aggregations": { "test": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "my body", "doc_count": 1 }, { "key": "my body2", "doc_count": 1 } ] } } 本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6432324.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

ES 相似度算法设置(续)

Tuning BM25 One of the nice features of BM25 is that, unlike TF/IDF, it has two parameters that allow it to be tuned: k1 This parameter controls how quickly an increase in term frequency results in term-frequency saturation. The default value is 1.2. Lower values result in quicker saturation, and higher values in slower saturation. b This parameter controls how much effect field-length normalization should have.A value of 0.0disables normalization completely, and a value of 1.0normalizes fully. The default is 0.75. The practicalities of tuning BM25 are another matter. The default values fork1andbshould be suitable for most document collections, but the optimal values really depend on the collection. Finding good values for your collection is a matter of adjusting, checking, and adjusting again. The similarity algorithm can be set on a per-field basis.It’s just a matter of specifying the chosen algorithmin the field’s mapping: PUT /my_index { "mappings": { "doc": { "properties": { "title": { "type": "string", "similarity": "BM25" }, "body": { "type": "string", "similarity": "default" } } } } Thetitlefield uses BM25 similarity. Thebodyfield uses the default similarity (seeLucene’s Practical Scoring Function). Currently, it is not possible to change thesimilaritymapping for an existing field. You would need to reindex your data in order to do that. Configuring BM25 Configuring a similarity is muchlike configuring an analyzer. Custom similarities can be specified when creating an index. For instance: PUT /my_index { "settings": { "similarity": { "my_bm25": { "type": "BM25", "b": 0 } } }, "mappings": { "doc": { "properties": { "title": { "type": "string", "similarity": "my_bm25" }, "body": { "type": "string", "similarity": "BM25" } } } } } 参考:https://www.elastic.co/guide/en/elasticsearch/guide/current/changing-similarities.html 本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6472828.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Linux java mysql es redis 安装

0关闭防火墙 chkconfig iptables off 1空白的center os6 修改 host vi /etc/sysconfig/network HOSTNAME=mechine001 vi /etc/hosts 127.0.0.1 mechine001 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 mechine001 localhost localhost.localdomain localhost6 localhost6.localdomain6 2切换到root用户 su root chmod 777 /etc/sudoers root ALL=(ALL) ALL baoyou ALL=(ALL) ALL %wheel ALL=(ALL) ALL %wheel ALL=(ALL) nopasswd:ALL chmod 644 /etc/sudoers 可以获取root 用户了 3在/home/baoyou 下创建 package、soft文件夹 4安装java 下载 jdk jre-7u5-linux-i586.tar.gz 解压 tar -zxvf jre-7u5-linux-i586.tar.gz 移动到 mv jre1.7.0_05 ../soft/jre1.7.0_05 修改配置文件 sudo -s vi /etc/profile export JAVA_HOME=/home/baoyou/soft/jre1.7.0_05/ export PATH=.:$JAVA_HOME/bin:$PATH source /etc/profile java -version 5安装maven 下载 apache-maven-3.2.3-bin.tar.gz 解压 tar -zxvf apache-maven-3.2.3-bin.tar.gz 移动 mv apache-maven-3.2.3 ../soft/maven 修改配置文件 sudo -s vi /etc/profile export MAVEN_HOME=/home/baoyou/soft/maven/ export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH source /etc/profile mvn -v 6安装nexus 下载 nexus-2.11.4-01-bundle.tar.gz 解压 tar -zxvf nexus-2.11.4-01-bundle.tar.gz 移动 mv nexus-2.11.4-01 ../soft/nexus 修改配置文件 进入 cd soft/nexus sudo chown -R baoyou:baoyou * cd bin ./nexus start 成功启动 7安装mysql 卸载 mysql rpm -qa | grep -i mysql rpm -e --nodeps xxx rpm -ev xxxx rpm --import /etc/pki/rpm-gpg/RPM* yum remove xxx rm -rf /usr/lib/mysql rm -rf /usr/include/mysql rm -rf /etc/my.cnf rm -rf /etc/init.d/mysql rm -rf /var/lib/mysql rm -rf /etc/init.d/mysql rpm -ivh xxx rpm -ivh MySQL-server-5.6.15-1.el6.x86_64.rpm cp /usr/share/mysql/my-default.cnf /etc/my.cnf /usr/bin/mysql_install_db service mysql start cat /root/.mysql_secret #查看root账号密码 mysql -uroot –pxxxxx SET PASSWORD = PASSWORD('root'); 远程登录 use mysql; select host,user,password from user; update user set password=password('root') where user='root'; update user set host='%' where user='root' and host='localhost'; 或者 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; flush privileges; 开机自启动 chkconfig mysql on chkconfig --list | grep mysql /var/lib/mysql/ #数据库目录 /usr/share/mysql #配置文件目录 /usr/bin #相关命令目录 /etc/init.d/mysql #启动脚本 8安装elactis search 集群 下载 elasticsearch-2.1.0.tar.gz 解压 tar -zxvf elasticsearch-2.1.0.tar.gz 移动 mv elasticsearch-2.1.0 ../soft/elasticsearch-2.1.0 修改配置文件 进入 cd soft/elasticsearch-2.1.0 sudo chown -R baoyou:baoyou elasticsearch-2.1.0/ cd config vi elasticserach.xml cluster.name: elasticsearch node.name: "mechine002" node.master: true node.data: true node.rack: mechine002 index.translog.flush_threshold_period: 60s index.refresh_interval: 30s indices.memory.index_buffer_size: 50% indices.memory.min_index_buffer_size: 500m index.translog.flush_threshold: 30000 index.store.type: mmapfs index.merge.policy.use_compound_file: false index.cache.field.type: soft path.logs: /home/baoyou/soft/elasticsearch-2.1.0/logs bootstrap.mlockall: true #gateway.type: local discovery.zen.fd.ping_timeout: 120s discovery.zen.fd.ping_retries: 60 discovery.zen.fd.ping_interval: 30s client.transport.ping_timeout: 10s 启动 cd bin ./elasticsearch -d 查看启动成功 http://localhost:9200/_cluster/state?pretty 9安装 redis 集群 下载 redis-2.6.17.tar.gz 解压 tar -zxvf redis-2.6.17.tar.gz 移动 mv redis-2.8.12../soft/redis-2.6.17 cd ../soft/redis-2.6.17 安装 make sudo make install 集群 主 不需要修改 从 修改redis.conf slaveof 192.168.50.143 6397 (主ip) appendonly yes 主 redis-server redis.conf 启动 从 redis-server redis.conf 启动 主 redis-cli set name baoyou 从 redis-cli info (查看节点信息) get name 捐助开发者 在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。 谢谢您的赞助,我会做的更好!

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册