|
OpenGL: glGetTexImage |
Erin Maus
Member #7,537
July 2006
|
I'm wondering that, when using glGetTexImage, what format is the texture in? For example, say the texture is 1920 x 1080 and the pixel format is R8G8B8A8. Now, I figure I can't simple have a loop like this: for (int x = 0; x < TextureWidth; x++) { for (int y = 0; y < TextureHeight; y++) { bla.SetPixel(x, y, Color.FromArgb(glImage[x, y, 0], glImage[x, y, 1], glImage[x, y, 2])); } } I figure this because if I try that, then the image is...strange: {"name":"599389","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/e\/eef27875ec139019b9b9af4aee1199f8.png","w":480,"h":270,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/e\/eef27875ec139019b9b9af4aee1199f8"} When it should be more like this: {"name":"599390","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/b\/cb8379e5a153e21575901f031d752776.png","w":283,"h":162,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/b\/cb8379e5a153e21575901f031d752776"} Basically, how do I use the data from glGetTexImage into the standard (0, 0) is top left and (W, H) is bottom right? --- |
Thomas Harte
Member #33
April 2000
|
Not sure exactly what language you're using there for "glImage[x, y, 0]" to reference anything other than the very first byte, but with R8G8B8A8 (assuming you mean that you're specifying a format of GL_RGBA and a type of GL_UNSIGNED_BYTE) each pixel will be a byte of red, then a byte of green, then a byte of blue, then a byte of alpha. So, example code: 1void printPixelsOfMipMap(int mipMapLevel)
2{
3 GLint textureWidth, textureHeight;
4
5 glGetTexLevelParameter(GL_TEXTURE_2D, mipMapLevel, GL_TEXTURE_WIDTH, &textureWidth);
6 glGetTexLevelParameter(GL_TEXTURE_2D, mipMapLevel, GL_TEXTURE_HEIGHT, &textureHeight);
7
8 GLubyte *buffer = (GLubyte *)malloc(textureWidth*textureHeight*4);
9
10 glGetTexImage(GL_TEXTURE_2D, mipMapLevel, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
11
12 for(int y = 0; y < textureHeight; y++)
13 for(int x = 0; x < textureWidth; x++)
14 {
15 int startAddressOfPixel = ((y*textureWidth) + x)*4;
16
17 printf("pixel at %d %d has colour r=%d g=%d b=%d a=%d\n", x, y, buffer[startAddressOfPixel], buffer[startAddressOfPixel+1], buffer[startAddressOfPixel+2], startAddressOfPixel[startAddressOfPixel+3]);
18 }
19
20 free(buffer);
21}
[My site] [Tetrominoes] |
Erin Maus
Member #7,537
July 2006
|
Peculiar. I was using C#. With a few changes based on your code it works now. Thanks! --- |
|