-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-example.cpp
57 lines (45 loc) · 1.55 KB
/
test-example.cpp
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
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
//test flow
//default height and width
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
int main(){
//initialising OpenGL with version OpenGL3.3 and Core profile
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
//Creating window object
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Hello OpenGL", NULL, NULL);
if(window == NULL){
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
//call window object
glfwMakeContextCurrent(window);
//initialise GLAD
if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
//the openGL rendering window
glViewport(0, 0, 800, 600);
//call framebuffer_size_callback whenver screen is resized
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
//till stopped by the user
while(!glfwWindowShouldClose(window)){
glfwSwapBuffers(window);
glfwPollEvents();
}
//clean GLFW resources
glfwTerminate();
return 0;
}
//framebuffer size callback function defination
void framebuffer_size_callback(GLFWwindow* window, int width, int height){
glViewport(0, 0, width, height);
}