Sign in to follow this  
MShaw

Updating Texture Issue - TV like effect

Recommended Posts

Hi, I am trying to use one texture in my project that will be applied to a poly and then updated every second. The images that will be used as the textures are 640by480 pixels in size. I have use this usual commands to setup the texture (texture 1) in hardware memory: glBindTexture(GL_TEXTURE_2D, 1); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 1, 640, 480, 0, GL_LUMINANCE,GL_UNSIGNED_BYTE,textData); When I need to update the texture I use these commands: glBindTexture(GL_TEXTURE_2D, 1); glTexImage2D(GL_TEXTURE_2D, 0, 1, 640, 480, 0, GL_LUMINANCE,GL_UNSIGNED_BYTE,textData); The problem: During tests the texture never seems to update but only stays the same as the first uploaded texture image. Q1) Could the issue be that I am not using an a texture image of 2^m by 2^m pixels or can I leave them as 640 by 480?? Q2) any ideas on if I'm missing anything.... I'm use freeglut.h with glutMainLoopEvent(); rather then the usual glutMainLoop(); for processing events. Cheers and thanks MShaw

Share this post


Link to post
Share on other sites
So I think I found a solution to my problem which I now beleave is rooted in using glutMainLoopEvent();

I do not think glutMainLoopEvent(); was accessing my DrawGLScene() every time I called it so I have now just called glutMainLoopEvent(); to open the gl window and then used DrawGLScene() every time I update the texture and this seems to work.

If anyone knows why glutMainLoopEvent(); would not be calling my idle DrawGLScene(); function please let me know.

Cheers and thanks,

MShaw

Share this post


Link to post
Share on other sites
Hey thanks for the pointer.
Yes, this is good idea and should make things more efficient!!

I'm using freeglut as I am interested in using opengl but I do not want to have my code driven by the event loop. With freeglut they added a command to just run through one event loop and then returns to the calling function :) Almost all the commands clame to be almost 100% compatible with glut.h.

Cheers and thanks,

MShaw

Share this post


Link to post
Share on other sites
hi MShaw,
i was doing somthing similar like yours by having a cube to use images capture from the webcam as texture. therefore i need to the cube to auto update itself and display the current image as texture. i was going to try to use opencv to do so, but when i know u have done it using only glut libraries i thought u can give me a hand on this. may i have a look at your source files please? i really need it coz i have been stuck with this prob for so long. really hope u can help.thanks

regards,
derek

Share this post


Link to post
Share on other sites
I'd have to see your code, but there are 2 problems I can think of.

1) it is only redrawing when it gets a redraw message from the underlying windowing system. It should redraw when you resize if this is true. There is a way to change this behavior using glut. I don't have it on hand though.... Turning on double buffering I think shoudl do this automatically.

2) I'm sorry if you are insulted that I suggest this.. but you did pass the function pointer into glut to register your draw function callback right?


If it isn't one of those, I'm not sure I can help you.

Share this post


Link to post
Share on other sites
A1) Humm....will see if it redraws on window resize
A2) LOL, this is an important point to make and I understand fully. However I did give it the pointer for the callback.

Cheers,

Michael

Share this post


Link to post
Share on other sites
Hey,

This is the base code I used from NeHe.
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06

Only real change is that after I initially generate the texture I will again call this code to again replace them when needed:

glBindTexture(GL_TEXTURE_2D, 1);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 1, 640, 480, 0, GL_LUMINANCE,GL_UNSIGNED_BYTE,textData);

sequence. This is obviously not the most efficent way of doing this but it got the job done.


Because I didn't was the event loop I used freeglut.h rather then glut.h that way I can use glutMainLoopEvent(); rather then glutMainLoop();

As for openGL you probably have to use it regardless because you require webcam input - so your going to be stuck with it (or another library for webcam input) either way.

As a first step just try using the NeHe code to swap textures on a key press after that your good to go.

Share this post


Link to post
Share on other sites
Hi MShaw,

About the freeglut, i replaced glutMainLoop() with glutMainLoopEvent() but when i did that, the program runs and closes itself automatically, what seems to be the prob or did i miss out something?

Regards,
dunnodt

Share this post


Link to post
Share on other sites
Oh IC....

Thats sounds proper to me - you probably did not writing your own event loop and the program finishes the glutMainLoopEvent(); and exit your program.

Just set that back to glutMainLoop(); and you should see the window and its contents.

Do this
1) run the NeHe code AS IS
2) run the NeHe code with the modification of makeing it update the texture whenever needed.


I use this simple function where load_image_data() loads a bitmap:

void LoadAndUpdateGLTexture(char* file_name) {

load_image_data(rightIMG, file_name);

glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 1, 640, 480, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, rightIMG_Linear);
texCount++;
};

So every time you need to update the texture I just call LoadAndUpdateGLTexture("somefilename.bmp");

Cheers,

Michael

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this