Jump to content
  • Advertisement
Sign in to follow this  
fpsgamer

OpenGL glTexImage2d: Even lines only or Odd lines only.

This topic is 3654 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!