Changeset 8b7cfcf in opengl-game
- Timestamp:
- Aug 5, 2017, 2:24:43 AM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- d0b9596
- Parents:
- c40990d
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
makefile
rc40990d r8b7cfcf 13 13 $(CC) $? $(DEP) $(CFLAGS) -o $@ 14 14 15 game: mygame.cpp common/shader.cpp common/texture.cpp common/controls-new.cpp15 game: game.cpp common/shader.cpp common/texture.cpp common/controls-new.cpp 16 16 $(CC) $? $(DEP) $(CFLAGS) -o $@ 17 17 -
new-game.cpp
rc40990d r8b7cfcf 1 // NEXT STEP; Modify the vertex shader 2 1 3 #include "logger.h" 2 4 … … 81 83 }; 82 84 83 GLuint vbo = 0; 84 glGenBuffers(1, &vbo); 85 glBindBuffer(GL_ARRAY_BUFFER, vbo); 85 GLfloat colors[] = { 86 1.0, 0.0, 0.0, 87 0.0, 1.0, 0.0, 88 0.0, 0.0, 1.0, 89 }; 90 91 GLuint points_vbo = 0; 92 glGenBuffers(1, &points_vbo); 93 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 86 94 glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW); 95 96 GLuint colors_vbo = 0; 97 glGenBuffers(1, &colors_vbo); 98 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 99 glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW); 87 100 88 101 GLuint vao = 0; 89 102 glGenVertexArrays(1, &vao); 90 103 glBindVertexArray(vao); 104 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 105 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); 106 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 107 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); 108 91 109 glEnableVertexAttribArray(0); 92 glBindBuffer(GL_ARRAY_BUFFER, vbo); 93 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); 94 95 //string vertexShaderString = loadShader(); 110 glEnableVertexAttribArray(1); 96 111 97 112 GLuint vs = loadShader(GL_VERTEX_SHADER, "./test.vert"); … … 101 116 glAttachShader(shader_program, vs); 102 117 glAttachShader(shader_program, fs); 118 119 // this must be used on OSX instead of using layout() in the shader 120 glBindAttribLocation(shader_program, 0, "vertex_position"); 121 glBindAttribLocation(shader_program, 1, "vertex_color"); 122 103 123 glLinkProgram(shader_program); 104 124 -
test.frag
rc40990d r8b7cfcf 1 1 #version 410 2 2 3 //uniform vec4 inputColor;4 out vec4 frag Color;3 in vec3 color; 4 out vec4 frag_color; 5 5 6 6 void main() { 7 //fragColor = inputColor; 8 fragColor = vec4(0.5, 0.0, 0.5, 1.0); 7 frag_color = vec4(color, 1.0); 9 8 } -
test.vert
rc40990d r8b7cfcf 1 1 #version 410 2 2 3 // using layout() doens't work on OSX, so use glBindAttribLocation() in the C++ code instead 4 // layout(position = 0) in vec3 vertex_position; 5 // layout(position = 1) in vec3 vertex_color; 6 3 7 in vec3 vertex_position; 8 in vec3 vertex_color; 9 10 out vec3 color; 4 11 5 12 void main() { 13 color = vertex_color; 6 14 gl_Position = vec4(vertex_position, 1.0); 7 15 }
Note:
See TracChangeset
for help on using the changeset viewer.