2016年にはを使用しないでください。glBegin
/glEnd
を使用してください。とんでもない。代わりにVertex Array Obejctsを使用してください。 vertexおよび/またはgeometryシェーダを使用して、頂点データの位置を変更して変更します。これらの手法を使用すると、GPUにデータを一度アップロードすると、さまざまな変換で同じメッシュを描画できます。
// 1. Initialization.
// Object handles:
GLuint vao;
GLuint verticesVbo;
// Generate and bind vertex array object.
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
// Generate a buffer object.
glGenBuffers(1, &verticesVbo);
// Enable vertex attribute number 0, which
// corresponds to vertex coordinates in older OpenGL versions.
const GLuint ATTRIBINDEX_VERTEX = 0;
glEnableVertexAttribArray(ATTRIBINDEX_VERTEX);
// Bind buffer object.
glBindBuffer(GL_ARRAY_BUFFER, verticesVbo);
// Mesh geometry. In your actual code you probably will generate
// or load these data instead of hard-coding.
// This is an example of a single triangle.
GLfloat vertices[] = {
0.0f, 0.0f, -9.0f,
0.0f, 0.1f, -9.0f,
1.0f, 1.0f, -9.0f
};
// Determine vertex data format.
glVertexAttribPointer(ATTRIBINDEX_VERTEX, 3, GL_FLOAT, GL_FALSE, 0, 0);
// Pass actual data to the GPU.
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*3*3, vertices, GL_STATIC_DRAW);
// Initialization complete - unbinding objects.
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
// 2. Draw calls.
while(/* draw calls are needed */) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindVertexArray(vao);
// Set transformation matrix and/or other
// transformation parameters here using glUniform* calls.
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindVertexArray(0); // Unbinding just as an example in case if some other code will bind something else later.
}
と頂点シェーダは、このようになります:
layout(location=0) in vec3 vertex_pos;
uniform mat4 viewProjectionMatrix; // Assuming you set this before glDrawArrays.
void main(void) {
gl_Position = viewProjectionMatrix * vec4(vertex_pos, 1.0f);
}
も加速良い現代のためthis pageを見てみましょう。ここ
は、あなたのコードは次のように見えるかもしれ方法の概要でありますグラフィックスブック。
メッシュを頂点バッファオブジェクトにアップロードします。最終的には、固定機能パイプラインを使用しないでください(古くなってから古くなっています)、コアプロファイルに移行してください。ここでは、頂点バッファオブジェクトの使用が義務付けられています。 – BDL
古いOpenGL APIを使用しています。最新のAPIを使用してみてください。私は古いOpenGLに関する多くの書籍があることを知っており、OpenGLを研究する正しい方法はどこにあるのかは分かりません。 – Unick