J'ai du mal à rendre un triangle simple. Le code ci-dessous compile et s'exécute, sauf qu'il n'y a pas de triangle; seulement un fond noir.Le triangle ne rend pas
GLuint VBO;
static void RenderSceneCB()
{
//glClear sets the bitplane area of the window to values previously selected by glClearColor, glClearDepth, and glClearStencil.
glClear(GL_COLOR_BUFFER_BIT);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
//swaps the buffers of the current window if double buffered.
glutSwapBuffers();
}
static void InitializeGlutCallbacks()
{
glutDisplayFunc(RenderSceneCB);
}
static void CreateVertexBuffer()
{
Vector3f Vertices[3];
Vertices[0] = Vector3f(-1.0f, -1.0f, 0.0f);
Vertices[1] = Vector3f(1.0f, -1.0f, 0.0f);
Vertices[2] = Vector3f(0.0f, 1.0f, 0.0f);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(1024, 768);
glutInitWindowPosition(100, 100);
glutCreateWindow("Tutorial 02");
InitializeGlutCallbacks();
// Must be done after glut is initialized!
GLenum res = glewInit();
if (res != GLEW_OK) {
fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
return 1;
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
CreateVertexBuffer();
glutMainLoop();
return 0;
}
Je suis assez nouveau pour OpenGL, mais cela ressemble à la "nouvelle" OpenGL où vous devez avoir des shaders. Pour un très bon tutoriel, je recommande [celui-ci] (http://arcsynthesis.org/gltut/index.html), et vous pourriez vouloir lire le ["Bonjour le triangle"] (http://arcsynthesis.org/gltut /Basics/Tutorial%2001.html) chapitre. –
Peut-être essayer de changer la couleur de l'écran entier en utilisant 'glClearColor()' et appelez cette fonction après glClear 'glLoadIdentity' – mr5
@RetoKoradi - Merci .... Cela a fonctionné! – SINGULARITY