How would I display a texture/image in a cplusplus TOP? Couldn’t find anything in the example code. A little example would be very helpful.
thanks
A
How would I display a texture/image in a cplusplus TOP? Couldn’t find anything in the example code. A little example would be very helpful.
thanks
A
You can write to the output buffer directly from CPU memory using glDrawPixels(). It’s not the fastest way though, but good for a proof of concept.
For better performance, create a texture using glTexImage2D with a NULl pointer to allocate the memory, and upload it using glTexSubImage2D.
Then you can draw a quad with the texture on it to the framebuffer, or look into the GL_EXT_framebuffer_blit extension which allows for copying between textures and framebuffers.
Let me know which way you want to go and I can elaborate more on monday.
tried glDrawPixels(), and it kinda works. Dunno if I need any additional ::gl* commands? I just used
glDrawPixels(640, 480, GL_RGB, GL_UNSIGNED_BYTE, g_imageMD.RGB24Data());
The image is a bit smaller, i.e. doesn’t fill the whole TOP, but it works. Gotta play around some more
But some more info about the second solution would be great, as it seems that this is the approach the app I’m trying to port uses as well. Attached is the original source file i’m trying to port to touch Viewer.zip (2.9 KB)
I didn’t find much info about glTexSumbImage2D, if not too much work I’d love to see an example for this as well.
thx
Sorry, typo, glTexSubImage2D. I’ll write more later hopefully
This is uncompiled code but it should give you the idea.
// Initialization, only call this once
GLuint id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// Now every frame you call this
glBindTexture(GL_TEXTURE_2D, id);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
I’ll leave it to a google search to find how to apply a texture to a quad, but the CPP TOP automatically sets up a orthographic projection such that drawing a quad like this will cover up the entire view port exactly.
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2i(0, 0);
glTexCoord2f(1, 0);
glVertex2i(width, 0);
glTexCoord2f(1, 1);
glVertex2i(width, height);
glTexCoord2f(0, 1);
glVertex2i(0, height);
glEnd();
thx malcolm, I’ll try. What else besides setting up the “orthographic projection” does the cpp TOP already do in regards to OpenGl? Just wondering which parts of all the gl examples I can savely ignore (e.g. as I haven’t seen it in your example TOP code, do I need to call clear()…) . And what version of OpenGl is currently supported?
I can’t figure out why glTexSubImage2D won’t update properly inside of execute() for me. I always just get a grey image. If I use glTexImage2D to create a texture every execute it works fine. Any ideas?
You can control whether or not I do a glClear in the getGeneralInfo() function. I also setup and and FBO + renderbuffers based on the requested pixel formats and antialias level. I load the identity matrix into the modelview matrix. I also turn off the scissor test.
Other than that you shouldn’t assume anything (dont assume the depth test is on or off for example).
James, you are re-binding the texture every frame right? The fact that it’s grey is pretty strange also… Is the w/h you are passing correct.
I am rebinding every execute but I am using RGB format and a non power of two texture size. maybe that is the problem. I haven’t figured out how to manipulate my data array to be in RGBA format yet.
Non power of two texture size doesn’t matter on today’s GPU. If you try uploading an array filled with 255s as RGBA does it turn white?
If I fill the array with 0 or 255 its the same result. Its like glGenTextures is not generating a unique id because if I middle click on any top it goes black and if I interact with certain menus it goes black too.
You are only generating one ID and storing it for us on the next frame right?
I got it to work by adding
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
after the intitial glTex2d calls and calls to glEnable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D) to your example code. Unfortunately I don’t see any speed increase from generating the texture every frame. I guess the bottleneck is in the prime sense capturing.
hey james,
just a shot in the dark as I’m a total programming beginner, but in the primesense samples, they usually create a power of 2 texture and therefore store the 640480 depthmap in a 1024512 texture. Dunno if you also have to do this when running it in the cpp TOP, but maybe this is worth a try.
How bad is your performance hit? I went the opposite route and modified the OpenNI samples to write their output into a shared memory, hoping that this will have less impact on the TD performance than having the whole thing run inside TD.
Starting at the Geforce 6000 series, texture no longer need to be power-of-two resolutions.
I was seeing 12-20 ms spiky cook times but am realizing that it’s calculating the histogram on the cpu that’s eating up the most time. I also figured out the spikes would be less if I changed the openni context to WaitNoneUpdateAll.
If I just bind the pointer to the prime sense driver’s capture data its only 3 ms which is awesome but I can’t figure out how to bind it properly. The values are mm distance from the sensor so they are vary between 0 to a max of 10000. If I bind it as an unsigned short the values are between 0 and .3 or so.
Not too bog down the forum with C++ questions, but can someone explain how can I get the values to come in as the actual distance in mm through a glsubteximage binding?
The value range of an unsigned short is 0-65535, so a value of 10000 will result in a normalized [0-1] value of ~0.15. Is it possible you have values up to 20000?
Shaders always function in normalized color space when working with a fixed point pixel format. The key thing about fixed point formats is that they don’t give you more range (it’s always [0-1]), you just get more precision inside that range.
i.e
8-bit → 0-255 fixed point → [0, 1] when sampled in a shader
16-bit → 0-65535 fixed point → [0, 1] when sampled in a shader
If you want re-map your values just multiply them by 65535 in a GLSL TOP (and output to a floating point texture).
Thanks, it looks remapping the values in a glsl top put the values back into the right range. One other issue is that middle clicking on any TOP or manipulating certain ui elements makes the cplusplus operators output go black. maybe this is because I’m not writing alpha values?
That sounds like a mismatch between how you leave the OpenGL state and what I expect it to be. Can you send me your sample so I can look into the issue?