glTexImage2d: Even lines only or Odd lines only.

Started by
4 comments, last by V-man 15 years, 10 months ago
I have an image in CPU memory. I want to be able to create an OpenGL texture consisting of either the even lines of the source image, or the odd lines of the source image. I've already tried doubling the width and halving the height of the texture. This essentially produces a texture where the odd lines are partitioned on the left of the texture, and the even lines are partitioned on the right side of the texture. This method is unacceptable because doubling the texture width causes me to exceed maximum texture sizes. Any help would be great.
Advertisement
I think I managed to figure it out:

//even lines
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_ROW_LENGTH, width*2);

//odd lines
glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, width*2);

Are glPixelStorei/glPixelStoref states stored globally, or per-texture object?
They're global, since they don't actually modify the texture. They modify the way image data (not only textures) are transferred between CPU and GPU.
Quote:Original post by Yann L
They're global, since they don't actually modify the texture. They modify the way image data (not only textures) are transferred between CPU and GPU.


Ah, thanks for pointing that out.

I have come across a slight problem with my solution.

When I extract even lines there seems to be extra line at the bottom of the image that shouldn't be there. Could this have something to do with texture wrap modes or something?

edit:

I think I need to tell OpenGL to take texture samples from non-edge texels or something. Does that sound right? Also, I cant remember how this is done and if I recall correctly it is an extension.
I figured out the cause of the problem and found a solution, but I am not entirely happy with it.

As it turns out the problem I had was that I could extract even lines, but not odd lines. The problem had to do with the fact that glPixelStorei(GL_UNPACK_SKIP_ROWS, 1) wasn't doing what it was supposed to do.

The OpenGL documentation says that GL_UNPACK_SKIP_ROWS is equivalent to incrementing the texel pointer you supply to glTexImage2D by n rows. To get the behavior I wanted I incremented my texel pointer by one row instead of specifying GL_UNPACK_SKIP_ROWS.

I cant Imagine why the glPixelStorei parameters I passed didn't work entirely as I expected. Did I make some sort of error?
I don't know why it didn't work either but what you are doing causes the driver to do some extra work instead of just simply uploading to texture.
What effect are you trying to acheive?

Perhaps you can use glTexSubImage2D and update the rows.
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);

This topic is closed to new replies.

Advertisement