Changeset 644a2e4 in opengl-game


Ignore:
Timestamp:
Jul 20, 2017, 2:36:56 AM (8 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
22b2c37
Parents:
516668e
Message:

Finish the triangle drawing program

File:
1 edited

Legend:

Unmodified
Added
Removed
  • new-game.cpp

    r516668e r644a2e4  
    2121      return 1;
    2222   }
    23    glfwMakeContextCurrent       (window);
     23   glfwMakeContextCurrent(window);
    2424   glewExperimental = GL_TRUE;
    2525   glewInit();
     
    4343   glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
    4444
    45    GLuint vao=0;
     45   GLuint vao = 0;
    4646   glGenVertexArrays(1, &vao);
    4747   glBindVertexArray(vao);
     
    5050   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    5151
     52   const char* vertex_shader =
     53   "#version 410\n"
     54   "in vec3 vp;"
     55   "void main() {"
     56   "   gl_Position = vec4(vp, 1.0);"
     57   "}";
     58
     59   GLuint vs = glCreateShader(GL_VERTEX_SHADER);
     60   glShaderSource(vs, 1, &vertex_shader, NULL);
     61   glCompileShader(vs);
     62
     63   const char* fragment_shader =
     64   "#version 410\n"
     65   "out vec4 frag_color;"
     66   "void main() {"
     67   "   frag_color = vec4(0.5, 0.0, 0.5, 1.0);"
     68   "}";
     69
     70   GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
     71   glShaderSource(fs, 1, &fragment_shader, NULL);
     72   glCompileShader(fs);
     73
     74   GLuint shader_program = glCreateProgram();
     75   glAttachShader(shader_program, vs);
     76   glAttachShader(shader_program, fs);
     77   glLinkProgram(shader_program);
     78
     79   while (!glfwWindowShouldClose(window)) {
     80      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     81      glUseProgram(shader_program);
     82      glBindVertexArray(vao);
     83      glDrawArrays(GL_TRIANGLES, 0, 3);
     84      glfwPollEvents();
     85      glfwSwapBuffers(window);
     86   }
     87
    5288   glfwTerminate();
    5389   return 0;
Note: See TracChangeset for help on using the changeset viewer.