Browse Source

init; working gl scene

develop
Robin Thoni 8 years ago
commit
fe2fbe1039
9 changed files with 220 additions and 0 deletions
  1. 3
    0
      .gitignore
  2. 24
    0
      TheGame/TheGame.pro
  3. 11
    0
      TheGame/main.cpp
  4. 14
    0
      TheGame/mainwindow.cpp
  5. 22
    0
      TheGame/mainwindow.h
  6. 33
    0
      TheGame/mainwindow.ui
  7. 78
    0
      TheGame/renderwidget.cpp
  8. 31
    0
      TheGame/renderwidget.h
  9. 4
    0
      UGameEngine.pro

+ 3
- 0
.gitignore View File

@@ -0,0 +1,3 @@
1
+*.pro.user
2
+*.o
3
+ui_*

+ 24
- 0
TheGame/TheGame.pro View File

@@ -0,0 +1,24 @@
1
+#-------------------------------------------------
2
+#
3
+# Project created by QtCreator 2016-08-31T15:17:33
4
+#
5
+#-------------------------------------------------
6
+
7
+QT       += core gui opengl
8
+
9
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10
+
11
+TARGET = TheGame
12
+TEMPLATE = app
13
+
14
+
15
+SOURCES += main.cpp\
16
+        mainwindow.cpp \
17
+    renderwidget.cpp
18
+
19
+HEADERS  += mainwindow.h \
20
+    renderwidget.h
21
+
22
+FORMS    += mainwindow.ui
23
+
24
+LIBS += -lGLU

+ 11
- 0
TheGame/main.cpp View File

@@ -0,0 +1,11 @@
1
+#include "mainwindow.h"
2
+#include <QApplication>
3
+
4
+int main(int argc, char *argv[])
5
+{
6
+    QApplication a(argc, argv);
7
+    MainWindow w;
8
+    w.show();
9
+
10
+    return a.exec();
11
+}

+ 14
- 0
TheGame/mainwindow.cpp View File

@@ -0,0 +1,14 @@
1
+#include "mainwindow.h"
2
+#include "ui_mainwindow.h"
3
+
4
+MainWindow::MainWindow(QWidget *parent) :
5
+    QWidget(parent),
6
+    ui(new Ui::MainWindow)
7
+{
8
+    ui->setupUi(this);
9
+}
10
+
11
+MainWindow::~MainWindow()
12
+{
13
+    delete ui;
14
+}

+ 22
- 0
TheGame/mainwindow.h View File

@@ -0,0 +1,22 @@
1
+#ifndef MAINWINDOW_H
2
+#define MAINWINDOW_H
3
+
4
+#include <QWidget>
5
+
6
+namespace Ui {
7
+class MainWindow;
8
+}
9
+
10
+class MainWindow : public QWidget
11
+{
12
+    Q_OBJECT
13
+
14
+public:
15
+    explicit MainWindow(QWidget *parent = 0);
16
+    ~MainWindow();
17
+
18
+private:
19
+    Ui::MainWindow *ui;
20
+};
21
+
22
+#endif // MAINWINDOW_H

+ 33
- 0
TheGame/mainwindow.ui View File

@@ -0,0 +1,33 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<ui version="4.0">
3
+ <class>MainWindow</class>
4
+ <widget class="QWidget" name="MainWindow">
5
+  <property name="geometry">
6
+   <rect>
7
+    <x>0</x>
8
+    <y>0</y>
9
+    <width>400</width>
10
+    <height>300</height>
11
+   </rect>
12
+  </property>
13
+  <property name="windowTitle">
14
+   <string>MainWindow</string>
15
+  </property>
16
+  <layout class="QGridLayout" name="gridLayout">
17
+   <item row="0" column="0">
18
+    <widget class="RenderWidget" name="widget" native="true"/>
19
+   </item>
20
+  </layout>
21
+ </widget>
22
+ <layoutdefault spacing="6" margin="11"/>
23
+ <customwidgets>
24
+  <customwidget>
25
+   <class>RenderWidget</class>
26
+   <extends>QWidget</extends>
27
+   <header>renderwidget.h</header>
28
+   <container>1</container>
29
+  </customwidget>
30
+ </customwidgets>
31
+ <resources/>
32
+ <connections/>
33
+</ui>

