vbo を使用しようとすると、黒い画面が表示されます。GLEWでGLFWを使用しています。テクスチャでも同じですが、テクスチャを使用して動作するかどうかを確認しませんでしたが、何らかの理由で動作しません。私はそれを機能させましたが、コードにいくつかの変更を加えたので、何かをしたと思います。PS: コードにエラーがある場合はお知らせください。レンダリングに影響しないコードを削除したため、誤って重要なコードを削除した可能性があります。
ここにmain.cppがあり、OpenGL に影響しないいくつかのものは削除されています。
//Include all OpenGL stuff, such as gl.h, glew.h, and glfw3.h
#include "gl.h"
//Include a header which adds some functions for loading shaders easier, there is nothing wrong with this code though
#include "shader.h"
float data[3][3] = {
{0.0, 1.0, 0.0},
{-1.0, -1.0, 0.0},
{1.0, -1.0, 0.0}
};
int main()
{
if (!glfwInit())
return 1;
GLFWwindow* window;
window = glfwCreateWindow(800, 600, "VBO Test", NULL, NULL);
if (!window)
{
glfwTerminate();
return 1;
}
glfwMakeContextCurrent(window);
if (GLEW_OK != glewInit())
{
return 1;
glfwTerminate();
}
//There are normal error handling stuff I do to ensure everything is loaded properly, so the shaders not loading isn't a concern as it'll clearly tell me :)
GLuint vertexShader = loadShader("shader.vert", GL_VERTEX_SHADER);
GLuint fragmentShader = loadShader("shader.frag", GL_VERTEX_SHADER);
GLuint program = createProgram(vertexShader, fragmentShader);
//Also, the shader files should make everything I draw yellow, and they are not defective
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
glColorPointer(3, GL_FLOAT, 0, 0);
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glUsePorgram(program);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
shader.vert
void main(void)
{
gl_Position = gl_Vertex;
}
シェーダー.フラグ
void main()
{
//Set fragment
gl_FragColor = vec4( 1.0, 1.0, 0.0, 1.0 );
}