Jump to content

  • Log In with Google      Sign In   
  • Create Account


saman_artorious

Member Since 01 Jul 2013
Offline Last Active Jan 21 2014 09:34 AM
-----

Topics I've Started

rotate a bitmap image

30 November 2013 - 03:34 AM

I do not know how to rotate bitmap BGR image of size 800 * 600 * 3 by 90 degrees. If it was an image with a header, the solution would be:

    QImage srcImg(":/icon.png");
    QPoint center = srcImg.rect().center();
    QMatrix matrix;
    matrix.translate(center.x(), center.y());
    matrix.rotate(90);
    QImage dstImg = srcImge.transformed(matrix);
    QPixmap dstPix = QPixmap::fromImage(dstImg);

I read the whole image in a 800 * 600 * 3 image. Next, before I render it to the screen, I need to rotate it by 90 degrees.


get RGB values from raw image index

18 November 2013 - 06:13 AM

 

I want to get RGB values from a 24 bit BGR data. This data is from a raw image without a header.
I don't know how to convert the index of the buffer to its corresponding RGB values.
here is what I have done:

    window_width  = 800;

    window_height = 600;

    size = window_width * window_height;

    pixels = new float[size*3];

    for(int i = 0, j = 0; i < size*3, j < size; i += 3, j++)
    {
        pixels[i+2] = bytes[i];
    }

    updateGL();


void GlWidget::paintGL()
{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glDrawPixels(window_width,window_height,GL_RGB,GL_FLOAT,pixels);
}

what am i missing?

bind a bitmap raw data as texture to gl

12 November 2013 - 06:54 AM

hi,
I am receiving a bitmap of size 800 by 600 with RGB 24 bits. When I receive this bitmap from the other machine, I need to bind it to gl widget.
what crossed my mind is to do the following, however I am not quite sure if it is correct:

    initializeGLFunctions();

    GLuint vboId;

    glBindBuffer(GL_ARRAY_BUFFER, vboId);

    glBufferSubData(GL_ARRAY_BUFFER, 0, 800 * 600 * 3 * sizeof(int), &buffer[0]);

    glBindBuffer(GL_ARRAY_BUFFER, 0);

is this the right way to bind bitmap to gl?
I would also thank if you mention how to declare the vboId in the second line.

create texture from PNG raw pixel

18 September 2013 - 03:50 AM

I want to create a texture when I receive a byte array. This byte array is converted first to QImage and after I bind it to the texture. When I run the program, it shows it for a second and then it jumps out. Do you know why?

 

This is where I receive the byte array:

void GlWidget::pixmapCatchFromForm(QByteArray bytes)
{
    QImage image((const uchar* )bytes.constData(), glWidth, glHeight, QImage::Format_ARGB32);
    texture = bindTexture(image);
    qDebug() << texture; // returns 1
}

and here I render:

void GlWidget::paintGL()
{
    //! [5]
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    QMatrix4x4 mMatrix;
    QMatrix4x4 vMatrix;

    QMatrix4x4 cameraTransformation;
    cameraTransformation.rotate(alpha, 0, 1, 0);
    cameraTransformation.rotate(beta, 1, 0, 0);

    QVector3D cameraPosition = cameraTransformation * QVector3D(0, 0, distance);
    QVector3D cameraUpDirection = cameraTransformation * QVector3D(0, 1, 0);

    vMatrix.lookAt(cameraPosition, QVector3D(0, 0, 0), cameraUpDirection);

    //! [6]
    shaderProgram.bind();

    shaderProgram.setUniformValue("mvpMatrix", pMatrix * vMatrix * mMatrix);

    shaderProgram.setUniformValue("texture", 0);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, texture);
    glActiveTexture(0);

    shaderProgram.setAttributeArray("vertex", vertices.constData());
    shaderProgram.enableAttributeArray("vertex");

    shaderProgram.setAttributeArray("textureCoordinate", textureCoordinates.constData());
    shaderProgram.enableAttributeArray("textureCoordinate");

    glDrawArrays(GL_TRIANGLES, 0, vertices.size());

    shaderProgram.disableAttributeArray("vertex");

    shaderProgram.disableAttributeArray("textureCoordinate");

    shaderProgram.release();
}

how to write text below a point on the screen

26 August 2013 - 12:59 AM

My screen renders some pixels. I also want to render/write the x y coordinate of every point below it. Could anyone please tell me what function I shall use to accomplish this.

PARTNERS