Skip to content

Instantly share code, notes, and snippets.

@kjunichi
Last active August 29, 2015 14:07
Show Gist options
  • Save kjunichi/76d314331c3bd4422924 to your computer and use it in GitHub Desktop.
Save kjunichi/76d314331c3bd4422924 to your computer and use it in GitHub Desktop.
GLuint buffers[2];
glGenVertexArrays(3, vao);
//
// VAO for first triangle
//
glBindVertexArray(vao[0]);
// Generate two slots for the vertex and color buffers
glGenBuffers(2, buffers);
// bind buffer for vertices and copy data into buffer
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices1), vertices1, GL_STATIC_DRAW);
glEnableVertexAttribArray(vertexLoc);
glVertexAttribPointer(vertexLoc, 4, GL_FLOAT, 0, 0, 0);
// bind buffer for colors and copy data into buffer
glBindBuffer(GL_ARRAY_BUFFER, buffers[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(colors1), colors1, GL_STATIC_DRAW);
glEnableVertexAttribArray(colorLoc);
glVertexAttribPointer(colorLoc, 4, GL_FLOAT, 0, 0, 0);
// 頂点配列オブジェクト
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
// 頂点バッファオブジェクト
GLuint vbo; // -> vbo[2];
glGenBuffers(1, &vbo); // -> glGenBuffers(2, vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof (GLfloat) * 2 * vertices, position, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
// 結合されている頂点バッファオブジェクトを attribute 変数から参照できるようにする
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); // vertexLoc=0,2<>4
// 頂点バッファオブジェクトと頂点配列オブジェクトの結合を解除する
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
return vao;

glGenBuffers

glVertexAttribPointer

  • 第 1 引数 index には属性インデックスを指定します。
  • 第 2 引数 size は各頂点属性の要素数で 1 ~ 4 の整数を指定します。
  • 第 3 引数 type では各要素のデータ型を GL_FLOAT, GL_DOUBLE, GL_INT などで指定します。
  • 第 4 引数 normalized を GL_TRUE にすると自動的に正規化されます。
  • 第 5 引数 stride は連続する属性間のバイトオフセットを指定します。
  • 第 6 引数 pointer はバッファの先頭から最初の属性へのバイトオフセットです。

glGetAttribLocation

GPU内の変数とやり取りするための位置情報を取得する。

gl_FragColor

gl_Position

glBindAttribLocation

バーテックスシェーダー内の変数をGPUの何番のレジスタを使うかを割り当てる命令?

void glBindAttribLocation(GLuint program, GLuint index, const GLchar *name);

PARAMETERS
       program
           Specifies the handle of the program object in which the association is to be made.

       index
           Specifies the index of the generic vertex attribute to be bound.

       name
           Specifies a null terminated string containing the name of the vertex shader attribute variable to
           which index is to be bound.
  • glLinkProgram

glBindFragDataLocation

フラグメントシェーダーを紐づける命令?

  • glLinkProgram

フラグメントシェーダー

色を付けるやつ。

ピクセルを操作する機能であり、基本的には頂点シェーダからの情報を元にテクスチャを合成したり表面色を適用したりする

バーテクスシェーダー

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment