Lesson 5

Vytvořte Lambertův shader (viz. přednáška)

uniform vec3 lightPosition;   //the shader has light position

 

…//somewhere in C++ code

glUseProgram(programID);

...
GLint myLoc = glGetUniformLocation(programID, “lightPosition”);
glProgramUniform3f(programID, myLoc, pos.x, pos.y, pos.z); // aktualizace dat

...

glDrawArray(...);

...
glUseProgram(0);

glEnable(GL_DEPTH_TEST);
//třídění ploch podle vzdálenosti (více v dalších přednáškách)

GLSL syntax highlighting 

GLSL language integration ( https://marketplace.visualstudio.com/items?itemName=DanielScherzer.GLSL )

NShader ( https://marketplace.visualstudio.com/items?itemName=AlexandreMutel.NShader )


models (struct) [models.zip]
modely v2 [models2.zip]

glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);

GLuint vbo = 0;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

/*
void glVertexAttribPointer(	
   GLuint index,  //index of the generic vertex attribute to be modified.
   GLint size,    //number of components per generic vertex attribute.
   GLenum type,   //data type of each component in the array. 
   GLboolean normalized, //specifies whether fixed-point data values should be normalized.
   GLsizei stride,       //byte offset between consecutive generic vertex attributes.
   const GLvoid * pointer);  //offset of the first component of the first generic vertex attribute in the array in the data store.
*/
	
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,6*sizeof(float),(GLvoid*)0);
glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,6*sizeof(float),(GLvoid*)(3*sizeof(float)));
//([float, float, float], [float, float, float]) 3xfloat position, 3xfloat normal
</pre>

 
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 vertNormal;

glBindVertexArray(0); glDrawArrays(GL_TRIANGLES, 0, pocetPrvku); 

Pro načítání shaderu můžete použít toto (ShaderLoader.zip)

ShaderLoader *loader = new ShaderLoader();
GLuint shaderProgram = loader->loadShader("./shaders/vertex.glsl", "./shaders/fragment.glsl");