#include
//GLEW
# define GLEW_STATIC
#include
//GLFW
#include
//Function as
Void key_callback (GLFWwindow * window, int key, int scancode, int action, int mode).
//Window dimensions
Const GLuint WIDTH=800, HEIGHT=600;
//Shaders
Const GLchar * vertexShaderSource="version 330 core \ n"
"//offset is an input vertex attribute \ n", "
"The layout (location=0) in vec4 offset.
\ n""Void main () \ n"
"{\ n
""Const vec4 are [3]=vec4 [3] (vec4 (0.25, 0.25, 0.5, 1.0), and \ n
""The vec4 (0.25, 0.25, 0.5, 1.0), and \ n"
"Vec4 (0.25, 0.25, 0.5, 1.0));
\ n""//Add offset to our hard - coded vertex position \ n", "
"Gl_Position=are [gl_VertexID] + offset;
\ n""} \ 0 ";
Const GLchar * fragmentShaderSource="# version 330 core \ n"
"Out vec4 color;
\ n""Void main () \ n"
"{\ n
"0.5 "color=vec4 (1.0 f, f, f 0.2, 1.0 f);
\ n""} \ n \ 0 ";
//The MAIN function, from here we start The application and run The game loop
Int main ()
{
//Init GLFW
GlfwInit ();
//Set all the required options for GLFW
GlfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 3);
GlfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 3);
GlfwWindowHint (GLFW_OPENGL_PROFILE GLFW_OPENGL_CORE_PROFILE);
GlfwWindowHint (GLFW_RESIZABLE GL_FALSE);
//Create a GLFWwindow object that we can use for GLFW 's functions provides
GLFWwindow * window=glfwCreateWindow (WIDTH, HEIGHT, "LearnOpenGL nullptr, nullptr);
GlfwMakeContextCurrent (Windows);
//Set the required callback functions provides
GlfwSetKeyCallback (window, key_callback);
//Set this to true so GLEW knows to use a modern approach to retrieving function Pointers and extensions
GlewExperimental=GL_TRUE;
//Initialize GLEW to setup the OpenGL Function Pointers
GlewInit ();
//Define the viewport dimensions
Int width, height;
GlfwGetFramebufferSize (window, & amp; Width, & amp; Height);
GlViewport (0, 0, width, height);
//Build and compile our shader program
//Vertex shader
GLuint vertexShader=glCreateShader (GL_VERTEX_SHADER);
GlShaderSource (vertexShader, 1, & amp; VertexShaderSource, NULL);
GlCompileShader (vertexShader);
//Check for the compile time errors
GLint success;
GLchar infoLog [512].
GlGetShaderiv (vertexShader GL_COMPILE_STATUS, & amp; Success);
if (! Success)
{
GlGetShaderInfoLog (vertexShader, 512, NULL, infoLog);
STD: : cout & lt; & lt; "ERROR: : SHADER: : VERTEX: : COMPILATION_FAILED \ n" & lt; & lt; InfoLog & lt; & lt; STD: : endl;
}
//Fragment shader
GLuint fragmentShader=glCreateShader (GL_FRAGMENT_SHADER);
GlShaderSource (fragmentShader, 1, & amp; FragmentShaderSource, NULL);
GlCompileShader (fragmentShader);
//Check for the compile time errors
GlGetShaderiv (fragmentShader GL_COMPILE_STATUS, & amp; Success);
if (! Success)
{
GlGetShaderInfoLog (fragmentShader, 512, NULL, infoLog);
STD: : cout & lt; & lt; "ERROR: : SHADER: : fragments: : COMPILATION_FAILED \ n" & lt; & lt; InfoLog & lt; & lt; STD: : endl;
}
//Link shaders
GLuint shaderProgram=glCreateProgram ();
GlAttachShader (shaderProgram vertexShader);
GlAttachShader (shaderProgram fragmentShader);
GlLinkProgram (shaderProgram);
//Check for linking errors
GlGetProgramiv (shaderProgram GL_LINK_STATUS, & amp; Success);
if (! Success) {
GlGetProgramInfoLog (shaderProgram, 512, NULL, infoLog);
STD: : cout & lt; & lt; "ERROR: : SHADER: : PROGRAM: : LINKING_FAILED \ n" & lt; & lt; InfoLog & lt; & lt; STD: : endl;
}
GlDeleteShader (vertexShader);
GlDeleteShader (fragmentShader);
GLuint VBO VAO;
GlGenVertexArrays (1, & amp; VAO);
GlGenBuffers (1, & amp; VBO);
//to Bind the Vertex Array Object first, then the Bind and set Vertex buffer (s) and the attribute pointer (s).
GlBindVertexArray (VAO);
GlBindBuffer (GL_ARRAY_BUFFER VBO);
GLfloat attrib []={(float) sin (glfwGetTime ()) * 0.5 f,
(float) cos (glfwGetTime ()) * 0.6 f,
F 0.0, 0.0} f;
//Update the value of the input attribute 0
GlVertexAttrib4fv (0, attrib);
GlEnableVertexAttribArray (0);
GlBindBuffer (GL_ARRAY_BUFFER, 0);//Note that this is allowed, the call to glVertexAttribPointer registered VBO as the currently bound vertex buffer object so afterwards we can safely unbind
GlBindVertexArray (0);//Unbind VAO (it 's always a good thing to Unbind any buffer/array to prevent strange bugs)
//Game loop
while (! GlfwWindowShouldClose (Windows))
{
//Check if any events have had activiated (key pressed, the mouse version etc.) and call corresponding response functions provides
GlfwPollEvents ();
//Render
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull