Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <QtCore>
  4. #include <QWidget>
  5. #include "qapplication.h"
  6. #include "GLWidget.hpp"
  7. #include "assimp.h"
  8. #include "aiScene.h"
  9.  
  10. // rename GLWidget to GLBaseWidget (cause its abstract)
  11. // TEMP
  12.  
  13. namespace paragon {
  14.  
  15.     class Foo : public GLWidget {
  16.  
  17.         const aiScene *scene;
  18.  
  19.         public:
  20.  
  21.             Foo (QWidget *parent = 0) : GLWidget (0, parent) {
  22.  
  23.                 scene = aiImportFile ("wall_04x04.3DS", 0);
  24.  
  25.                 if (scene) {
  26.  
  27.                     std::cout << scene->mNumMeshes << std::endl;
  28.  
  29.                 }
  30.  
  31.             }
  32.  
  33.             ~Foo () {
  34.  
  35.                 if (scene) aiReleaseImport (scene);
  36.                 scene = 0;
  37.             }
  38.  
  39.         protected:
  40.  
  41.             void initializeGL () {
  42.  
  43.                 glShadeModel(GL_SMOOTH);
  44.  
  45.                 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  46.                 glClearDepth(1.0f);
  47.  
  48.                 glEnable(GL_DEPTH_TEST);
  49.                 glDepthFunc(GL_LEQUAL);
  50.  
  51.                 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  52.  
  53.                 glDisable (GL_LIGHTING);
  54.  
  55.             }
  56.  
  57.             void resizeGL (int width, int height) {
  58.  
  59.                 height = height?height:1;
  60.  
  61.                 glViewport( 0, 0, (GLint)width, (GLint)height );
  62.  
  63.                 glMatrixMode(GL_PROJECTION);
  64.                 glLoadIdentity();
  65.                 gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
  66.  
  67.                 glMatrixMode(GL_MODELVIEW);
  68.                 glLoadIdentity();
  69.  
  70.             }
  71.  
  72.             void paintGL () {
  73.  
  74.                 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  75.                 glLoadIdentity ();
  76.                 glTranslatef (0, 0, -25);
  77.  
  78.                 for (unsigned int n = 0; n < scene->mNumMeshes; ++n) {
  79.  
  80.                     const struct aiMesh *mesh = scene->mMeshes [n];
  81.  
  82.                     for (unsigned int t = 0; t < mesh->mNumFaces; ++t) {
  83.  
  84.                         const struct aiFace *face = &mesh->mFaces[t];
  85.  
  86.                         glBegin (GL_POLYGON);
  87.  
  88.                             for (unsigned int i = 0; i < face->mNumIndices; ++i) {
  89.  
  90.                                 int index = face->mIndices[i];
  91.                                 glVertex3fv (&mesh->mVertices[index].x);
  92.  
  93.                             }
  94.  
  95.                         glEnd ();
  96.  
  97.                     }
  98.  
  99.                 }
  100.  
  101.             }
  102.  
  103.     };
  104. }
  105.  
  106. int main (int argc, char *argv[]) {
  107.  
  108.     QApplication app (argc, argv);
  109.  
  110.     paragon::Foo widget;
  111.     widget.setWindowTitle ("QT OpenGL Widget");
  112.     widget.resize (640, 480);
  113.     widget.show ();
  114.  
  115.     return app.exec();
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement