Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fill in the blanks myshader.vs #version 330 core layout (location = ____________________________) in vec3 aPos; layout (location = ____________________________) in vec3 aNormal; out vec3 FragPos;

Fill in the blanks

myshader.vs

#version 330 core

layout (location = ____________________________) in vec3 aPos;

layout (location = ____________________________) in vec3 aNormal;

out vec3 FragPos;

out vec3 Normal;

uniform mat4 model;

uniform mat4 view;

uniform mat4 projection;

void main()

{

FragPos = vec3(model * vec4(aPos, 1.0));

Normal = mat3(transpose(inverse(model))) * aNormal;

gl_Position = ____________________________ * vec4(FragPos, 1.0);

}

myshader.fs

#version 330 core

out vec4 FragColor;

in vec3 Normal;

in vec3 FragPos;

uniform vec3 lightPos;

uniform vec3 viewPos;

uniform vec3 lightColor;

uniform vec3 objectColor;

void main()

{

vec3 ambient = lightColor;

vec3 norm = normalize(Normal);

vec3 lightDir = normalize(____________________________);

float diff = max(dot(____________________________), 0.0);

vec3 diffuse = diff * lightColor;

vec3 result = (____________________________) * objectColor;

FragColor = vec4(result, 1.0);

}

main.cpp

...

Shader myShader("myshader.vs", "myshader.vs");

//36 vertices and normals for a cube

float vertices[] = {

-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,

0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,

0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,

... ...

};

unsigned int VBO, cubeVAO;

glGenVertexArrays(1, &cubeVAO);

glGenBuffers(1, &VBO);

glBindBuffer(GL_ARRAY_BUFFER, VBO);

glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glBindVertexArray(____________________________);

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);

glEnableVertexAttribArray(____________________________);

glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));

glEnableVertexAttribArray(____________________________);

while (!glfwWindowShouldClose(window))

{

glClearColor(0.1f, 0.1f, 0.1f, 1.0f);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

myShader.use();

myShader.setVec3("objectColor", 1.0f, 0.5f, 0.31f);

myShader.setVec3("lightColor", 1.0f, 1.0f, 1.0f);

myShader.setVec3("lightPos", lightPos);

myShader.setVec3("viewPos", cameraPosition);

myShader.setMat4("projection", projection);

myShader.setMat4("view", view);

myShader.setMat4("model", model);

glBindVertexArray(cubeVAO);

glDrawArrays(GL_TRIANGLES, 0, ____________________________);

glfwSwapBuffers(window);

glfwPollEvents();

}

glDeleteVertexArrays(1, &cubeVAO);

glDeleteBuffers(1, &VBO);

glfwTerminate();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

More Books

Students also viewed these Databases questions

Question

Where do you see yourself in 5/10 years?

Answered: 1 week ago

Question

Discuss how selfesteem is developed.

Answered: 1 week ago