Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with glBindTexture

Problem with glBindTexture

Scheduled Pinned Locked Moved Unsolved General and Desktop
qopenglqopengltexturebindopengl
2 Posts 1 Posters 1.1k 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.
  • F Offline
    F Offline
    FrankE
    wrote on last edited by
    #1

    I've loaded a image using:

    image = new QImage(QString("d:\\temp.jpg"));
    

    and also I generated a OpenGL texture with:

    GLFunctions::gl30()->glGenTextures(1, &texHandle);
    GLFunctions::gl30()->glBindTexture(GL_TEXTURE_2D, texHandle);
    GLFunctions::gl30()->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width(), image->height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, image->mirrored().bits());
    

    Where GLFunctions::gl30() is a function that returns QOpenGLFunctions_3_0 of the current context.
    binding it to a shader doesn't work or it is not sent to the shader

    GLFunctions::gl30()->glBindTexture(GL_TEXTURE_2D, texHandle);
    

    In the other hand using QOpenGLTexture, it works ok

    tex = new QOpenGLTexture(image->mirrored());
    tex->bind();
    

    So the shader workflow is correct.
    Also I know that the texHandlle is ok since I can make:

    //TRY TO READ THE TEXTURE TO CHECK IF IT IS VALID
    float *landArray=(float*) malloc (image->width()*image->height()*3*sizeof(float));
    GLFunctions::gl30()->glGetTexImage(GL_TEXTURE_2D,0,GL_RGB,GL_FLOAT,landArray );
    int off=(floor(0.5*image->height())*image->width())*3;
    off+=floor(0.5*image->width())*3;
    float res[3];
    res[0]=landArray[off];
    res[1]=landArray[off+1];
    res[2]=landArray[off+2];
    qDebug()<<"GL buffer contains color "<<res[0]<<res[1]<<res[2];
    

    And it dumps correct values.

    Any tips on this? Thank you in advance

    1 Reply Last reply
    0
    • F Offline
      F Offline
      FrankE
      wrote on last edited by
      #2

      That's becoming even more weird:

      GLFunctions::gl30()->glGenTextures(1, &texHandle);
      

      returns 2 in texHandle.

      but for using it in the shader it works for a value of 1 in the bindTexture

      GLFunctions::gl30()->glBindTexture(GL_TEXTURE_2D, texHandle-1); 
      

      This is driving me nuts.

      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