From b188cb992c54b59d45c956c3ab88324984712db0 Mon Sep 17 00:00:00 2001 From: kazu Date: Fri, 15 Jul 2016 15:21:44 +0200 Subject: [PATCH] will try some openGL on android --- main.cpp | 48 ++++++++++++++++++++--------- map/MapView.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ map/MapView.h | 26 ++++++++++++++++ yasmin.pro | 6 ++-- 4 files changed, 145 insertions(+), 17 deletions(-) create mode 100644 map/MapView.cpp create mode 100644 map/MapView.h diff --git a/main.cpp b/main.cpp index 9ba96e7..0b623d0 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,12 @@ #include #include +#include +#include +#include #include "sensors/SensorFactory.h" - +#include "map/MapView.h" #include @@ -25,27 +28,42 @@ public: }; int main(int argc, char *argv[]) { -// test(); - LeListener listener; - WiFiSensor& wifi = SensorFactory::getWiFi(); - wifi.addListener(&listener); - wifi.start(); +//// test(); +// LeListener listener; +// WiFiSensor& wifi = SensorFactory::getWiFi(); +// wifi.addListener(&listener); +// wifi.start(); -// AccelerometerSensor& acc = SensorFactory::getAccelerometer(); -// acc.addListener(&listener); -// acc.start(); +//// AccelerometerSensor& acc = SensorFactory::getAccelerometer(); +//// acc.addListener(&listener); +//// acc.start(); - StepSensor& steps = SensorFactory::getSteps(); - steps.addListener(&listener); - steps.start();; +// StepSensor& steps = SensorFactory::getSteps(); +// steps.addListener(&listener); +// steps.start();; - std::this_thread::sleep_for(std::chrono::seconds(10000)); +// std::this_thread::sleep_for(std::chrono::seconds(10000)); -// QGuiApplication app(argc, argv); + //QGuiApplication app(argc, argv); + QApplication app(argc, argv); + + QMainWindow* win = new QMainWindow(); + + QVBoxLayout* lay = new QVBoxLayout(); + win->setLayout(lay); + + MapView* map = new MapView(win); + lay->addWidget(map); + map->setMinimumHeight(200); + map->setMinimumWidth(200); + + win->setMinimumWidth(400); + win->setMinimumHeight(400); + win->show(); // QQmlApplicationEngine engine; // engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); -// return app.exec(); + return app.exec(); } diff --git a/map/MapView.cpp b/map/MapView.cpp new file mode 100644 index 0000000..2352f97 --- /dev/null +++ b/map/MapView.cpp @@ -0,0 +1,82 @@ +#include "MapView.h" + + +MapView::MapView(QWidget* parent) : QGLWidget(parent) { + +}; + + void MapView::initializeGL() { + + qglClearColor(Qt::black); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glShadeModel(GL_SMOOTH); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + static GLfloat lightPosition[4] = { 0, 0, 10, 1.0 }; + glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); + + } + + void MapView::paintGL() { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -10.0); + glRotatef(20 / 16.0, 1.0, 0.0, 0.0); + glRotatef(30 / 16.0, 0.0, 1.0, 0.0); + glRotatef(60 / 16.0, 0.0, 0.0, 1.0); + draw(); + } + + void MapView::resizeGL(int width, int height) { + int side = qMin(width, height); + glViewport((width - side) / 2, (height - side) / 2, side, side); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + #ifdef QT_OPENGL_ES_1 + glOrthof(-2, +2, -2, +2, 1.0, 15.0); + #else + glOrtho(-2, +2, -2, +2, 1.0, 15.0); + #endif + glMatrixMode(GL_MODELVIEW); + } + + void MapView::draw() + { + qglColor(Qt::red); + glBegin(GL_QUADS); + glNormal3f(0,0,-1); + glVertex3f(-1,-1,0); + glVertex3f(-1,1,0); + glVertex3f(1,1,0); + glVertex3f(1,-1,0); + + glEnd(); + glBegin(GL_TRIANGLES); + glNormal3f(0,-1,0.707); + glVertex3f(-1,-1,0); + glVertex3f(1,-1,0); + glVertex3f(0,0,1.2); + glEnd(); + glBegin(GL_TRIANGLES); + glNormal3f(1,0, 0.707); + glVertex3f(1,-1,0); + glVertex3f(1,1,0); + glVertex3f(0,0,1.2); + glEnd(); + glBegin(GL_TRIANGLES); + glNormal3f(0,1,0.707); + glVertex3f(1,1,0); + glVertex3f(-1,1,0); + glVertex3f(0,0,1.2); + glEnd(); + glBegin(GL_TRIANGLES); + glNormal3f(-1,0,0.707); + glVertex3f(-1,1,0); + glVertex3f(-1,-1,0); + glVertex3f(0,0,1.2); + glEnd(); + } diff --git a/map/MapView.h b/map/MapView.h new file mode 100644 index 0000000..2790bb9 --- /dev/null +++ b/map/MapView.h @@ -0,0 +1,26 @@ +#ifndef MAPVIEW_H +#define MAPVIEW_H + +#include + +class MapView : public QGLWidget { + +public: + + MapView(QWidget* parent = 0); + +protected: + + void initializeGL(); + + void paintGL(); + + void resizeGL(int width, int height); + +private: + + void draw(); + +}; + +#endif // MAPVIEW_H diff --git a/yasmin.pro b/yasmin.pro index 8d0f007..e1ba40b 100644 --- a/yasmin.pro +++ b/yasmin.pro @@ -1,6 +1,6 @@ TEMPLATE = app -QT += qml +QT += qml opengl # android? #QT += androidextras sensors @@ -20,6 +20,7 @@ OTHER_FILES += \ SOURCES += \ main.cpp \ + map/MapView.cpp RESOURCES += qml.qrc @@ -48,7 +49,8 @@ HEADERS += \ sensors/WiFiSensor.h \ misc/Debug.h \ misc/fixc11.h \ - sensors/dummy/WiFiSensorDummy.h + sensors/dummy/WiFiSensorDummy.h \ + map/MapView.h DISTFILES += \ android-sources/src/MyActivity.java