|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 3 | +<plist version="1.0"> |
| 4 | +<dict> |
| 5 | + <key>Kind</key> |
| 6 | + <string>Xcode.Xcode3.ProjectTemplateUnitKind</string> |
| 7 | + <key>Identifier</key> |
| 8 | + <string>me.huntto.dt.unit.LearnOpenGL.HelloTriangle</string> |
| 9 | + <key>Ancestors</key> |
| 10 | + <array> |
| 11 | + <string>com.apple.dt.unit.base</string> |
| 12 | + <string>com.apple.dt.unit.osxBase</string> |
| 13 | + </array> |
| 14 | + <key>Concrete</key> |
| 15 | + <true/> |
| 16 | + <key>SortOrder</key> |
| 17 | + <integer>50</integer> |
| 18 | + <key>Description</key> |
| 19 | + <string>This template creates a LearnOpenGL project of HelloTriangle.</string> |
| 20 | + <key>Targets</key> |
| 21 | + <array> |
| 22 | + <dict> |
| 23 | + <key>ProductType</key> |
| 24 | + <string>com.apple.product-type.tool</string> |
| 25 | + <key>TargetIdentifier</key> |
| 26 | + <string>com.apple.dt.commandLineToolTarget</string> |
| 27 | + <key>BuildPhases</key> |
| 28 | + <array> |
| 29 | + <dict> |
| 30 | + <key>Class</key> |
| 31 | + <string>Sources</string> |
| 32 | + </dict> |
| 33 | + <dict> |
| 34 | + <key>Class</key> |
| 35 | + <string>Frameworks</string> |
| 36 | + </dict> |
| 37 | + <dict> |
| 38 | + <key>Class</key> |
| 39 | + <string>CopyFiles</string> |
| 40 | + <key>DstPath</key> |
| 41 | + <string>/usr/share/man/man1/</string> |
| 42 | + <key>DstSubfolderSpec</key> |
| 43 | + <string>0</string> |
| 44 | + <key>RunOnlyForDeploymentPostprocessing</key> |
| 45 | + <string>YES</string> |
| 46 | + </dict> |
| 47 | + </array> |
| 48 | + <key>Frameworks</key> |
| 49 | + <array> |
| 50 | + <string>OpenGL</string> |
| 51 | + </array> |
| 52 | + </dict> |
| 53 | + </array> |
| 54 | + <key>Options</key> |
| 55 | + <array> |
| 56 | + <dict> |
| 57 | + <key>Identifier</key> |
| 58 | + <string>languageChoice</string> |
| 59 | + <key>Name</key> |
| 60 | + <string>Language:</string> |
| 61 | + <key>Description</key> |
| 62 | + <string>The primary implementation language for the command-line tool</string> |
| 63 | + <key>Default</key> |
| 64 | + <string>Swift</string> |
| 65 | + <key>Type</key> |
| 66 | + <string>popup</string> |
| 67 | + <key>Values</key> |
| 68 | + <array> |
| 69 | + <string>C++</string> |
| 70 | + </array> |
| 71 | + <key>Units</key> |
| 72 | + <dict> |
| 73 | + <key>C++</key> |
| 74 | + <dict> |
| 75 | + <key>Nodes</key> |
| 76 | + <array> |
| 77 | + <string>main.cpp:comments</string> |
| 78 | + <string>main.cpp:include</string> |
| 79 | + <string>main.cpp:functions</string> |
| 80 | + <string>main.cpp:settings</string> |
| 81 | + <string>main.cpp:shader_source</string> |
| 82 | + <string>main.cpp:main:content</string> |
| 83 | + <string>main.cpp:processInput</string> |
| 84 | + <string>main.cpp:framebuffer_size_callback</string> |
| 85 | + <string>glad.c</string> |
| 86 | + </array> |
| 87 | + <key>Definitions</key> |
| 88 | + <dict> |
| 89 | + <key>main.cpp:include</key> |
| 90 | + <string>#include <glad/glad.h> |
| 91 | +#include <GLFW/glfw3.h> |
| 92 | +
|
| 93 | +#include <iostream> |
| 94 | +</string> |
| 95 | + <key>main.cpp:main:content</key> |
| 96 | + <string>// glfw: initialize and configure |
| 97 | +// ------------------------------ |
| 98 | +glfwInit(); |
| 99 | +glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); |
| 100 | +glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); |
| 101 | +glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); |
| 102 | +glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // uncomment this statement to fix compilation on OS X |
| 103 | +
|
| 104 | +// glfw window creation |
| 105 | +// -------------------- |
| 106 | +GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); |
| 107 | +if (window == NULL) |
| 108 | +{ |
| 109 | + std::cout << "Failed to create GLFW window" << std::endl; |
| 110 | + glfwTerminate(); |
| 111 | + return -1; |
| 112 | +} |
| 113 | +glfwMakeContextCurrent(window); |
| 114 | +glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); |
| 115 | +
|
| 116 | +// glad: load all OpenGL function pointers |
| 117 | +// --------------------------------------- |
| 118 | +if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) |
| 119 | +{ |
| 120 | + std::cout << "Failed to initialize GLAD" << std::endl; |
| 121 | + return -1; |
| 122 | +} |
| 123 | +
|
| 124 | +
|
| 125 | +// build and compile our shader program |
| 126 | +// ------------------------------------ |
| 127 | +// vertex shader |
| 128 | +int vertexShader = glCreateShader(GL_VERTEX_SHADER); |
| 129 | +glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); |
| 130 | +glCompileShader(vertexShader); |
| 131 | +// check for shader compile errors |
| 132 | +int success; |
| 133 | +char infoLog[512]; |
| 134 | +glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success); |
| 135 | +if (!success) |
| 136 | +{ |
| 137 | + glGetShaderInfoLog(vertexShader, 512, NULL, infoLog); |
| 138 | + std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl; |
| 139 | +} |
| 140 | +// fragment shader |
| 141 | +int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); |
| 142 | +glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL); |
| 143 | +glCompileShader(fragmentShader); |
| 144 | +// check for shader compile errors |
| 145 | +glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success); |
| 146 | +if (!success) |
| 147 | +{ |
| 148 | + glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog); |
| 149 | + std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl; |
| 150 | +} |
| 151 | +// link shaders |
| 152 | +int shaderProgram = glCreateProgram(); |
| 153 | +glAttachShader(shaderProgram, vertexShader); |
| 154 | +glAttachShader(shaderProgram, fragmentShader); |
| 155 | +glLinkProgram(shaderProgram); |
| 156 | +// check for linking errors |
| 157 | +glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); |
| 158 | +if (!success) { |
| 159 | + glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog); |
| 160 | + std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << std::endl; |
| 161 | +} |
| 162 | +glDeleteShader(vertexShader); |
| 163 | +glDeleteShader(fragmentShader); |
| 164 | +
|
| 165 | +// set up vertex data (and buffer(s)) and configure vertex attributes |
| 166 | +// ------------------------------------------------------------------ |
| 167 | +float vertices[] = { |
| 168 | + -0.5f, -0.5f, 0.0f, // left |
| 169 | + 0.5f, -0.5f, 0.0f, // right |
| 170 | + 0.0f, 0.5f, 0.0f // top |
| 171 | +}; |
| 172 | +
|
| 173 | +unsigned int VBO, VAO; |
| 174 | +glGenVertexArrays(1, &VAO); |
| 175 | +glGenBuffers(1, &VBO); |
| 176 | +// bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s). |
| 177 | +glBindVertexArray(VAO); |
| 178 | +
|
| 179 | +glBindBuffer(GL_ARRAY_BUFFER, VBO); |
| 180 | +glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); |
| 181 | +
|
| 182 | +glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); |
| 183 | +glEnableVertexAttribArray(0); |
| 184 | +
|
| 185 | +// note that this is allowed, the call to glVertexAttribPointer registered VBO as the vertex attribute's bound vertex buffer object so afterwards we can safely unbind |
| 186 | +glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 187 | +
|
| 188 | +// You can unbind the VAO afterwards so other VAO calls won't accidentally modify this VAO, but this rarely happens. Modifying other |
| 189 | +// VAOs requires a call to glBindVertexArray anyways so we generally don't unbind VAOs (nor VBOs) when it's not directly necessary. |
| 190 | +glBindVertexArray(0); |
| 191 | +
|
| 192 | +
|
| 193 | +// uncomment this call to draw in wireframe polygons. |
| 194 | +//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); |
| 195 | +
|
| 196 | +// render loop |
| 197 | +// ----------- |
| 198 | +while (!glfwWindowShouldClose(window)) |
| 199 | +{ |
| 200 | + // input |
| 201 | + // ----- |
| 202 | + processInput(window); |
| 203 | +
|
| 204 | + // render |
| 205 | + // ------ |
| 206 | + glClearColor(0.2f, 0.3f, 0.3f, 1.0f); |
| 207 | + glClear(GL_COLOR_BUFFER_BIT); |
| 208 | +
|
| 209 | + // draw our first triangle |
| 210 | + glUseProgram(shaderProgram); |
| 211 | + glBindVertexArray(VAO); // seeing as we only have a single VAO there's no need to bind it every time, but we'll do so to keep things a bit more organized |
| 212 | + glDrawArrays(GL_TRIANGLES, 0, 3); |
| 213 | + // glBindVertexArray(0); // no need to unbind it every time |
| 214 | +
|
| 215 | + // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) |
| 216 | + // ------------------------------------------------------------------------------- |
| 217 | + glfwSwapBuffers(window); |
| 218 | + glfwPollEvents(); |
| 219 | +} |
| 220 | +
|
| 221 | +// optional: de-allocate all resources once they've outlived their purpose: |
| 222 | +// ------------------------------------------------------------------------ |
| 223 | +glDeleteVertexArrays(1, &VAO); |
| 224 | +glDeleteBuffers(1, &VBO); |
| 225 | +
|
| 226 | +// glfw: terminate, clearing all previously allocated GLFW resources. |
| 227 | +// ------------------------------------------------------------------ |
| 228 | +glfwTerminate(); |
| 229 | +return 0;</string> |
| 230 | + <key>main.cpp:processInput</key> |
| 231 | + <string> |
| 232 | +// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly |
| 233 | +// --------------------------------------------------------------------------------------------------------- |
| 234 | +void processInput(GLFWwindow *window) |
| 235 | +{ |
| 236 | + if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) |
| 237 | + glfwSetWindowShouldClose(window, true); |
| 238 | +}</string> |
| 239 | + <key>main.cpp:framebuffer_size_callback</key> |
| 240 | + <string> |
| 241 | +// glfw: whenever the window size changed (by OS or user resize) this callback function executes |
| 242 | +// --------------------------------------------------------------------------------------------- |
| 243 | +void framebuffer_size_callback(GLFWwindow* window, int width, int height) |
| 244 | +{ |
| 245 | + // make sure the viewport matches the new window dimensions; note that width and |
| 246 | + // height will be significantly larger than specified on retina displays. |
| 247 | + glViewport(0, 0, width, height); |
| 248 | +}</string> |
| 249 | + <key>main.cpp:functions</key> |
| 250 | + <string>void framebuffer_size_callback(GLFWwindow* window, int width, int height); |
| 251 | +void processInput(GLFWwindow *window); |
| 252 | +</string> |
| 253 | + <key>main.cpp:settings</key> |
| 254 | + <string>// settings |
| 255 | +const unsigned int SCR_WIDTH = 800; |
| 256 | +const unsigned int SCR_HEIGHT = 600; |
| 257 | +</string> |
| 258 | + <key>main.cpp:shader_source</key> |
| 259 | + <string>const char *vertexShaderSource = "#version 330 core\n" |
| 260 | + "layout (location = 0) in vec3 aPos;\n" |
| 261 | + "void main()\n" |
| 262 | + "{\n" |
| 263 | + " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" |
| 264 | + "}\0"; |
| 265 | +const char *fragmentShaderSource = "#version 330 core\n" |
| 266 | + "out vec4 FragColor;\n" |
| 267 | + "void main()\n" |
| 268 | + "{\n" |
| 269 | + " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" |
| 270 | + "}\n\0"; |
| 271 | +</string> |
| 272 | + </dict> |
| 273 | + </dict> |
| 274 | + </dict> |
| 275 | + </dict> |
| 276 | + </array> |
| 277 | + <key>Project</key> |
| 278 | + <dict> |
| 279 | + <key>SharedSettings</key> |
| 280 | + <dict> |
| 281 | + <key>HEADER_SEARCH_PATHS</key> |
| 282 | + <array> |
| 283 | + <string>$(GLFW_PATH)/include</string> |
| 284 | + <string>$(GLAD_PATH)/include</string> |
| 285 | + </array> |
| 286 | + <key>OTHER_LDFLAGS</key> |
| 287 | + <array> |
| 288 | + <string>-ObjC -all_load -weak_library $(GLFW_PATH)/lib/libglfw.dylib</string> |
| 289 | + </array> |
| 290 | + </dict> |
| 291 | + </dict> |
| 292 | + <key>Definitions</key> |
| 293 | + <dict> |
| 294 | + <key>*:main</key> |
| 295 | + <dict> |
| 296 | + <key>Beginning</key> |
| 297 | + <string>int main(int argc, const char * argv[]) {</string> |
| 298 | + <key>End</key> |
| 299 | + <string>}</string> |
| 300 | + <key>Indent</key> |
| 301 | + <integer>1</integer> |
| 302 | + </dict> |
| 303 | + <key>glad.c</key> |
| 304 | + <dict> |
| 305 | + <key>Path</key> |
| 306 | + <string>glad.c</string> |
| 307 | + </dict> |
| 308 | + </dict> |
| 309 | +</dict> |
| 310 | +</plist> |
0 commit comments