J'ai lu quelques tutoriels pour écrire le code suivant. La seule différence est les didacticiels originaux où l'utilisation de SDL au lieu de GLEW.OpenGL sans shaders
Je ne comprends pas ce qui ne va pas dans ce code. Il compile mais je ne vois pas le triangle. (Le tutoriel n'utilisaient pas trop shaders)
#include <iostream>
#include <GL/glew.h>
#include <GL/gl.h>
#include <GLFW/glfw3.h>
GLFWwindow* window;
int main(int argc, const char * argv[])
{
if (!glfwInit())
{
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
window = glfwCreateWindow(640, 480, "Test", NULL, NULL);
if (window==NULL)
{
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = true;
if (glewInit() != GLEW_OK)
{
return -1;
}
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
glClearColor(0.0f, 1.0f, 1.0f, 1.0f);
do
{
glfwPollEvents();
float vertices[] = {-0.5, -0.5, 0.0, 0.5, 0.5, -0.5};
glClear(GL_COLOR_BUFFER_BIT);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glfwSwapBuffers(window);
}
while(glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0);
glfwTerminate();
return 0;
}
voir [complet GL + GLSL + VAO/VBO l'exemple C de] (https: // stackoverflow .com/a/31913542/2521214) pour un simple exemple de shader ... – Spektre