Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualsaman_artorious

Posted 18 September 2013 - 06:34 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();
}

#1saman_artorious

Posted 18 September 2013 - 03:50 AM

I want to create & render textures using raw pixel PNG I receive. I want to make sure I set image raw data correctly to the texture. Besides, I want to know how to write the shader files and what to write inside the paint() event.

void GlWidget::pixmapCatchFromForm(QByteArray bytes)
{
    QImage image((const uchar* )bytes.constData(), glWidth, glHeight, QImage::Format_RGB32);
    //qDebug() << image.byteCount();


    unsigned int *pData;

    GLuint GLCAM_TEX;
    glEnable(GL_TEXTURE_2D);
    pData = new unsigned int [glWidth*glHeight*3];

    pData = (unsigned int*) bytes.constData();

    //Generate an ID for texture binding
    glGenTextures(1, &GLCAM_TEX); //Texture binding
    glBindTexture(GL_TEXTURE_2D, GLCAM_TEX);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, pData);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glDisable(GL_TEXTURE_2D);
}


PARTNERS