Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. [solved] I get some QGLWidget + OpenGLES 2.0 problems
QtWS25 Last Chance

[solved] I get some QGLWidget + OpenGLES 2.0 problems

Scheduled Pinned Locked Moved Game Development
4 Posts 2 Posters 3.9k 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.
  • T Offline
    T Offline
    Tratstil
    wrote on last edited by
    #1

    I try to use QGLWidget and OpenGLES 2.0 to write a game, my problem is the game always render the (0,0) coordinate in center of screen instead of top left corner. The code like this
    @QGraphicsScene scene;
    scene.setSceneRect(QRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT));
    GraphicsView viewer(&scene;);
    _qtgame._glwidget->resize(SCREEN_WIDTH,SCREEN_HEIGHT);
    _qtgame._glwidget->rect().topLeft();
    viewer.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    viewer.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    viewer.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    viewer.setFrameStyle(0);
    viewer.setViewport(_qtgame._glwidget);
    viewer.showFullScreen();@

    and
    @
    void GLWidget::resizeGL(int width, int height){
    glViewport(0, 0, DEVICE_WIDTH, DEVICE_HEIGHT);
    }@

    Did I forget some things?

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Just do this:

      @
      viewer.setViewport(new QGLWidget)
      @

      there is no need to sub-class QGLWidget and reimplement resizeGL().

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tratstil
        wrote on last edited by
        #3

        Thanks ZapB for help. But I need overwritten QGLWidget to make GLSL programe, I try no reimplement resizeGL() and rewrite my code as follow, but the (0,0) still stay at center of screen. Maybe I do something wrong here, but I don't know.

        @int main(int argc, char *argv[])
        {
        QApplication app(argc, argv);
        QApplication::setGraphicsSystem("opengl");
        QtGame _qtgame;
        _qtgame._viewer->showFullScreen();//now i handle the viewer inside _qtgame.

        QTimer *timer = new QTimer();
        timer->setInterval(500);
        QObject::connect(timer, SIGNAL(timeout()), &_qtgame, SLOT(ProcessSignal()));
        timer->start();
        return app.exec();
        

        }
        @

        QtGame show like this
        @
        //_viewer and _glwidget are public.
        QtGame::QtGame(){
        QGraphicsScene scene;
        scene.setSceneRect(QRect(0,0,k_SCREEN_WIDTH,k_SCREEN_HEIGHT));
        _viewer = new GraphicsView(&scene;);
        _viewer->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        _viewer->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        _viewer->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
        _viewer->setFrameStyle(0);
        _viewer->setViewport(new GLWidget());
        _glwidget = (GLWidget*)_viewer->viewport();
        }
        void QtGame::ProcessSignal(){
        _glwidget->updateGL();
        _glwidget->paintGL2();
        }
        @

        and the GLWidget: public QGLWidget

        @
        void GLWidget::initializeGL ()
        {
        //makeCurrent();
        ConfigOpenGL();// I create my GLSL programe here.
        glClearColor(1.0f, 0.972f, 0.862f, 1.0f);
        glViewport(0, 0, k_DEVICE_WIDTH, k_DEVICE_HEIGHT);
        }
        void GLWidget::paintGL2(){
        swapBuffers();
        makeCurrent();
        glViewport(0, 0, k_DEVICE_WIDTH, k_DEVICE_HEIGHT);
        glClearColor(0.989f, 0.989f, 0.872f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        Draw();//and draw the regtangle (0.0f, 0.0f , 0.9f, 0.9f) here
        }
        @
        And result
        !http://files.myopera.com/tratstil/files/20110728-181150.png(Screen shot)!

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tratstil
          wrote on last edited by
          #4

          After read the opengl_es2 exsample, i know that by default the (0,0) coordinate (in my case) is center of screen.

          and i do this to move the (0,0) coordinate to top-left corner. I multiply vertex with a (4x4) matrix.

          @
          _projectionMatrix.Identity();
          _projectionMatrix.Ortho(-(float)k_SCREEN_WIDTH,+0.0f,+0.0f,-(float)k_SCREEN_HEIGHT,-1.0f,+1.0f);
          @
          the code to Identity and Ortho can be found "here ":http://db-in.com/blog/2011/04/cameras-on-opengl-es-2-x/

          Thanks everybody!
          p/s : My english is very limited to representing my idear :D

          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