小编Gis*_*ela的帖子

使用GLES20,顶点缓冲区对象(VBO)无法在Android 2.3.3上运行

在Android上,我试图让一个简单的OpenGL ES 2.0应用程序运行,它使用顶点缓冲区对象,但我失败了.

我从这个项目开始:

http://developer.android.com/resources/tutorials/opengl/opengl-es20.html
Run Code Online (Sandbox Code Playgroud)

一切都很好地解释和按照描述工作.精细.

我添加了一些代码,使用glDrawElements命令而不是glDrawArrays来替换渲染.我成功了.

现在下一步:我想使用顶点缓冲区对象来做同样的事情.

所以我补充说:

  1. 新的vars:

    private int [] mVBOid = new int [2]; // VBO和索引缓冲区所需的2个ID是私有的ShortBuffer mIndices; //使用的索引

  2. 添加了创建VBO的代码:

        ByteBuffer vbb = ByteBuffer.allocateDirect(
                triangleCoords.length * SIZEOF_FLOAT); 
        vbb.order(ByteOrder.nativeOrder());// use the device hardware's native byte order
        mTriangleVB = vbb.asFloatBuffer();  // create a floating point buffer from the ByteBuffer
        mTriangleVB.put(triangleCoords);    // add the coordinates to the FloatBuffer
        mTriangleVB.position(0);            // set the buffer to read the first coordinate
    
        ByteBuffer ibb = ByteBuffer.allocateDirect(
                indices.length * SIZEOF_SHORT);
        ibb.order(ByteOrder.nativeOrder()); // use the device …
    Run Code Online (Sandbox Code Playgroud)

shader android vbo opengl-es-2.0

9
推荐指数
1
解决办法
1万
查看次数

PEG.js - 如何解析c风格的评论?

实现一个基于peg.js的解析器,我不得不添加代码来处理c风格的注释/*像这样*/.

我需要找到结束标记而不吃它.

这不起作用:

multi = '/*' .* '*/'
Run Code Online (Sandbox Code Playgroud)

消息是:

line: 14
Expected "*/" or any character but end of input found.
Run Code Online (Sandbox Code Playgroud)

我明白为什么这不起作用,但不幸的是我不知道如何使评论解析功能.

这是迄今为止的代码:

start = item*

item = comment / content_line

content_line = _ p:content _ {return ['CONTENT',p]}

content = 'some' / 'legal' / 'values'

comment = _ p:(single / multi) {return ['COMMENT',p]}

single = '//' p:([^\n]*) {return p.join('')}

multi = 'TODO'


_ = [ \t\r\n]* {return null}
Run Code Online (Sandbox Code Playgroud)

和一些样本输入:

// line comment, no problems here

