Advertisement
Guest User

Untitled

a guest
Feb 21st, 2015
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.62 KB | None | 0 0
  1. MapView constructor:
  2. MapView::MapView(World* mWorld, QWidget* parent)
  3. : QOpenGLWidget(parent)
  4. , world(mWorld)
  5. , camera(new Camera(this))
  6. , ...
  7. {
  8.     setFocusPolicy(Qt::StrongFocus);
  9.     setMouseTracking(true);
  10.  
  11.     QSurfaceFormat format;
  12.     format.setDepthBufferSize(24);
  13.     format.setMajorVersion(4);
  14.     format.setMinorVersion(3);
  15.     format.setSamples(4);
  16.     format.setProfile(QSurfaceFormat::CoreProfile);
  17.     format.setOption(QSurfaceFormat::DebugContext);
  18.  
  19.     QSurfaceFormat::setDefaultFormat(format);
  20.  
  21.     surface = new QOffscreenSurface();
  22.     surface->setFormat(format);
  23.     surface->create();
  24.  
  25.     qDebug() << "surface validation:" << surface->isValid(); // return true
  26.  
  27.     // Initialize the camera position and orientation
  28.     camera->setPosition(QVector3D(250.0f, 10.0f, 250.0f));
  29.     camera->setViewCenter(QVector3D(250.0f, 10.0f, 249.0f));
  30.     camera->setUpVector(QVector3D(0.0f, 1.0f, 0.0f));
  31.  
  32.     // Assign camera to World
  33.     world->setCamera(camera);
  34.  
  35.     startTimer(16);
  36. }
  37.  
  38. MapView intializeGL:
  39. void MapView::initializeGL()
  40. {
  41.     QOpenGLContext* _context = world->getContext();
  42.  
  43.     qDebug() << _context->makeCurrent(surface); // return true
  44.     qDebug() << _context->isValid() << (QOpenGLContext::currentContext() == _context); // return true true
  45.  
  46.     initializeOpenGLFunctions(); // its still working? or have I call gl funcs from world?
  47.  
  48.     // Initialize World
  49.     world->initialize(/*this->context(),*/ size(), worldCoords);
  50.  
  51.     // Initialize camera shader
  52.     camera->initialize();
  53.  
  54.     // Enable depth testing
  55.     world->getGLFunctions()->glEnable(GL_DEPTH_TEST);
  56.     world->getGLFunctions()->glEnable(GL_CULL_FACE);
  57.  
  58.     world->getGLFunctions()->glDepthFunc(GL_LEQUAL); // just testing new depth func
  59.  
  60.     world->getGLFunctions()->glClearColor(0.65f, 0.77f, 1.0f, 1.0f);
  61. }
  62.  
  63. MapView paintGL: I think there is some problem
  64. void MapView::paintGL()
  65. {
  66.     world->getContext()->makeCurrent(surface);
  67.  
  68.     world->getGLFunctions()->glDrawBuffer(GL_FRONT);
  69.     world->getGLFunctions()->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  70.     world->draw(...);
  71.  
  72.     //world->getContext()->swapBuffers(surface); // not working even uncommented
  73. }
  74.  
  75. World initialize:
  76. void World::initialize(/*QOpenGLContext* context,*/ QSize fboSize, bool** mapCoords)
  77. {
  78.     GLfuncs = context->versionFunctions<QOpenGLFunctions_4_2_Core>();
  79.  
  80.     if(!GLfuncs)
  81.     {
  82.         qDebug() << QObject::tr("Requires OpenGL >= 4.2");
  83.  
  84.         qFatal(QObject::tr("Requires OpenGL >= 4.2").toLatin1().data());
  85.  
  86.         exit(1);
  87.     }
  88.  
  89.     GLfuncs->initializeOpenGLFunctions();
  90.     ...
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement