-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManager.cpp
73 lines (64 loc) · 2.02 KB
/
Manager.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
73
//
// Manager.cpp
// GLFWosxTEST1
//
// Created by 王宇鑫 on 2017/9/7.
// Copyright © 2017年 王宇鑫. All rights reserved.
//
#include "Manager.hpp"
#include "Displayer.hpp"
#include <iostream>
#include <cmath>
using namespace std;
Manager& Manager::manager = Manager::initManager();
Manager::Manager()
{
graphics.push_back(new Graphic());
}
Manager& Manager::initManager()
{
return *(new Manager());
}
void Manager::render()
{
//clear
glad_glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glad_glClear(GL_COLOR_BUFFER_BIT);
//use
glad_glUseProgram(Displayer::displayer.shaderProgram);
//color
/* GLfloat timeValue = glfwGetTime();
GLfloat greenValue = (sin(timeValue) / 2) + 0.5;
GLfloat redValue = 1 / greenValue;
GLfloat blueValue = 0.5;
GLint vertexColorLocation = glad_glGetUniformLocation(Displayer::displayer.shaderProgram, "ourColor");
glad_glUniform4f(vertexColorLocation, redValue, greenValue, blueValue, 1.0f);
*/
//draw
glad_glBindVertexArray(Displayer::displayer.VAO);
// glad_glDrawArrays(GL_TRIANGLES, 0, 3);
glad_glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glad_glBindVertexArray(0);
}
void Manager::bufferData()
{
glad_glBufferData(GL_ARRAY_BUFFER, graphics.front()->size(), graphics.front()->pointer(), GL_STATIC_DRAW);
glad_glBufferData(GL_ELEMENT_ARRAY_BUFFER, graphics.front()->indicesSize(), graphics.front()->getIndices(), GL_STATIC_DRAW);
}
void Manager::mainloop()
{
Displayer::displayer.mainloop();
}
void Manager::errorCallback(int error, const char* description)
{
cerr << "error NO." << error << " : " << description << endl;
}
void Manager::keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_Q && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);
else if (key == GLFW_KEY_L && action == GLFW_PRESS)
glad_glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
else if (key == GLFW_KEY_F && action == GLFW_PRESS)
glad_glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}