-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
85 lines (66 loc) · 2.25 KB
/
Copy pathMain.cpp
File metadata and controls
85 lines (66 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include"Model.h"
const unsigned int width = 800;
const unsigned int height = 800;
int main()
{
// Initialize GLFW
glfwInit();
// Configure GLFW
// Set the OpenGL version to 3.3 and use the core profile
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Create a windowed mode window and its OpenGL context
GLFWwindow* window = glfwCreateWindow(width, height, "OpenGL", NULL, NULL);
// Check if the window was created successfully
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
// Make the window's context current
glfwMakeContextCurrent(window);
// Load OpenGL function pointers using GLAD
gladLoadGL();
// Set the viewport
glViewport(0, 0, width, height);
// Create shader program
Shader shaderProgram("default.vert", "default.frag");
// Light properties
glm::vec4 lightColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
glm::vec3 lightPos = glm::vec3(0.5f, 0.5f, 0.5f);
glm::mat4 lightModel = glm::mat4(1.0f);
lightModel = glm::translate(lightModel, lightPos);
// Set the uniforms for the shaders
shaderProgram.Activate();
// Send the light color and position to the shader
glUniform4f(glGetUniformLocation(shaderProgram.ID, "lightColor"), lightColor.x, lightColor.y, lightColor.z, lightColor.w);
glUniform3f(glGetUniformLocation(shaderProgram.ID, "lightPos"), lightPos.x, lightPos.y, lightPos.z);
// Enable depth testing
glEnable(GL_DEPTH_TEST);
Camera camera(width, height, glm::vec3(0.0f, 0.0f, 2.0f));
Model model("models/wooden/scene.gltf");
// Main loop
while (!glfwWindowShouldClose(window))
{
// Set the clear color and clear the screen
glClearColor(0.07f, 0.13f, 0.17f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Handle camera inputs
camera.Inputs(window);
// Update and send the camera matrix to the shader
camera.updateMatrix(45.0f, 0.1f, 100.0f);
model.Draw(shaderProgram, camera);
// Unbind the texture
glfwSwapBuffers(window);
// Poll for and process events
glfwPollEvents();
};
// Deallocate resources
shaderProgram.Delete();
// Clean up and exit
glfwDestroyWindow(window);
glfwTerminate();
return 0;
};