#include #include #include GLuint loadShader(const char *path, GLenum shadertype) { FILE *file; char *src; size_t length; GLuint shader; src = malloc(1000); file = fopen(path, "r"); length = fread(src, 1, 1000, file); fclose(file); shader = glCreateShader(shadertype); glShaderSource(shader, 1, &src, &length); free(src); glCompileShader(shader); return shader; } int main(void) { GLFWwindow* window; GLuint vs, fs, prog; if (!glfwInit()) return -1; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); window = glfwCreateWindow(640, 480, "Test", NULL, NULL); if (!window) { glfwTerminate(); return -1; } glfwMakeContextCurrent(window); vs = loadShader("vertex.glsl", GL_VERTEX_SHADER); printShaderLog(vs); prog = glCreateProgram(); glAttachShader(prog, vs); glLinkProgram(prog); glUseProgram(prog); while (!glfwWindowShouldClose(window)) { glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(window); } glfwTerminate(); return 0; }