5

glDrawPixels画像の結果を拡大縮小する必要があります。

QtQGLWidgetでglDrawPixelsを使用して640x480ピクセルの画像バッファーを描画しています。

PaintGLで次のことを実行しようとしました。

glScalef(windowWidth/640, windowHeight/480, 0);
glDrawPixels(640,480,GL_RGB,GL_UNSIGNED_BYTE,frame);

しかし、それは機能しません。

ウィジェットのサイズを次のようにOpenGLビューポートとglOrthoに設定しています。

void WdtRGB::paintGL() {

         glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

         // Setup the OpenGL viewpoint
         glMatrixMode(GL_PROJECTION);
         glLoadIdentity();
         glOrtho(0, windowWidth, windowHeight, 0, -1.0, 1.0);

    glDepthMask(0);
        //glRasterPos2i(0, 0);
        glScalef(windowWidth/640, windowHeight/480, 0);
        glDrawPixels(640,480,GL_RGB,GL_UNSIGNED_BYTE,frame);
    }

    //where windowWidth and windowHeight corresponds to the widget size.
    /the init functions are:

    void WdtRGB::initializeGL() {

        glClearColor ( 0.8, 0.8, 0.8, 0.0); // Background to a grey tone

        /* initialize viewing values  */
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        glOrtho(0, windowWidth, windowHeight, 0, -1.0, 1.0);

        glEnable (GL_DEPTH_TEST);

    }

    void WdtRGB::resizeGL(int w, int h) {
        float aspect=(float)w/(float)h;

        windowWidth = w;
        windowHeight = h;
        glViewport (0, 0, (GLsizei) w, (GLsizei) h);
        glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();

        if( w <= h )
                glOrtho ( -5.0, 5.0, -5.0/aspect, 5.0/aspect, -5.0, 5.0);
        else
                glOrtho (-5.0*aspect, 5.0*aspect, -5.0, 5.0, -5.0, 5.0);

        //printf("\nresize");
        emit changeSize ( );
    }
4

3 に答える 3

1

glDrawPixels画像の結果を拡大縮小する必要があります。

glDrawPixelsは直接フレームバッファに移動します。したがって、すべての入力ピクセルは1:1で出力にマッピングされます。glDrawPixelsをズームできる関数glPixelZoomがあります(ああ、なぜ私はあなたにこれを言っているのですか) 。

ただし、glDrawPixelsを使用しないことをお勧めします。

代わりにテクスチャクワッドを使用してください。glDrawPixelsは減価償却された関数であり、最新のOpenGL-3ではサポートされなくなりました。そして、それが非推奨にされなかったときでさえ、それはまだ非常に遅い機能です。テクスチャードクワッドは、あらゆる点で優れています。

于 2012-01-08T13:33:48.797 に答える