Shader Uniform
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -112,9 +112,7 @@ int main(void){
|
||||
}
|
||||
|
||||
//Main window creation
|
||||
GLFWwindow* window;
|
||||
|
||||
window = glfwCreateWindow(640, 480, "OpenGl practice", NULL, NULL);
|
||||
GLFWwindow* window = glfwCreateWindow(640, 480, "OpenGl practice", NULL, NULL);
|
||||
if (!window){
|
||||
std::cout << "Window could not be created!" << std::endl;
|
||||
glfwTerminate();
|
||||
@@ -123,9 +121,11 @@ int main(void){
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
glfwSwapInterval(1); //v-sync
|
||||
|
||||
//GLEW init
|
||||
if (glewInit() != GLEW_OK) {
|
||||
std::cout << "GLEW Error" << std::endl;
|
||||
std::cout << "GLEW could not be initialized" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -169,15 +169,30 @@ int main(void){
|
||||
unsigned int shader = CreateShader(source.VertexSource, source.FragmentSource);
|
||||
glUseProgram(shader);
|
||||
|
||||
//need to bound a shader before this
|
||||
GLCall(int location = glGetUniformLocation(shader, "u_Color")); //finding u_Color location
|
||||
ASSERT(location != -1);
|
||||
GLCall(glUniform4f(location, 0.8f, 0.3f, 0.8f, 1.0f));
|
||||
|
||||
GLCall(glBindBuffer(GL_ARRAY_BUFFER, 0)); //unbinding the buffer
|
||||
|
||||
float r = 0.0f;
|
||||
float increment = 0.05f;
|
||||
//Main loop
|
||||
while (!glfwWindowShouldClose(window)){
|
||||
/* Render here */
|
||||
GLCall(glClear(GL_COLOR_BUFFER_BIT));
|
||||
|
||||
GLCall(glUniform4f(location, r, 0.3f, 0.8f, 1.0f));
|
||||
GLCall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr));
|
||||
|
||||
if (r > 1.0f)
|
||||
increment = -0.05f;
|
||||
else if (r < 0.0f)
|
||||
increment = 0.05f;
|
||||
|
||||
r += increment;
|
||||
|
||||
/* Swap front and back buffers */
|
||||
GLCall(glfwSwapBuffers(window));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user