Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: C++  |  size: 1.90 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void Field::paintEvent(QPaintEvent *event)
  2. {
  3.     makeCurrent();
  4. //! [4]
  5.     glMatrixMode(GL_MODELVIEW);
  6.     glPushMatrix();
  7. //! [4]
  8.  
  9. //! [6]
  10.     qglClearColor(QColor(100,150,80));
  11.  
  12.     glShadeModel(GL_SMOOTH);
  13.     glEnable(GL_DEPTH_TEST);
  14.     glEnable(GL_CULL_FACE);
  15.     glEnable(GL_LIGHTING);
  16.     glEnable(GL_LIGHT5);
  17.     glEnable(GL_MULTISAMPLE);
  18.     static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
  19.     glLightfv(GL_LIGHT5, GL_POSITION, lightPosition);
  20.  
  21.     setupViewport(width(), height());
  22. //! [6]
  23.  
  24.  
  25.  
  26. //! [7]
  27.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  28.     glLoadIdentity();
  29.     glTranslatef(0.0, 0.0, -10.0);
  30. ////////
  31.  
  32.  
  33. //! [7]
  34.  
  35. //! [8]
  36.     glShadeModel(GL_FLAT);
  37.     glDisable(GL_CULL_FACE);
  38.     glDisable(GL_DEPTH_TEST);
  39.     glDisable(GL_LIGHTING);
  40.  
  41.     glMatrixMode(GL_MODELVIEW);
  42.     glPopMatrix();
  43. //! [8]
  44.  
  45.   //  Player->move(rect());
  46.    // Player->SetVelX(0);
  47.    // Player->SetVelY(0);
  48.     //    update();
  49. //! [10]
  50.     setupViewport(width(), height());
  51.     QPainter painter(this);
  52.  
  53.  
  54.     painter.setRenderHint(QPainter::Antialiasing);
  55.  
  56.     DrawBack(&painter);
  57.  
  58.     foreach(Block* block, Blocks)
  59.     {
  60.         //if (block->rect().intersects(event->rect()))
  61.             block->draw(&painter);
  62.     }
  63.  
  64.  
  65.     if (Player->rect().intersects(event->rect()))
  66.         Player->drawBubble(&painter);
  67.  
  68.    foreach (Bubble *bubble, AI) {
  69.         if (bubble->rect().intersects(event->rect()))
  70.             bubble->drawBubble(&painter);
  71.     }
  72.  
  73.  
  74.  
  75.   //drawInstructions(&painter);*/
  76.     foreach (holder* Bullet,Bullets)
  77.     {
  78.         if (Bullet->rect().intersects(event->rect()))
  79.             Bullet->draw(&painter);
  80.     }
  81.  
  82.     painter.end();
  83. }
  84. void Field::DrawBack(QPainter *painter)
  85. {
  86.     painter->save();
  87. //    painter->translate(pos.x(), pos.y());
  88.     painter->setBrush(brush);
  89.     painter->drawRect(0,0,1000,1000);
  90.     painter->restore();
  91. }