Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: How to use texture format of GL_RGB10_A2UI?

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2012
    Location
    -- Please Select --
    Posts
    8

    Question How to use texture format of GL_RGB10_A2UI?

    Hi,all:
    I want to write a demo, it's texture format is RGB10_A2UI.
    Code :
    typedef struct __TEXTURE_{
            GLubyte R;
            GLubyte G;
            GLubyte B;
            GLubyte A;
    }TexRGB10A2UI,*pTexRGB10A2UI;
    GLuint RGBA10_10_10_2_UI_CAST(const pTexRGB10A2UI texture)
    {
            return (GLuint)((GLuint)(texture->R & 0x03FFu) << 22u |\
                            (GLuint)(texture->G & 0x03FFu) << 12u |\
                            (GLuint)(texture->B & 0x03FFu) <<  2u |\
                            (GLuint)(texture->A & 0x0003u) <<  0u);
    }
     
     
    static void makeCheckImages(void)
    {
       int i, j, c;
     
     
       for (i = 0; i < checkImageHeight; i++) 
        {
          for (j = 0; j < checkImageWidth; j++) 
        {
             c = ((((i&0x8)==0)^((j&0x8)==0)))*255;
             checkImage[i][j][0] = (GLuint) c;
         checkImage[i][j][1] = (GLuint) c;
          checkImage[i][j][2] = (GLuint) c;
         checkImage[i][j][3] = (GLuint) 255;
        RGB10A2UIImage[i][j] = RGBA10_10_10_2_UI_CAST((pTexRGB10A2UI)checkImage[i][j]);
        }
         }    
    }
     
     
    static void init(void)
    {
       glClearColor (0.0, 0.0, 1.0, 0.0);
       glShadeModel(GL_FLAT);
       glEnable(GL_DEPTH_TEST);
     
     
       makeCheckImages();
       glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
     
     
       glGenTextures(1, texName);
       glBindTexture(GL_TEXTURE_2D, texName);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2UI, checkImageWidth,
                    checkImageHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT_10_10_10_2,
            RGB10A2UIImage);
     
     
       printf("%s\n",gluErrorString(glGetError()));
       glEnable(GL_TEXTURE_2D);
    }
    static void display(void)
    {
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       glBindTexture(GL_TEXTURE_2D, texName);
       glPushMatrix();
           glBegin(GL_QUADS);
           glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
           glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0);
           glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
           glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);
           glEnd();
        glPopMatrix();
       glFlush();
    }
    When I use
    Code :
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,checkImageHeight, 0, GL_RGBA,GL_UNSIGNED_INT,checkImage);
    instead of
    Code :
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2UI, checkImageWidth,checkImageHeight, 0, GL_RGBA_INTEGER,GL_UNSIGNED_INT_10_10_10_2,RGB10A2UIImage);
    , I got the right texture reslut, it shows a check image on the window.
    When I use
    Code :
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2UI, checkImageWidth,checkImageHeight, 0, GL_RGBA_INTEGER,GL_UNSIGNED_INT_10_10_10_2,RGB10A2UIImage);
    ,although the demo reports "no error", I've got a white texture on the window.
    so I am a little baffled why the demo can't give the right texture result.

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268
    Integer textures are useless in fixed function. You need to upgrade to GLSL to make use of them.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,135
    Please don't open a new thread when your old thread, concerning the exact same thing, is not even two weeks old: http://www.opengl.org/discussion_boa...r?goto=newpost

  4. #4
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,256
    Didn't you say you were using GL 3.3 in your other thread? You should be using shaders for ALL rendering.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2012
    Location
    -- Please Select --
    Posts
    8
    Quote Originally Posted by thokra View Post
    Please don't open a new thread when your old thread, concerning the exact same thing, is not even two weeks old: http://www.opengl.org/discussion_boa...r?goto=newpost
    ok,got it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •