This commit is contained in:
2018-05-12 11:00:18 +02:00
40 changed files with 640 additions and 153 deletions

View File

@@ -112,12 +112,16 @@ MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) {
grabGesture(Qt::PinchGesture);
auto format = QSurfaceFormat();
//format.setVersion(4,3);
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setVersion(3, 4);
format.setSamples(2);
//format.setProfile(QSurfaceFormat::CoreProfile);
format.setProfile(QSurfaceFormat::CompatibilityProfile);
format.setOption(QSurfaceFormat::DebugContext);
setFormat(format);
setFormat(format);
auto ver = format.version();
std::cout << "OpenGL Context Version: " << ver.first << "." << ver.second << std::endl;
}
@@ -126,6 +130,32 @@ void MapView3D::initializeGL() {
//setFormat(QGLFormat(QGL::SampleBuffers));
QOpenGLWidget::initializeGL();
initializeOpenGLFunctions();
logger = new QOpenGLDebugLogger(this);
if (logger->initialize()) {
connect(logger, &QOpenGLDebugLogger::messageLogged, [] (const QOpenGLDebugMessage& debugMessage) {
std::cout << debugMessage.message().toStdString() << std::endl;
});
logger->startLogging(QOpenGLDebugLogger::SynchronousLogging);
}
// Print device info
const GLubyte* vendor = glGetString(GL_VENDOR);
const GLubyte* renderer = glGetString(GL_RENDERER);
const GLubyte* version = glGetString(GL_VERSION);
std::cout << "Device info: ";
if (vendor) {
std::cout << (const char*) vendor << " ";
}
if (renderer) {
std::cout << (const char*) renderer << " ";
}
if (version) {
std::cout << (const char*) version << " ";
}
std::cout << std::endl;
// this should be the default!!
glCullFace(GL_BACK);
@@ -134,8 +164,7 @@ void MapView3D::initializeGL() {
// additional settings
glEnable(GL_DEPTH_TEST);
glClearColor(0.9, 0.9, 1.0, 1.0);
glClearColor(0.5, 0.5, 0.5, 1.0);
}
void MapView3D::paintGL() {
@@ -293,7 +322,7 @@ void MapView3D::layerChange() {
void MapView3D::draw() {
static RenderSettings rs = RenderSettings(new Shader());
static RenderSettings rs = RenderSettings(new Shader(), this);
// view
QMatrix4x4 V;
@@ -305,7 +334,7 @@ void MapView3D::draw() {
V.rotate(rot.z, 0.0, 0.0, 1.0);
V.translate(center.x, center.y, center.z);
float far = 200; // TODO
float farPlane = 200; // TODO
// projection
QMatrix4x4 P;
@@ -316,14 +345,14 @@ void MapView3D::draw() {
float h = height() / 30;
viewport.size.x = w;
viewport.size.y = h;
P.perspective(45.0f, aspect, 0.01, far);
P.perspective(45.0f, aspect, 0.01, farPlane);
} else {
// default size: 50 * 50/aspect meters
float w = 50.0f;
float h = 50.0f * height() / width();
viewport.size.x = w;
viewport.size.y = h;
P.ortho(-w, +w, -h, +h, 0.1f, +far);
P.ortho(-w, +w, -h, +h, 0.1f, +farPlane);
}
rs.shader->bind();