VirtualBox

Changeset 79745 in vbox


Ignore:
Timestamp:
Jul 12, 2019 6:03:42 PM (5 years ago)
Author:
vboxsync
Message:

WDDM: opengl test application: texture2d.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/ogltest/oglrender.cpp

    r77646 r79745  
    4949
    5050
     51/*
     52 * Texture2D.
     53 */
     54class OGLRenderTexture2D : public OGLRender
     55{
     56    virtual HRESULT InitRender();
     57    virtual HRESULT DoRender();
     58    GLuint texName;
     59    static const int texWidth = 8;
     60    static const int texHeight = 8;
     61};
     62
     63HRESULT OGLRenderTexture2D::InitRender()
     64{
     65    static GLubyte texImage[texHeight][texWidth][4];
     66    for (int y = 0; y < texHeight; ++y)
     67    {
     68       for (int x = 0; x < texWidth; ++x)
     69       {
     70          GLubyte v = 255;
     71          if (   (texHeight/4 <= y && y < 3*texHeight/4)
     72              && (texWidth/4 <= x && x < 3*texWidth/4))
     73          {
     74              if (y < x)
     75              {
     76                  v = 0;
     77              }
     78          }
     79
     80          texImage[y][x][0] = v;
     81          texImage[y][x][1] = 0;
     82          texImage[y][x][2] = 0;
     83          texImage[y][x][3] = 255;
     84       }
     85    }
     86
     87    glClearColor(0.0, 0.0, 1.0, 1.0);
     88
     89    glGenTextures(1, &texName);
     90    glBindTexture(GL_TEXTURE_2D, texName);
     91
     92    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     93    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     94
     95    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     96    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, texImage);
     97
     98    glBindTexture(GL_TEXTURE_2D, 0);
     99
     100    return S_OK;
     101}
     102
     103HRESULT OGLRenderTexture2D::DoRender()
     104{
     105    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     106
     107    glEnable(GL_TEXTURE_2D);
     108
     109    glBindTexture(GL_TEXTURE_2D, texName);
     110
     111    glBegin(GL_TRIANGLES);
     112    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f);
     113    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, 0.0f);
     114    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, 0.0f);
     115
     116    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f);
     117    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, 0.0f);
     118    glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.0f, -1.0f, 0.0f);
     119    glEnd();
     120
     121    glBindTexture(GL_TEXTURE_2D, 0);
     122
     123    glDisable(GL_TEXTURE_2D);
     124
     125    glFlush();
     126
     127    return S_OK;
     128}
     129
     130
    51131OGLRender *CreateRender(int iRenderId)
    52132{
     
    55135    {
    56136        case 0: pRender = new OGLRenderTriangle(); break;
     137        case 1: pRender = new OGLRenderTexture2D(); break;
    57138        default:
    58139            break;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette