pushing UV data into texture

pushing UV data into texture

I'm trying to render the data coming from the Perceptual Computing SDK into a mesh. It is probably important to know I am using OpenGL (and it might be helpful to know I'm using openFrameworks). Currently I do the following:

  1. grab the depth, UV, and color data into buffers
  2. run through the UV buffer and create a new color buffer which matches the depth buffer dimensions and puts the colors in the right place.
  3. push the depth and pre-processed, down-sampled color buffers to textures
  4. use a vertex shader to deform a plane based on the depth texture, and a fragment shader to apply the appropriate color.

What I would like to do is not pre-process and down-sample the color feed, so I'm imagining I would:

  1. push the raw depth, UV, and color data to textures
  2. use a vertex shader to deform a plane based on the depth texture, and a fragment shader to lookup in the UV texture and apply the appropriate color from the color texture.

What I am having trouble with is figuring out how to get the data from the UV buffer into a OpenGL texture. Since the SDK returns the UV data as a byte array, but the data needs to be interpreted as a 32-bit floating point number, I thought I might:

//initialize the texture
mTexUV.allocate(mDimsDepth[0], mDimsDepth[1], GL_RG, GL_RG, GL_DOUBLE);

//load the data from the SDK straight into the texture
mTexUV.loadData(cData.planes[2], mDimsDepth[0], mDimsDepth[1], GL_RG, GL_DOUBLE);


for those not familiar with openFramework's texture methods, the first uses the arguments (width, height, gl_internal_type, gl_incoming_format, gl_incoming_type), and the second uses the format (const void *data, width, height, gl_incoming_format, gl_incoming_type).

This doesn't seem to be working, and in fact when I even have the following line in my fragment shader without even using the value of uv_:

vec4 uv_ = texture2DRect(uvTex, referencePosition);

I get blackness (but no logged errors about the shader not compiling or crashing...) I know this is not a complete self-contained code snippet, but I'm hoping someone knows OpenGL well enough, or experience in getting this kind of data wrangled into a texture to help me out.


2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Well, turns out the simple solution is the right solution. I realized that right above my texture loading code, I was already reading the UV map into a float buffer for cpu processing, so all I had to do is cast the byte array to a float array and done!

mTexUV.loadData((float*)cData.planes[2], mDimsDepth[0], mDimsDepth[1], GL_RG);

I got confused by the float16, float32, and double and started thinking that doubles were 32-bit on my system. Anyway, that one minor detail is now figured out, on to the other 999.

Leave a Comment

Please sign in to add a comment. Not a member? Join today