Jump to content

  • Log In with Google      Sign In   
  • Create Account


Dynamically loading and displaying greyscale textures


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Ender1618   Members   -  Reputation: 242

Like
0Likes
Like

Posted 05 April 2013 - 07:57 PM

I am trying to create a 1 channel texture, and update on the fly with a 1 channel image buffer. Im trying to render the texture at its native black and white.

 

I am creating the storage like so:

glTexStorage2D (
    GL_TEXTURE_2D,
    1,
    GL_R8,
    width,
    height
);

 

And filling it like so (where data is a single channel image buffer):

glTexSubImage2D (
    GL_TEXTURE_2D,
    0,
    0,
    0,
    width,
    height,
    GL_RED,
    GL_UNSIGNED_BYTE,
    data
);

When rendering I am getting a red version of my b/w image.

 

My intention was that the other channels would get duplicates of the red channel (other than alpha which would get 1,0).

 

My shader is generic for any type of texture, and I dont want to have a custom one for greyscale images, as i am also showing non-greyscale images.

 

I was under the impression that GL_LUMINACE would do what I intended, but I thought that was deprecated.

 

I would rather not use a BGRA texture and fill the B G R with the same value coming from my data. Im trying to fill this as fast as possible from a decoded b/w video, and at the same time minimize use of texture memory. I also get RGB video, that i am uploading as BGRA8, which works fine (swizzling and adding A before the upload), but I want to use the same shader.

 

I must be doing something silly, and misunderstanding something.

 

How would I accomplish this?

 

Thanx for any help.


Edited by Ender1618, 05 April 2013 - 08:56 PM.


Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 7413

Like
0Likes
Like

Posted 06 April 2013 - 06:54 AM

Set a swizzle mask: http://www.opengl.org/wiki/Texture#Swizzle_mask

 

In your case, this should so the trick:

 

GLint swizzleMask[] = {GL_RED, GL_RED, GL_RED, GL_ONE};
glTexParameteriv (GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);

 

That will only need to be set once, at texture creation time.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS