View Full Version : calling 2D in 3D

05-25-2000, 06:34 PM
I want to draw a 3D pic with a mirror/picture frame image in it, and then draw a 2D pic in the frame. The 2D pic is half written, using opengl. Can I actually do this, and how? Anyone?

05-25-2000, 08:33 PM
if i understood your question right, you wanna have something like a 2d-painting on a 3d-wall.. then you need texture-mapping..
you can draw some pic and simply ( http://www.opengl.org/discussion_boards/ubb/smile.gif ) put it on your object..

05-25-2000, 10:15 PM
Would that work, even though the 2D picture is an opengl (written in C) program, with animation, and not a bitmap image?

05-26-2000, 12:13 AM
well, there are several methods to "animate" a texture ( i think the simplest way is to change the texture every frame i.e. 10 different textures in a sec. for example )

But i dont know if this good solution to your problem, maybe you find another way to include your 2D-scene into 3D.

if you tell us how your 2D-program is made up, maybe someone can tell you..

if you want to move/rotate the 3D-parts with the 2d-image in it, i think a texture is the only way to do this

[This message has been edited by sebastian (edited 05-26-2000).]

05-26-2000, 06:01 AM
I have been thinking about how to do this myself. I've never tried to impliment it, but I figured the code would have to be something to the effect of:

if( update_painting ) {
glDrawBuffer( GL_AUX1 ); //so we cant see it

* sceen drawing instructions.

glReadBuffer( GL_AUX1 );
glCopyTexImage2D( texname, 0, GL_RGB, 0, 0, resolutionX, resolutionY, 0 );

glDrawBuffer( GL_BACK ); // rest of sceen gets hidden while drawing


I imagine this would kill a frame rate but I've never accually tried it. You'd prolly want some kind of test to make sure the user can see the painting before going through all
the trouble of rendering it.

humm... I hope that made some kind of sense.


05-26-2000, 10:58 PM
To clarify, only the 2D 'painting' is animated, not the 3D scene it's in.

Could I test Maarcke's code by writing the 2D pic to the point where it works but as yet has no animation, and then using that code? ..I think that would work as a test. Only, what is glCopyTexImage?

05-27-2000, 11:56 AM
Blue Book says:

glCopyTexImage2D - copy pixels into a 2D texture image

void glCopyTexImage2D(
GLenum target, // specifies the target texture
GLint level, // specifies level of mipmap detail reduction. Level 0 is the base image level
GLenum internalformat, // format of pixels
Glint x, y, // Window coords of the lower left corner of the region to be copied
GLsizei width, // Width of the texture image. Must be 0 or 2^n+2*border for some integer n.
GLsizei height, // Height of the texture image. Must be 0 or 2^m+2*border for some integer n.
GLint border // Specifies the width of the border. Must be 0 or 1.

That is, more or less, a quote from the refrence manual. They seem to imply that the width and height must be based on a power of two, but later in the description they imply that it's just the width and height of the region you want to grab.

This will grab pixels out of where ever the current GL_READ_BUFFER points (usually the current display), hence the switch to AUX1.