the aim of my program is to move a 50x50 pixel (pic_a) immage over a 500x500 pixel (pic_b) image by moving the mouse over the big image.
also, i have to copy a part of pic_b to produce pic_a and change to rgb color into a grayscale for pic_a. In the end the grayscaled pic_a
has to move over pic_b while exactly matching in content. i know it is hard to explain but i just hope that anybody can give me an idea how to
make a copy, save this and put it into the front. i am using c++ and opengl and think i need several buffers and switch them while moving???
thanks in advance,
patrick
Timmmm3d
December 26th, 2006, 08:20 PM
Well, I'm not sure exactly what you mean (perhaps you should explain what you are using this for), but this might be useful:
Presumably the pictures are shown as textured quads, if so I imagine you kept the texture data around for pic_a, in which case you can just copy the pixels into a new greyscale texture (glTexImage2D with GL_INTENSITY8). The intensities are just intensity=(red + green + blue)/3 for each pixel.
If you mean you want to get a bit of rendered output, then you can use glReadPixels, or I think glCopyTexImage2D.
Otherwise you'll have to be more specific about the problem.
patrickH80
December 27th, 2006, 10:41 AM
firstly, thanks for your reply :).
the only thing i have at the moment is my 3D scene. the issue with the grayscale is not the most important one at the moment. I more dont know how to get out a piece of the rendered scene, save both pictures maybe into different buffers? and and than create a kind of texture which i can use for later interactions.
glCopyTexImage2D sounds good but this would make the use of buffers unnecessary, doesnt it?
if i use textures, would i have to create two GL_TEXTURE_2D to copy the pixel from one into the other?
Timmmm3d
December 28th, 2006, 01:09 PM
So as I understand it, you want a texture created from part of the screen.
I'm pretty sure you can just use glCopyTexImage2D. That copies data from the current read buffer (the front screen buffer by default) into a texture.
macklin01
January 14th, 2007, 04:26 PM
I have done some work in creating interfaces between my EasyBMP BMP library (http://easybmp.sourceforge.net) and OpenGL. The write-up on this page (http://easybmp.sourceforge.net/OpenGL.html) is a bit outdated, so instead, please see the sample application that's included with the extensions download (http://easybmp.sourceforge.net/download.html#Extensions), as well as the included change log.
In that example, there's a code sample that loads an image as a texture (Richard Nixon), which it pastes to a rotating square. There's also a background image, which it modifies between each frame. (Seen as red, white and blue scrolling through the background--it's cheesy, but I was tired and it seemed funny at the time.) These demonstrate modifying textures that you map onto the screen.
There are also screenshot (hit 'S') and filming (hit 'F') functions to grab screen output and save to image files. This demonstrates getting the buffer through the simple EasyBMP interface.
Put these together, and you can grap, modify, and rewrite the buffer. Even if you don't use EasyBMP, I'd encourage you to download the source code and give it a look, as it will help give you an idea of how to use the OpenGL texture functions that were suggested above. In particular, none of these functions rely on GLUT (although the sample program does), making it a little bit more portable still.
Best of luck! -- Paul
patrickH80
January 17th, 2007, 07:23 PM
Firstly, thank u so much for ur help. I tried a lot of things now just to display my rendered scene but it always disappears after a second (My scene is interactive and can be rotated and every position of any mouse move is catched during runtime). After debugging for ages I found out that the displayed picture gets lost after calling
graphicscontext->swapBuffers()
Before that i am creating a texture with the size of the viewport and rasterize this into the viewport. Then it shows up (exactly like I like to have that) for a second and is gone. Here some code which hopefully explains my problem:
Firstly, thank u so much for ur help. I tried a lot of things now just to display my rendered scene but it always disappears after a second (My scene is interactive and can be rotated and every position of any mouse move is catched during runtime). After debugging for ages I found out that the displayed picture gets lost after calling
graphicscontext->swapBuffers()
Before that i am creating a texture with the size of the viewport and rasterize this into the viewport. Then it shows up (exactly like I like to have that) for a second and is gone. Here some code which hopefully explains my problem:
Hmm, that's a toughy. I suppose in part that after the buffers have been swapped, the display routine uses whatever polygons, etc., exist in the scene to draw the next frame. i.e., I think this is happening:
1) draw a frame in memory (buffer A). buffer B is displayed.
2) modify pixels in buffer A if user interaction is detected.
4) swap buffers to display buffer A.
5) buffer B is created by the regular routine. (wherever your polygons are, etc.)
6) swap buffers to show buffer B. Only buffer A was modified, so the changes are lost.
Does that sound right to you?
If that's the case, then one potential solution is to save the modified buffer to an array of pixels (e.g., a texture, or a BMP object) and overwrite the buffer with that just prior to your buffer swap. The model goes something like this:
1) draw a frame in memory (buffer in memory)
2) if user action detected:
a) modify pixels in the memory buffer
b) save a "screenshot" of the modified memory buffer
as a texture, etc.
2') if not (2):
overwrite memory buffer with the saved texture.
3) swap buffers to display memory buffer
In effect, you'd be using the last known good image as your current buffer. I'm not sure how well this would work, but it's an idea ... -- Paul
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.