+ 78
- 0
TheGame/renderwidget.cpp View File

@@ -0,0 +1,78 @@
1
+#include "renderwidget.h"
2
+#include <GL/glu.h>
3
+#include <QTimer>
4
+#include <math.h>
5
+
6
+RenderWidget::RenderWidget(QWidget *parent) :
7
+    QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
8
+  , angle(0)
9
+  , _fov(70)
10
+{
11
+}
12
+
13
+void RenderWidget::initializeGL()
14
+{
15
+    makeCurrent();
16
+    qglClearColor(Qt::gray);
17
+
18
+    glEnable(GL_DEPTH_TEST);
19
+    glEnable(GL_CULL_FACE);
20
+    glShadeModel(GL_SMOOTH);
21
+    glEnable(GL_MULTISAMPLE);
22
+
23
+    glMatrixMode(GL_PROJECTION);
24
+    gluPerspective(_fov, width()/height(), 0.1, 100.0);
25
+    glMatrixMode(GL_MODELVIEW);
26
+    animate();
27
+}
28
+
29
+void RenderWidget::paintGL()
30
+{
31
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
32
+    glLoadIdentity();
33
+
34
+    float rad = (float)angle / 180.0 * M_PI;
35
+    float radius = 5.0f;
36
+
37
+    gluLookAt(radius * cos(rad), 5.0f, radius * sin(rad),
38
+               0.0f, 0.0f, 0.0f,
39
+               0.0f, 1.0f, 0.0f);
40
+
41
+    drawAxes();
42
+}
43
+
44
+void RenderWidget::resizeGL(int width, int height)
45
+{
46
+    int side = qMin(width, height);
47
+    glViewport((width - side) / 2, (height - side) / 2, side, side);
48
+}
49
+
50
+void RenderWidget::animate()
51
+{
52
+    angle = (angle + 3) % 360;
53
+    update();
54
+    QTimer::singleShot(50, this, SLOT(animate()));
55
+}
56
+
57
+void RenderWidget::drawAxes()
58
+{
59
+    glLineWidth(2.5);
60
+
61
+    glColor3f(1.0, 0.0, 0.0);
62
+    glBegin(GL_LINES);
63
+    glVertex3f(0.0, 0.0, 0.0);
64
+    glVertex3f(1.0, 0.0, 0.0);
65
+    glEnd();
66
+
67
+    glColor3f(0.0, 1.0, 0.0);
68
+    glBegin(GL_LINES);
69
+    glVertex3f(0.0, 0.0, 0.0);
70
+    glVertex3f(0.0, 1.0, 0.0);
71
+    glEnd();
72
+
73
+    glColor3f(0.0, 0.0, 1.0);
74
+    glBegin(GL_LINES);
75
+    glVertex3f(0.0, 0.0, 0.0);
76
+    glVertex3f(0.0, 0.0, 1.0);
77
+    glEnd();
78
+}

+ 31
- 0
TheGame/renderwidget.h View File

@@ -0,0 +1,31 @@
1
+#ifndef RENDERWIDGET_H
2
+#define RENDERWIDGET_H
3
+
4
+#include <QGLWidget>
5
+
6
+class RenderWidget : public QGLWidget
7
+{
8
+    Q_OBJECT
9
+public:
10
+    explicit RenderWidget(QWidget *parent = 0);
11
+
12
+protected:
13
+    void initializeGL();
14
+    void paintGL();
15
+    void resizeGL(int width, int height);
16
+
17
+signals:
18
+
19
+public slots:
20
+    void animate();
21
+
22
+    void drawAxes();
23
+
24
+private:
25
+    int angle;
26
+
27
+    float _fov;
28
+
29
+};
30
+
31
+#endif // RENDERWIDGET_H

+ 4
- 0
UGameEngine.pro View File

@@ -0,0 +1,4 @@
1
+TEMPLATE = subdirs
2
+
3
+SUBDIRS += \
4
+    TheGame

Loading…
Cancel
Save