-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
72 lines (55 loc) · 1.8 KB
/
main.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "glad/include/glad/glad.h"
#include <GLFW/glfw3.h>
#include "opengl_ults.h"
#include <iostream>
#include <math.h>
#include "Shader.h"
const char *fragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"in vec3 ourColor;\n"
"void main()\n"
"{\n"
" FragColor = vec4(ourColor, 1.0f);\n"
"}\n\0";
// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 800;
int main()
{
float vertices[] = {
// positions // colors
0.5f, -0.5f, 0.0f, 1.f, 0.0f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top
};
/*
int indices[] = { // note that we start from 0!
0, 1, 3, // first Triangle
1, 2, 3 // second Triangle
};
*/
Opengl_ults myclass;
myclass.init();
myclass.setupWindows(3,3);
GLFWwindow* window = myclass.createWindows(SCR_WIDTH,SCR_HEIGHT, "LearnOpenGL");
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
return -1;
}
int vertexShader = myclass.createVertexShader();
int fragmentShader = myclass.createFragmentShader(fragmentShaderSource);
int programShader = myclass.linkShaders(vertexShader, fragmentShader);
int vao = myclass.linkingAttributes(vertices, sizeof(vertices));
//int vao = myclass.ElementBuffer(vertices, sizeof(vertices), indices, sizeof(indices));
while (!glfwWindowShouldClose(window))
{
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
myclass.processInput(window, GLFW_KEY_ESCAPE);
myclass.drawTriangle(programShader, vao);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}