Jump to content
  • Advertisement
Sign in to follow this  
MShaw

Updating Texture Issue - TV like effect

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

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
Advertisement
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
I don't know too much about freeglut so I can't help with your new question, but if you only want to update a texture you should use glTexSubImage2D instead of glTexImage2D. Using glTexImage2D will recreate the entire texture object, whereas glTexSubImage2D will just redefine the texture's image data.

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
Hi Mshaw,

can you send me the codes for the example pls? i really appreciate your help.
thanks

Regards,
dunnodt

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!