-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.cpp
46 lines (36 loc) · 1.31 KB
/
renderer.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
#include "renderer.h"
#include <iostream>
Renderer::Renderer()
{
}
void GLClearError()
{
while (glGetError() != GL_NO_ERROR);
}
bool GLLogCall(const char* function, const char* file, int line){
while (GLenum error = glGetError()){
std::cout << "[OpenGL error] " <<error<<" : "<<function<<" "<<file<<":"<<line<<std::endl;
return false;
}
return true;
}
void Renderer::render(const ChessBoard& board, const std::vector<ChessPiece>& pieces, const glm::mat4& viewMatrix, const glm::mat4& projectionMatrix) {
Shader shader("shaders/SimpleVertexShader.vertexshader", "shaders/SimpleFragmentShader.fragmentshader");
shader.use();
// Set view and projection matrices
// unsigned int viewLoc = glGetUniformLocation(shader.programID, "view");
// unsigned int projLoc = glGetUniformLocation(shader.programID, "projection");
// glUniformMatrix4fv(viewLoc, 1, GL_FALSE, &viewMatrix[0][0]);
// glUniformMatrix4fv(projLoc, 1, GL_FALSE, &projectionMatrix[0][0]);
shader.setUniformMat4("view", viewMatrix);
shader.setUniformMat4("projection", projectionMatrix);
// Render chessboard and pieces
board.draw();
for (const auto& piece : pieces) {
piece.draw(shader);
}
}
void Renderer::Clear() const
{
GLCall(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
}