Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Persian
  4. راهنمایی برای شروع کار با openGL

راهنمایی برای شروع کار با openGL

Scheduled Pinned Locked Moved Persian
3 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alizadeh91
    wrote on last edited by
    #1

    p{direction: rtl ; text-align: right}. سلام دوستان :)
    یک مرجع خوب برای شروع openGL تو Qt چی میتونه باشه؟ خود Qt چه کتابخونه هایی برای کارهای سه بعدی داره؟ در واقع یه کار خیلی ساده میخوام انجام بدم ولی نیاز به یک راهنمایی دارم که از کجا باید شروع کنم؟ :)
    ممنون

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hdeldar
      wrote on last edited by
      #2

      main.cpp
      @
      #include <QtGui/QApplication>
      #include <QtOpenGL/QGLWidget>
      #include "GLWidget.h"

      int main(int argc, char *argv[]) {

      QApplication app(argc, argv);
      
      GLWidget window;
      window.resize(800,600);
      window.show();
      
      return app.exec();
      

      }
      @

      GLWidget.h

      @
      #ifndef _GLWIDGET_H
      #define _GLWIDGET_H

      #include <QtOpenGL/QGLWidget>

      class GLWidget : public QGLWidget {

      Q_OBJECT // must include this if you use Qt signals/slots
      

      public:
      GLWidget(QWidget *parent = NULL);

      protected:
      void initializeGL();
      void resizeGL(int w, int h);
      void paintGL();
      void mousePressEvent(QMouseEvent *event);
      void mouseMoveEvent(QMouseEvent *event);
      void keyPressEvent(QKeyEvent *event);
      };

      #endif /* _GLWIDGET_H */
      @

      GLWidget.cpp

      @
      #include <QtGui/QMouseEvent>
      #include "GLWidget.h"

      GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {
      setMouseTracking(true);
      }

      void GLWidget::initializeGL() {
      glDisable(GL_TEXTURE_2D);
      glDisable(GL_DEPTH_TEST);
      glDisable(GL_COLOR_MATERIAL);
      glEnable(GL_BLEND);
      glEnable(GL_POLYGON_SMOOTH);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glClearColor(0, 0, 0, 0);
      }

      void GLWidget::resizeGL(int w, int h) {
      glViewport(0, 0, w, h);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluOrtho2D(0, w, 0, h); // set origin to bottom left corner
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      }

      void GLWidget::paintGL() {
      glClear(GL_COLOR_BUFFER_BIT);
      glColor3f(1,0,0);
      glBegin(GL_POLYGON);
      glVertex2f(0,0);
      glVertex2f(100,500);
      glVertex2f(500,100);
      glEnd();
      }

      void GLWidget::mousePressEvent(QMouseEvent *event) {

      }
      void GLWidget::mouseMoveEvent(QMouseEvent *event) {
      printf("%d, %d\n", event->x(), event->y());
      }

      void GLWidget::keyPressEvent(QKeyEvent* event) {
      switch(event->key()) {
      case Qt::Key_Escape:
      close();
      break;
      default:
      event->ignore();
      break;
      }
      }
      @

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hdeldar
        wrote on last edited by
        #3

        "http://doc.qt.digia.com/stable/opengl-hellogl.html":http://doc.qt.digia.com/stable/opengl-hellogl.html

        "www.cs.tufts.edu/comp/175/support/Tutorial.pdf":www.cs.tufts.edu/comp/175/support/Tutorial.pdfhttp://

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved