Jump to content
  • Advertisement
Sign in to follow this  
Zarathustra

reading some float data into a texture (take 2)

This topic is 3907 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

so I loaded some data (32 float values) into a buffer, and then I supposedly wrote those values to a 1*32 texture. But when I try to use them in my shader, or when I read them out I get some random values. Can anyone tell me what I'm doing wrong here? Code: float *dataBuffer = loadData(); //Printing out the data, it looks fine like it should be for (int i = 0; i<32; i++){ cout<<dataBuffer<<endl; } GLenum dataTarget = GL_TEXTURE_RECTANGLE_NV; glGenTextures(1, &dataTexture); glBindTexture(dataTarget, dataTexture); glTexParameteri(dataTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(dataTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(dataTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(dataTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //Putting the data onto the texture. glTexImage2D(dataTarget, 0, GL_LUMINANCE16F_ARB, 32, 1, 0,GL_LUMINANCE, GL_FLOAT, dataBuffer); //Setting the texture for the shader. setdataParam(dataTarget); //And here I test if the stuff in the dataTarget actually i what I wanted to put in there.. And it isn't float* testBuffer = (float*) malloc(32*sizeof(float)); glGetTexImage(dataTarget,0,GL_LUMINANCE,GL_FLOAT,testBuffer); for (int i = 0; i<32; i++){ cout<<testBuffer<<endl; } This is the result from the first for loop 0.363 1.316 0.361 1.382 0.3561 1.403 0.3724 1.133 0.3887 0.9257 0.401 0.8074 0.4151 0.7359 0.4366 0.697 0.4804 0.5117 0.5391 0.268 0.2656 0.6669 0.5833 0.2269 0.3004 0.7964 0.5533 0.3682 0.007137 1.015 0.003445 1.355 This is the result from the second for loop 1.7208e-038 1.71738e-038 4.05571e-008 5.02811e-010 2.65136e-009 4.05571e-008 5.02755e-010 2.70009e-006 4.02542e-011 8.6276e-033 1.068e-005 2.01113e-009 4.17214e-008 4.05562e-008 8.8217e-033 1.07789e-008 5.02826e-010 2.5641e-009 4.15296e-005 8.67706e-033 2.62197e-009 5.0274e-010 6.6763e-007 4.00268e-011 2.71499e-006 2.5956e-006 5.02826e-010 6.7013e-010 4.00268e-011 1.05615e-005 6.489e-007 8.533e-033

Share this post


Link to post
Share on other sites
Advertisement
Could it have something to do with this (relating to glGetTexImage, from the opengl.org documentation):
Quote:

If the selected texture image does not contain four
components, the following mappings are applied. Single-
component textures are treated as RGBA buffers with red set
to the single-component value, green set to 0, blue set to
0, and alpha set to 1. Two-component textures are treated
as RGBA buffers with red set to the value of component zero,
alpha set to the value of component one, and green and blue
set to 0. Finally, three-component textures are treated as
RGBA buffers with red set to component zero, green set to
component one, blue set to component two, and alpha set to
1.

Just guessing as I don't know what effect using GL_LUMINANCE16F_ARB extension has on the result of glGetTexImage. I guess it probably in the specs though, did you check?

Share this post


Link to post
Share on other sites
Well I doubt that's the problem also because the core problem isn't with the the glTexGetImage. I get the same values in my cg shader.

Share this post


Link to post
Share on other sites
How are you checking the values you are getting in the cg shader?
If you render using those values it would look black I would guess, is that what you mean or are you using some sort of shader debugger? Can we see the shader code and the render code?

Share this post


Link to post
Share on other sites
I'm using stuff like this to see what kind of values they are.

float2 coords = (2,0);
float test = texRECT(datamap,coords);
float test1 = texRECT(datamap,float2(30,0));
if(test == test1 ){
color.x =1;
}
if(test == 0){
color.yz = (0,0);
}



the data enters the shader like this

uniform samplerRECT datamap

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!