Skip to content

Commit 9b8760b

Browse files
committed
Small refactorizations
1 parent 13b6341 commit 9b8760b

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

include/matgui/draw.h

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ void setDimensions(int width, int height);
100100
void pushViewport(int x, int y, int width, int height);
101101
void popViewport();
102102

103+
// Fill the current render buffer (often the screen) with a single color
104+
void clear(float r, float g, float b, float a, bool depth = true);
105+
103106
// clang-format on
104107

105108
} // namespace matgui

include/matgui/texture.h

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#pragma once
99

1010
#include <memory>
11-
#include <stdexcept>
1211
#include <string>
1312
#include <vector>
1413

src/draw.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,9 @@ void QuitDrawModule() {
379379
lineProgram.program.reset();
380380
}
381381

382+
void clear(float r, float g, float b, float a, bool depth) {
383+
glClearColor(r, g, b, a);
384+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT * depth);
385+
}
386+
382387
} // namespace matgui

src/shaderobject.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "shaderobject.h"
22
#include "translateshader.h"
33
#include <iostream>
4-
#include <sstream>
4+
// #include <sstream>
55
#include <stdexcept>
66
#include <vector>
77

@@ -13,8 +13,8 @@ namespace matgui {
1313
using namespace std;
1414

1515
#ifdef __EMSCRIPTEN__
16-
cout << info << endl;
17-
cout << code << endl;
16+
cerr << info << endl;
17+
cerr << code << endl;
1818

1919
#endif
2020

@@ -28,11 +28,11 @@ namespace matgui {
2828

2929
if (firstColon == string::npos && firstParen == string::npos &&
3030
secondParen == string::npos) {
31-
cout << info << endl;
32-
cout << code << endl;
31+
cerr << info << endl;
32+
cerr << code << endl;
3333
}
3434

35-
cout << info;
35+
cerr << info;
3636
// auto b = info.begin();
3737
// cout << "line: " << string(b + firstColon + 1, b + firstParen) <<
3838
// endl; cout << "col: " << string(b + firstParen + 1, b + secondParen)

src/shaderprogram.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void ShaderProgram::loadObject(GLint type, std::filesystem::path path) {
156156
if (!file || !*file) {
157157
cout << "could not open " << typeMap.at(type) << " shader file " << path
158158
<< endl;
159-
throw std::runtime_error{"could not open shader file"};
159+
throw std::runtime_error{"could not open shader file " + path.string()};
160160
return;
161161
}
162162
std::string code((std::istreambuf_iterator<char>(*file)),

src/window.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "matgui/window.h"
99
#include "matgui/application.h"
10-
#include "matgui/common-gl.h"
10+
// #include "matgui/common-gl.h"
1111
#include "matgui/draw.h"
1212
#include "windowdata.h"
1313
#include <iostream>
@@ -128,8 +128,7 @@ Window::~Window() {
128128
void Window::clear() {
129129
_windowData->context.makeCurrent(sdl::WindowView{_windowData->window});
130130
auto &color = currentStyle.fill;
131-
glClearColor(color.r, color.g, color.b, color.a);
132-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
131+
matgui::clear(color.r, color.g, color.b, color.a);
133132
}
134133

135134
void Window::draw() {

0 commit comments

Comments
 (0)