- glm::vec3 lightPos = glm::vec3(sin(d) * 10, 0, cos(d) * 10);
-
- drawPyramids(d, lightPos);
- drawLight(d, lightPos);
-
- glutSwapBuffers();
-}
-
-void attachShader(GLuint progId, const char* filePath, GLenum type) {
- GLuint shader = glCreateShader(type);
-
- if (!shader) {
- fprintf(stderr, "error creating shader\n");
- exit(1);
- }
-
- ifstream file(filePath);
- stringstream buffer;
- buffer << file.rdbuf();
- string str = buffer.str();
- const char* contents = str.c_str();
-
- glShaderSource(shader, 1, (const GLchar**)&contents, NULL);
- glCompileShader(shader);
- GLint success;
- glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
- if (!success) {
- GLchar log[1024];
- glGetShaderInfoLog(shader, 1024, NULL, log);
- fprintf(stderr, "error: %s\n", log);
- exit(1);
- }
- glAttachShader(progId, shader);
-}
-
-GLuint compileShaders(char* vertexShader, char* fragmentShader) {
- GLuint progId = glCreateProgram();
-
- attachShader(progId, vertexShader, GL_VERTEX_SHADER);
- attachShader(progId, fragmentShader, GL_FRAGMENT_SHADER);
-
- glLinkProgram(progId);
- GLint success = 0;
- glGetProgramiv(progId, GL_LINK_STATUS, &success);
- if (!success) {
- GLchar log[1024];
- glGetProgramInfoLog(progId, sizeof(log), NULL, log);
- fprintf(stderr, "error linking: %s\n", log);
- exit(1);
- }
-
- return progId;
-}
-
-#define BUFFER_OFFSET(i) ((char *)NULL + (i))
-
-GLuint setupBuffers(glm::vec3* vertices, glm::vec3* normals, GLuint progId) {
-
- GLfloat colors[] = {
- 0, 1, 0, 1,
- 1, 0, 0, 1,
- 0, 0, 1, 1,
-
- 0, 1, 0, 1,
- 1, 0, 0, 1,
- 0, 0, 1, 1,
-
- 0, 1, 0, 1,
- 1, 0, 0, 1,
- 0, 0, 1, 1,
-
- 0, 1, 0, 1,
- 1, 0, 0, 1,
- 0, 0, 1, 1
- };