-5

最近、C/C++ でプログラミングを始めましたが、特定のことを理解するのが少し難しいと感じています。たとえば、私の vertices.h ファイル:

#ifndef _vertices_h
#define _vertices_h

typedef struct
{
    float XYZW[4];
    float RGBA[4];
} Vertex;

extern Vertex Vertices[];
extern GLubyte Indices[];

#endif

そして私の vertices.c ファイル:

#include "vertices.h"

Vertex Vertices[] =
{
    { { 0.0f, 0.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 1.0f, 1.0f } }       
};
GLubyte Indices[] = {
    0, 1, 3,
    0, 3, 2,
    3, 1, 4,
    3, 4, 2
 };

いいえ、Vertices 配列を使用する他の .h ファイルに関数を作成する必要があります。以下は shader.c ファイルです。

#include "vertices.h"

void CreateVBO(){ #############################################1
// some operations that uses the passed Vertices array
}

そして私の「shaders.h」ファイル:

#ifndef _shaders_h
#define _shaders_h

void CreateVBO(); #############################################################2

#endif

私の質問は、メイン関数で CreateVBO 関数を呼び出し、必要な Vertices Array を渡したいということです。私の場合、宣言したのは 1 だけですが、もっと宣言して、必要なものを渡したいと思います。したがって、基本的に、CreateVBO関数の引数を宣言する方法が本当にわかりません。行方不明の行は #### で署名されています。

void doSemthing(int argc, char* argv[]){
...
CreateVBO(); #############################################################3
}
4

2 に答える 2

1

Vertices[]グローバルであり、パラメーターを介して渡す必要はありません。ただし、頂点も渡すことができます。

以下のように関数を作成します

void CreateVBO(Vertex vertices[]);

あれを呼べ

CreateVBO(Vertices);
于 2013-04-18T14:00:55.027 に答える
1

あなたの質問は私には明確ではないようですが、配列「 Vertices[ ]」に要素をさらに宣言し、それらのいずれかを「 CreateVBO() 」に渡したいと想定しています。

" vertices.h " で " Vertices[ ] " を次のように宣言したとします。

Vertices[index1] = {...something....};    // Vertices with index1 elements.

「shaders.h」ファイルで、CreateVBO() を次のように宣言および定義できます。

void CreateVBO(Vertex *V)
{
    //....something....

    V[index1].XYZW[index2]   // You can access the variables as shown.
    V[index1].RGBA[index2]   // You can access the variables as shown.

    //....something....
}

そして、「 doSemthing() 」では、次のように頂点を「 CreateVBO() 」に渡すことができます。

void doSemthing(int argc, char* argv[])
{
    ...something....

    CreateVBO(Vertices);

    ...something....
}
于 2013-04-18T15:30:34.177 に答える