首页 文章

使用OpenGL数据在运行时创建纹理

提问于
浏览
1

我目前在数据库中有一些热图数据 . 我成功地使用相同的数据[使用一些顶点着色]在平面上创建绘制热图 . 例:

OpenGL的热图图像示例

Heat-Map Image example for openGL

名称:Capture.jpg浏览次数:0大小:8.5 KB ID:2667

现在,问题是我目前正在使用以下内容:

glBegin(GL_QUADS);
glColor4ub(point1.color.red(), point1.color.green(), point1.color.blue(), transparency);
glVertex3d(point1.xCood - 750, point1.yCood - 750, 0);
glColor4ub(point2.color.red(), point2.color.green(), point2.color.blue(), transparency);
glVertex3d(point2.xCood - 750, point2.yCood - 750, 0);
glColor4ub(point3.color.red(), point3.color.green(), point3.color.blue(), transparency);
glVertex3d(point3.xCood - 750, point3.yCood - 750, 0);
glColor4ub(point4.color.red(), point4.color.green(), point4.color.blue(), transparency);
glVertex3d(point4.xCood - 750, point4.yCood - 750, 0);
glEnd();

而这[至少在我的理论中]的作用是它在现有平面上创造了另一层 . 这会导致单击下面的平面上的代码变得无用 . 现在无法更改现有代码,因为我无权编辑它 . 我发现如果我在旧平面上绘制纹理(而不是为平面着色),代码仍然有效 . 示例(纹理图块只定义了所需的重复次数,在这种情况下值为1):

glBegin(GL_QUADS);
glTexCoord2d(0.0, textureTile);
glVertex3d(gridRect.left(), gridRect.top(), 0.0);
glTexCoord2d(0.0, 0.0);
glVertex3d(gridRect.left(), gridRect.bottom(), 0.0);
glTexCoord2d(textureTile, 0.0);
glVertex3d(gridRect.right(), gridRect.bottom(), 0.0);
glTexCoord2d(textureTile, textureTile);
glVertex3d(gridRect.right(), gridRect.top(), 0.0);
glEnd();

也就是说,我只是成功地从我制作的图像加载纹理 . 由于图像是在运行时计算和绘制的,我尝试从数据中创建图像以作为纹理加载 . 我使用Qt API功能来实现相同的功能 . 我无法重新创建相同的图像 . 我可能会建议一种从拥有的数据创建纹理图像的方法 .

谢谢

1 回答

  • 0

    对于迟到的回答感到抱歉(如果其他人想要答案的话) .

    我发现答案是使用QOpenGLFramebufferObject .

    最终代码类似于:

    glViewport(0, 0, VIEW_PORT_SIZE, VIEW_PORT_SIZE);
    QOpenGLFramebufferObject fbObject(VIEW_PORT_SIZE, VIEW_PORT_SIZE);
    fbObject.bind();
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    
    //Switch to Ortho Mode
    glMatrixMode(GL_PROJECTION);      // Select Projection
    glPushMatrix();                   // Push The Matrix
    glLoadIdentity();                 // Reset The Matrix
    glOrtho(left, right, bottom, top, -100, 100);  // Select Ortho Mode 
    glMatrixMode(GL_MODELVIEW);        // Select Modelview Matrix
    glPushMatrix();                    // Push The Matrix
    glLoadIdentity();                  // Reset The Matrix
    
                                       //Initialize variables
    SPointData point1, point2, point3, point4;
    //Paint on buffer
    //.................<some painting task>................
    //Switch to perspective mode
    glMatrixMode(GL_PROJECTION);      // Select Projection
    glPopMatrix();                    // Pop The Matrix
    glMatrixMode(GL_MODELVIEW);       // Select Modelview
    glPopMatrix();                    // Pop The Matrix
    
    fbObject.release();
    return fbObject.toImage();
    

相关问题