void InitializeProgram() { Shader s1(GL_VERTEX_SHADER), s2(GL_FRAGMENT_SHADER); s1.CompileSource(strVertexShader); s2.CompileSource(strFragmentShader); ShaderProgram program; program.AttachShader(s1); program.AttachShader(s2); program.SetupProgram(); glUseProgram(program.id()); }
int CALLBACK WinMain( __in HINSTANCE hInstance, __in HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nCmdShow ) #endif { if (!glfwInit()) return 0; GLFWwindow* window = glfwCreateWindow(640, 480, "Window Title", NULL, NULL); glfwMakeContextCurrent(window); glewExperimental = GL_TRUE; if (glewInit() != GLEW_OK) return -1; GLuint vertexBuffer; glGenBuffers(1, &vertexBuffer); Shader* vertexShader = new Shader("Content\\Shaders\\vertexShader.vs", GL_VERTEX_SHADER); Shader* fragmentShader = new Shader("Content\\Shaders\\fragmentShader.fs", GL_FRAGMENT_SHADER); ShaderProgram* program = new ShaderProgram(); program->AttachShader(vertexShader); program->AttachShader(fragmentShader); program->BindFragDataLocation(0, "outColour"); program->Link(); program->Use(); GLint posAttrib = program->GetAttribLocation("position"); GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); GLuint vbo; glGenBuffers(1, &vbo); float vertices[] = { 0.0f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f }; glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glEnableVertexAttribArray(posAttrib); glVertexAttribPointer (posAttrib, // Ref input 2, // Number of values for input GL_FLOAT, // Type of each component GL_FALSE, // Whether to normalise 0, // Stride 0); // Offset while (!glfwWindowShouldClose(window)) { glClearColor(0.f, 0.f, 0.f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_TRIANGLES, 0, 3); glfwSwapBuffers(window); glfwPollEvents(); } glfwDestroyWindow(window); return 0; }