/*
  how to parse this …
Run Code Online (Sandbox Code Playgroud)

parsing comments peg

8
推荐指数
2
解决办法
1712
查看次数

OpenGL ES 2.0指定位置属性vec3或vec4

在OpenGL ES 2.0的介绍中,可以在这里找到:http://www.webreference.com/programming/opengl_es/2.html 定义了一个顶点着色器:

GLbyte vShaderStr[] =
   "attribute vec4 vPosition;   \n"
   "void main()                 \n"
   "{                           \n"
   "   gl_Position = vPosition; \n"
   "};                          \n";
Run Code Online (Sandbox Code Playgroud)

vPosition属性是一个四分量向量.

稍后在文本中,应用程序将与片段着色器一起编译顶点着色器.使用glBindAttribLocation建立一个句柄,将应用程序顶点数据传递给着色器:

// Bind vPosition to attribute 0
glBindAttribLocation(programObject, 0, "vPosition");
Run Code Online (Sandbox Code Playgroud)

现在链接了两个着色器,程序已准备就绪.

用例是这样的:

GLfloat vVertices[] = {0.0f, 0.5f, 0.0f,
                        -0.5f, -0.5f, 0.0f,
                        0.5f, -0.5f, 0.0f};
...
// Load the vertex data
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
Run Code Online (Sandbox Code Playgroud)

意思是:

  • glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices) :将顶点数据传递给程序,使用位置0,每个顶点有3个组件,类型为float,不使用规范化.

  • glEnableVertexAttribArray(0) :着色器将使用传递的数据.

  • glDrawArrays(GL_TRIANGLES, 0, 3); …

iphone shader android opengl-es-2.0

7
推荐指数
1
解决办法
6059
查看次数

使用过滤器打开联系人选取器

可以轻松打开Android联系人应用程序以显示所有联系人并选择其中一个:

在活动中:

    private int PICK_CONTACT = 853456;

    // ...

    // open contact list
    void openContactPicker() {
        Intent it= new Intent(Intent.ACTION_PICK,  Contacts.CONTENT_URI);
        startActivityForResult(it, PICK_CONTACT);
    }

    // when back from intent: use pick result
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // ...
        switch (requestCode) {
        case PICK_CONTACT:
            if (dataOk(data)) {
                extractContactInfo(data);
            } else {
                showErrorMessage();
            }
            break;
        // ...
    }
Run Code Online (Sandbox Code Playgroud)

但是是否可以设置一些过滤条件,以便联系应用程序只显示那些具有指定元素的联系人 - 例如完整的邮政信息,或正确的电子邮件或电话号码?

我的应用程序需要邮政信息,当前实现的工作流程是这样的:

  • 用户单击按钮以打开联系人
  • 联系应用程序已启动,显示所有联系人
  • 用户选择一个
  • 回到我的活动中,检查联系人
    • 邮政信息 - >做正确的事
    • 邮政信息不可用 - >消息框

由于许多联系人没有邮政信息,因此在大多数情况下会显示一个消息框"抱歉没有可用于此联系人的邮政信息".这不是一种可接受的行为.

一种替代方案是 - 我只是实现这一点 …

android android-contacts start-activity

6
推荐指数
1
解决办法
1112
查看次数

apt-get install apache2-utils尝试安装不存在的包

当试图安装ab(apache benchmark)时,像这样:

sudo apt-get install apache2-utils
Run Code Online (Sandbox Code Playgroud)

在我的Mint 16/Ubuntu 13系统上,我收到以下消息:

sudo apt-get install apache2-utils
[sudo] password for <user>: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libjs-cropper libjs-prototype libjs-scriptaculous libphp-phpmailer libphp-snoopy tinymce
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
  apache2-utils
0 upgraded, 1 newly installed, 0 to remove and 15 not upgraded.
Need to get 82,4 kB of archives.
After this …
Run Code Online (Sandbox Code Playgroud)

ubuntu install apt-get apachebench apache-utils

6
推荐指数
0
解决办法
2231
查看次数

科尔多瓦检测方向变化

我目前正在开发的应用程序需要知道设备的方向,因此我使用此代码来检测orientationchange 事件:

window.addEventListener('orientationchange', function(){
    theApp.orientationChange();
});
Run Code Online (Sandbox Code Playgroud)

和这个属性来获得实际的方向值:

window.orientation
Run Code Online (Sandbox Code Playgroud)

问题:在 2 种横向模式之间切换时,不会触发任何事件,方向分别保持在错误的 90 度或 -90 度。

我正在 2 台运行 2.3.5 和 4.4.4 的 Android 设备上进行测试,它们都显示相同的行为。

所以,问题是:

  • 有解决方法吗?- 如何检测此事件?
  • 此错误仅在 Android 上显示,还是其他平台会受到影响?

澄清
我希望我的应用程序显示从用户位置到目标地理位置的方向。

为此,我需要 2 个不同的方向信息:

  1. 罗盘航向
  2. 屏幕方向

要获取指南针,使用此插件:

org.apache.cordova.device-orientation 0.3.10 "Device Orientation"
Run Code Online (Sandbox Code Playgroud)

我用

navigator.compass.watchHeading
Run Code Online (Sandbox Code Playgroud)

获取标题更新 - 这部分正在工作。

要使箭头元素指向目标位置,应用程序不仅需要知道指南针的方向,还需要知道屏幕方向(window.orientation 属性中的 0、90、-90 和 180 度值)。
但是这个 window.orientation 属性在经过测试的 Android 设备上是错误的,当直接将设备方向从横向 1 更改为横向 2 时,而不是通过纵向模式。此外,在这种情况下不会触发orientationchange 事件。

IOS 示例代码(顺便说一句:示例中没有特定于 IOS 的内容,代码应该在每个 WebView 中运行) KRIZTE 所引用的依赖于正确的 window.orientation 值。提到的问题(延迟初始更新)不是我的代码的问题。

(测试-)用于检查 window.orientation 的代码:

setInterval(function(){
    console.log('WO ' + …
Run Code Online (Sandbox Code Playgroud)

orientation cordova

4
推荐指数
1
解决办法
1万
查看次数

Zend/ZF2/TableGateway mysql_insert_id替换?

我试图从mysql切换到Zend/TableGateway类.

我不知道是否有一种方法,类似于mysql_insert_id,得到最后插入行的自动增量ID.

谷歌搜索周围,我发现了一些答案,数据库适配器的指向lastInsertId(),但是,这种方法似乎ZF2不再可用.另外:insert方法的返回值返回一个布尔值,而不是ZF1中的最后一个id.

目前我正在使用一个丑陋的解决方法.请参阅下面的代码.

是否有更好/推荐的获取身份证的方式?

table_1 {
    id: integer, primary key, autoincremented
    content: text
}

table_2 {
    table_1_id: integer
    other_content: text
}

// using mysql
$sql = "INSERT INTO table_1 (content) VALUES ('some text')";
$result = mysql_query($sql);
// check omitted

$id = mysql_insert_id();
$sql = "INSERT INTO table_2 (table_1_id, other_content) VALUES ($id, 'other text')";
$result = mysql_query($sql);


// using Zend - this is the code, I am currently using
//*************************************************************
// get_last_insert_id emulation; works only if content is unique
private …
Run Code Online (Sandbox Code Playgroud)

lastinsertid zend-db last-insert-id zend-framework2 tablegateway

3
推荐指数
1
解决办法
4318
查看次数