diff options
Diffstat (limited to 'src/tutorial.cpp')
| -rw-r--r-- | src/tutorial.cpp | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/tutorial.cpp b/src/tutorial.cpp index e3f7a9d..aa9baef 100644 --- a/src/tutorial.cpp +++ b/src/tutorial.cpp @@ -1,9 +1,12 @@ // https://learnopengl.com/Getting-started/OpenGL
+// seriously consider GLFW et al.
+
#include <iostream>
#include <GL/glew.h>
-#include <GL/glut.h>
+//#include <GL/glut.h>
+#include <GL/freeglut.h>
#include "TutorialConfig.h"
@@ -16,6 +19,9 @@ GLuint VAO1_glob; void renderScene(void) {
+ float seconds = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
+ float greenValue = sin(seconds) / 2.0 + 0.5;
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
@@ -26,6 +32,8 @@ void renderScene(void) { glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glUseProgram(shaderProgram_glob);
+ glUniform4f(glGetUniformLocation (shaderProgram_glob, "ourColor") , 0,greenValue,0,1);
+
glBindVertexArray(VAO_glob);
glDrawArrays(GL_TRIANGLES, 0, 3);
@@ -81,8 +89,9 @@ int main(int argc, char **argv) { // init GLUT and create Window
glutInit(&argc, argv);
+ glutSetOption(GLUT_ALLOW_NEGATIVE_WINDOW_POSITION,true);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
- glutInitWindowPosition(100,100);
+ glutInitWindowPosition(-500,600);
glutInitWindowSize(320,320);
glutCreateWindow("Lighthouse3D - GLUT Tutorial");
glutIdleFunc(idle);
@@ -122,20 +131,39 @@ int main(int argc, char **argv) { exit(1); // or handle the error in a nicer way
}
+ int nrAttributes;
+ glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &nrAttributes);
+ std::cout << "Maximum nr of vertex attributes supported: " << nrAttributes << std::endl;
+
int success;
char infoLog[512];
- const char *vertexShaderSource = "#version 330 core\n"
- "layout (location = 0) in vec3 aPos;\n"
- "void main()\n"
- "{\n"
- " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
- "}\0";
- const char *fragmentShaderSource = "#version 330 core\n"
- "out vec4 FragColor; void main() { FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f); } \0";
-
- const char *fragmentShader1Source = "#version 330 core\n"
- "out vec4 FragColor; void main() { FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f); } \0";
+ const char *vertexShaderSource =
+ "#version 330 core\n"
+ "layout (location = 0) in vec3 aPos;\n"
+ "out vec4 vertexColor;\n"
+ "uniform vec4 ourColor;"
+ "void main(){"
+ "gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);"
+ "vertexColor = vec4(aPos.y,aPos.x,ourColor.y,1.0);"
+ "vertexColor = ourColor;"
+ "}\0";
+
+ const char *fragmentShaderSource =
+ "#version 330 core\n"
+ "out vec4 FragColor;"
+ "in vec4 vertexColor;"
+ "void main(){"
+ "FragColor = vertexColor;"
+ "}\0";
+
+ const char *fragmentShader1Source =
+ "#version 330 core\n"
+ "out vec4 FragColor;"
+ "in vec4 vertexColor;"
+ "void main(){"
+ "FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);"
+ "}\0";
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
|
