小编Cur*_*sJC的帖子

最基本的工作vbo示例

我想知道在OpenGL中使用vbo的最简单的方法...我已经尝试运行一些有效的例子但是被所有其他信息蒙上阴影,这让我真的很困惑......此刻这就是我所拥有的

GLuint vboId = 0;
const int trisize = (m_tris.size()/2)*3;//m_tris is an index array for verts and normals
GLfloat* vertices = new GLfloat[trisize];
GLfloat* normals = new GLfloat[trisize];

int j=0;
for (int i=0; i<m_tris.size(); i+=2) {

    normals[j] = m_normals[m_tris[i+1]*3];
    vertices[j++] = m_vertices[m_tris[i]*3];
    normals[j] = m_normals[m_tris[i+1]*3+1];
    vertices[j++] = m_vertices[m_tris[i]*3+1];
    normals[j] = m_normals[m_tris[i+1]*3+2];
    vertices[j++] = m_vertices[m_tris[i]*3+2];
} //im pretty sure this loop is right as its what i used before to display mesh correctly without vbo's using glVertex3f

glGenBuffersARB(1, &vboId);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId); …
Run Code Online (Sandbox Code Playgroud)

c++ opengl

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

当C/C++中的数字常量以0为前缀时,这意味着什么?

好的...所以我有一个愚蠢的想法,并尝试将值0123放入一个int,只是好奇看看会发生什么,我假设当我打印的值我得到123,但我得到83 ...有什么想法吗?在编译器/内存中发生什么使该值变为83?

我在C++和C中使用GCC编译器尝试了这个,并尝试使用浮点数产生相同的结果.

c c++ compiler-construction syntax numbers

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

在Cuda实施Max Reduce

我一直在学习Cuda,我仍然在处理并行问题.我目前遇到的问题是对一组值实现最大减少.这是我的内核

__global__ void max_reduce(const float* const d_array,
                     float* d_max,
                     const size_t elements)
{
    extern __shared__ float shared[];

    int tid = threadIdx.x;
    int gid = (blockDim.x * blockIdx.x) + tid;

    if (gid < elements)
        shared[tid] = d_array[gid];
    __syncthreads();

    for (unsigned int s=blockDim.x/2; s>0; s>>=1) 
    {
        if (tid < s && gid < elements)
            shared[tid] = max(shared[tid], shared[tid + s]);
        __syncthreads();
    }

    if (gid == 0)
        *d_max = shared[tid];
}
Run Code Online (Sandbox Code Playgroud)

我已经使用相同的方法(用min替换max函数)实现了min reduce,这很好.

为了测试内核,我使用串行for循环找到了最小值和最大值.最小值和最大值在内核中总是相同,但只有min reduce匹配.

有什么明显的东西我错过了/做错了吗?

parallel-processing cuda

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

创建我自己的“数据类型”

我希望能够创建一个具有 3 个浮点数 (x,y,z) 的类型。我试过了:

typedef struct
{
 float x;
 float y;
 float z;
} Vertex;
Run Code Online (Sandbox Code Playgroud)

但这没有用。

这是否必须在可以看到的地方声明main?我将如何为我制作的类型创建 getter 方法和其他方法?

c++

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

引用一个向量

我有这个代码

void split(vector<float> &fvec, string str)
{
    int place = 0;
        for(int i=0; i<str.length(); i++)
        {
            if(str.at(i) == ' ')
            {
                fvec.push_back(atoi(str.substr(place,i-place).c_str()));
                place=i+1;
            }
        }
        fvec.push_back(atoi(str.substr(place).c_str()));
}
Run Code Online (Sandbox Code Playgroud)

我试图做的是将一个向量的引用传递给方法,所以它拆分字符串我给它浮动而不复制向量...我不想复制向量,因为它将包含1000的数字.

是不是可以通过引用传递一个向量,或者我只是犯了一个愚蠢的错误?

如果它有助于继承代码我测试它

int main (void)
{
    vector<float> fvec;
    string str = "1 2 2 3.5 1.1";

    split(&fvec, str);

    cout<<fvec[0];

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ reference tokenize

2
推荐指数
1
解决办法
451
查看次数

仅在 git log 装饰中显示遥控器

当我运行命令时,git log --oneline origin/dev...origin/release我得到类似于以下内容的输出:

e829fee14 (HEAD -> dev, origin/dev, origin/HEAD) latest commit message
d511c2de5 some other message
08e84e327 (origin/release) latest release message
eb267ff70 (release) a change in release but not in dev
Run Code Online (Sandbox Code Playgroud)

我追求的是:

e829fee14 (origin/dev, origin/HEAD) latest commit message
d511c2de5 some other message
08e84e327 (origin/release) latest release message
eb267ff70 a change in release but not in dev
Run Code Online (Sandbox Code Playgroud)

仅装饰远程分支,即我不希望显示本地分支。

git formatting

2
推荐指数
1
解决办法
390
查看次数