glDrawPixel - what is missing here?

  • Follow


glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
int rowSkip = offsetX;
int pixelSkip = offsetY;
glRasterPos2i(pixelSkip, rowSkip);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, pixelSkip);
glPixelStorei(GL_UNPACK_SKIP_ROWS, rowSkip);
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_iWidth); //this is width of the
frame buffer

glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);

values:
offsetX = 10
offsetY = 10
width = 630
height = 470

frame buffer is 640 x 480

It works fine if offsets are 0.

I am thinking there is a problem because my image is only 1 BYTE per
pixel and the frame buffer is GL_RGBA so maybe there is another
setting I am missing?

Thanks,

Judie

0
Reply Judie 4/30/2008 10:54:31 PM

Judie wrote:

> glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
> int rowSkip = offsetX;
> int pixelSkip = offsetY;
> glRasterPos2i(pixelSkip, rowSkip);
> glPixelStorei(GL_UNPACK_SKIP_PIXELS, pixelSkip);
> glPixelStorei(GL_UNPACK_SKIP_ROWS, rowSkip);
> glPixelStorei(GL_UNPACK_ROW_LENGTH, m_iWidth); //this is width
> of the frame buffer
> 
> glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE,
> image);
> 
> values:
> offsetX = 10
> offsetY = 10
> width = 630
> height = 470
> 
> frame buffer is 640 x 480
> 
> It works fine if offsets are 0.

Well, what is your intention?

Do you want to shift the whole picture withing the viewport?
Then you don't need to touch the UNPACK_SKIP_PIXELS /
UNPACK_SKIP_ROWS, just glRasterPos is sufficient.

> I am thinking there is a problem because my image is only 1
> BYTE per pixel and the frame buffer is GL_RGBA so maybe there
> is another setting I am missing?

No, there's no problem with that.

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: hexarith@jabber.org, ICQ: 134682867

0
Reply Wolfgang 4/30/2008 11:33:40 PM


On May 1, 12:54 am, Judie <judie.m.stan...@gmail.com> wrote:
>
> I am thinking there is a problem...

Nope.

> because my image is only 1 BYTE per pixel

That's what the "GL_LUMINANCE" in the "glDrawPixels"
is for, no need to touch glPixelStore

--
<\___/>
/ O O \
\_____/  FTB.     Remove my socks for email address.
0
Reply fungus 5/1/2008 11:44:42 AM

On Apr 30, 4:33=A0pm, Wolfgang Draxinger <wdraxin...@darkstargames.de>
wrote:
> Judie wrote:
> > glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
> > int rowSkip =3D offsetX;
> > int pixelSkip =3D offsetY;
> > glRasterPos2i(pixelSkip, rowSkip);
> > glPixelStorei(GL_UNPACK_SKIP_PIXELS, pixelSkip);
> > glPixelStorei(GL_UNPACK_SKIP_ROWS, rowSkip);
> > glPixelStorei(GL_UNPACK_ROW_LENGTH, m_iWidth); //this is width
> > of the frame buffer
>
> > glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE,
> > image);
>
> > values:
> > offsetX =3D 10
> > offsetY =3D 10
> > width =3D 630
> > height =3D 470
>
> > frame buffer is 640 x 480
>
> > It works fine if offsets are 0.
>
> Well, what is your intention?
>
> Do you want to shift the whole picture withing the viewport?
> Then you don't need to touch the UNPACK_SKIP_PIXELS /
> UNPACK_SKIP_ROWS, just glRasterPos is sufficient.
>
> > I am thinking there is a problem because my image is only 1
> > BYTE per pixel and the frame buffer is GL_RGBA so maybe there
> > is another setting I am missing?
>
> No, there's no problem with that.
>
> Wolfgang Draxinger
> --
> E-Mail address works, Jabber: hexar...@jabber.org, ICQ: 134682867- Hide qu=
oted text -
>
> - Show quoted text -

Well that was easy!

Thanks Wolfgang.

Judie
0
Reply Judie 5/1/2008 2:56:28 PM

On Apr 30, 4:33=A0pm, Wolfgang Draxinger <wdraxin...@darkstargames.de>
wrote:
> Judie wrote:
> > glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
> > int rowSkip =3D offsetX;
> > int pixelSkip =3D offsetY;
> > glRasterPos2i(pixelSkip, rowSkip);
> > glPixelStorei(GL_UNPACK_SKIP_PIXELS, pixelSkip);
> > glPixelStorei(GL_UNPACK_SKIP_ROWS, rowSkip);
> > glPixelStorei(GL_UNPACK_ROW_LENGTH, m_iWidth); //this is width
> > of the frame buffer
>
> > glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE,
> > image);
>
> > values:
> > offsetX =3D 10
> > offsetY =3D 10
> > width =3D 630
> > height =3D 470
>
> > frame buffer is 640 x 480
>
> > It works fine if offsets are 0.
>
> Well, what is your intention?
>
> Do you want to shift the whole picture withing the viewport?
> Then you don't need to touch the UNPACK_SKIP_PIXELS /
> UNPACK_SKIP_ROWS, just glRasterPos is sufficient.
>
> > I am thinking there is a problem because my image is only 1
> > BYTE per pixel and the frame buffer is GL_RGBA so maybe there
> > is another setting I am missing?
>
> No, there's no problem with that.
>
> Wolfgang Draxinger

Is there any way to draw a negative offset of the image? So if I
wanted it shifted 10 pixels to the left and 10 pixels down, is there a
way to specify that or is the only solution to clip the left and
bottom 10 pixel margins from the image first?

This is for an augmented reality application where we need the exact
centering of a camera image (per the camera "experts") in a 3D scene.

Judie
0
Reply Judie 5/1/2008 3:10:39 PM

On May 1, 4:44=A0am, fungus <openglMYSO...@artlum.com> wrote:
> On May 1, 12:54 am, Judie <judie.m.stan...@gmail.com> wrote:
>
>
>
> > I am thinking there is a problem...
>
> Nope.
>
> > because my image is only 1 BYTE per pixel
>
> That's what the "GL_LUMINANCE" in the "glDrawPixels"
> is for, no need to touch glPixelStore
>
> --
> <\___/>
> / O O \
> \_____/ =A0FTB. =A0 =A0 Remove my socks for email address.

OK - good to know.

Judie
0
Reply Judie 5/1/2008 3:11:48 PM

Judie wrote:

> Is there any way to draw a negative offset of the image? So if
> I wanted it shifted 10 pixels to the left and 10 pixels down,
> is there a way to specify that or is the only solution to clip
> the left and bottom 10 pixel margins from the image first?
> 
> This is for an augmented reality application where we need the
> exact centering of a camera image (per the camera "experts") in
> a 3D scene.

Use textures then. In your usage scenario you might make good use
of the GL_ARB_texture_rectangle extension.

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: hexarith@jabber.org, ICQ: 134682867

0
Reply Wolfgang 5/1/2008 3:26:08 PM

On May 1, 5:10 pm, Judie <judie.m.stan...@gmail.com> wrote:
>
> Is there any way to draw a negative offset of the image? So if I
> wanted it shifted 10 pixels to the left and 10 pixels down, is there a
> way to specify that or is the only solution to clip the left and
> bottom 10 pixel margins from the image first?
>

The position of glRasterPos is clipped to the current
viewport, if it fails, the image won't appear. This is
logical if you know how OpenGL works but surprises
most newbies.

The solution is to make your viewport bigger than the
visible window, eg:

glViewport(-100,-100,windowWidth+100, windowHeight+100)

(or whatever values are big enough...)
0
Reply fungus 5/1/2008 4:17:12 PM

On May 1, 8:26=A0am, Wolfgang Draxinger <wdraxin...@darkstargames.de>
wrote:
> Judie wrote:
> > Is there any way to draw a negative offset of the image? So if
> > I wanted it shifted 10 pixels to the left and 10 pixels down,
> > is there a way to specify that or is the only solution to clip
> > the left and bottom 10 pixel margins from the image first?
>
> > This is for an augmented reality application where we need the
> > exact centering of a camera image (per the camera "experts") in
> > a 3D scene.
>
> Use textures then. In your usage scenario you might make good use
> of the GL_ARB_texture_rectangle extension.
>

I don't know if I could get exact pixel alignment with a texture by
changing the texture coordinates which is what is so crucial to the
"camera" people. I will look into the GL_ARB_texture_rectangle
extension to see if it helps. Although I am currently able to
demonstrate the usage on a PC with an NVidia graphics card, the
released version will run on an embedded system that has Intel
Integrated Graphics. Unfortunately, they still do not support
GL_ARB_texture_non_power_of_two and our camera image is 640 x 480.

Judie

0
Reply Judie 5/1/2008 8:03:28 PM

On May 1, 9:17=A0am, fungus <openglMYSO...@artlum.com> wrote:
> On May 1, 5:10 pm, Judie <judie.m.stan...@gmail.com> wrote:
>
>
>
> > Is there any way to draw a negative offset of the image? So if I
> > wanted it shifted 10 pixels to the left and 10 pixels down, is there a
> > way to specify that or is the only solution to clip the left and
> > bottom 10 pixel margins from the image first?
>
> The position of glRasterPos is clipped to the current
> viewport, if it fails, the image won't appear. This is
> logical if you know how OpenGL works but surprises
> most newbies.
>
> The solution is to make your viewport bigger than the
> visible window, eg:
>
> glViewport(-100,-100,windowWidth+100, windowHeight+100)
>
> (or whatever values are big enough...)

I can't do that because that would affect the size of the rendered
objects as they are projected to the screen which would add a whole
nother layer of difficulty which at some point we will conquer, just
not initially.
0
Reply Judie 5/1/2008 8:05:22 PM

Judie wrote:

> I don't know if I could get exact pixel alignment with a
> texture by changing the texture coordinates which is what is so
> crucial to the "camera" people.

Of course pixel exact placement is possible. You've just to know
the way, how OpenGL maps texture coordinates to pixels. Some
time ago I wrote a small example application, that renders a
full screen quad with the (well known) X11 default background
pattern. This pattern has the nice property, that even the
smallest misalignement is clearly visible. So this pattern is
the perfect example of how to pixel exactly place a texture.

> GL_ARB_texture_non_power_of_two and our camera image is 640 x
> 480.

Then use a 1024x512 texture and leave some blank margin.
glTexSubImage2D is your friend.

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: hexarith@jabber.org, ICQ: 134682867

0
Reply Wolfgang 5/1/2008 9:54:38 PM

On May 1, 2:54=A0pm, Wolfgang Draxinger <wdraxin...@darkstargames.de>
wrote:
> Judie wrote:
> > I don't know if I could get exact pixel alignment with a
> > texture by changing the texture coordinates which is what is so
> > crucial to the "camera" people.
>
> Of course pixel exact placement is possible. You've just to know
> the way, how OpenGL maps texture coordinates to pixels. Some
> time ago I wrote a small example application, that renders a
> full screen quad with the (well known) X11 default background
> pattern. This pattern has the nice property, that even the
> smallest misalignement is clearly visible. So this pattern is
> the perfect example of how to pixel exactly place a texture.
>
> > GL_ARB_texture_non_power_of_two and our camera image is 640 x
> > 480.
>
> Then use a 1024x512 texture and leave some blank margin.
> glTexSubImage2D is your friend.
>
> Wolfgang Draxinger
> --
> E-Mail address works, Jabber: hexar...@jabber.org, ICQ: 134682867

Well, I just looked up glTexSubImage2D and it sounds perfect! Now can
you provide your example so I can get perfect texture coordinate i.e.
pixel mapping?

Lets say my quad is 640 x 480 and the texture is 640 x 480 but I make
it 1024 x 512 initially.

After processing the image may be 630 x 470 and require an offset of
10 pixels in the x and y directions. (so if it were glDrawPixels I
would set the glRasterPos2i(10, 10);

In this case I give my quad (drawn as 2D in ortho) the same
coordinates, (0,0), (630, 0), (630, 470), (0,470). But now figuring
out the texture coordinates is trixy.

minXTexCoord =3D 0.0;
minYTexCoord =3D 0.0;
maxXTexCoord =3D 630.0/1024.0;
maxYTexCoord =3D 470.0/512.0;

Is this correct?

Even if it is correct, how do I guarantee that it gets mapped as well
as if I were to use glDrawPixels?

Judie
0
Reply Judie 5/1/2008 11:08:34 PM

Judie wrote:

> Is there any way to draw a negative offset of the image? So if I
> wanted it shifted 10 pixels to the left and 10 pixels down, is there a
> way to specify that or is the only solution to clip the left and
> bottom 10 pixel margins from the image first?

Use glRasterPos to position the raster position somewhere inside the 
viewport, then use glBitmap with a 0x0 bitmap to move the raster 
position anywhere -- including outside the window. Now the glDrawPixels 
image will be placed where you want it. Use glScissor to clip the raster 
image as desired.

However, the texture image is probably a better plan.

--
Andy V
0
Reply Andy 5/1/2008 11:21:55 PM

Judie wrote:

> Well, I just looked up glTexSubImage2D and it sounds perfect!
> Now can you provide your example so I can get perfect texture
> coordinate i.e. pixel mapping?
> 
> Lets say my quad is 640 x 480 and the texture is 640 x 480 but
> I make it 1024 x 512 initially.
> 
> After processing the image may be 630 x 470 and require an
> offset of 10 pixels in the x and y directions. (so if it were
> glDrawPixels I would set the glRasterPos2i(10, 10);
> 
> In this case I give my quad (drawn as 2D in ortho) the same
> coordinates, (0,0), (630, 0), (630, 470), (0,470). But now
> figuring out the texture coordinates is trixy.
> 
> minXTexCoord = 0.0;
> minYTexCoord = 0.0;
> maxXTexCoord = 630.0/1024.0;
> maxYTexCoord = 470.0/512.0;
> 
> Is this correct?

Almost. You placed a 640x480 image within a 1024x512 texture. In
the most simple case just in the left lower corner, so you have
some 384 pixel margin at the right and a 32 pixel margin to the
top.

GLint image_width = 640;
GLint image_height = 480;
GLint texture_width = 1024;
GLint texture_height = 512;

GLint margin_left = 0;
GLint margin_bottom = 0;
GLint margin_right = texture_width - image_width;
GLint margin_top = texture_height - image_height;

Now you want to place the image using pixel coordinates within
the viewport, so it makes sense to map the modelview XY plane to
the viewport plane _and_ let modelview units be pixels.

glViewport(viewport_offset_x,
        viewport_offset_y,
        viewport_width,
        viewport_height);
glScissor(viewport_offset_x,
        viewport_offset_y,
        viewport_width,
        viewport_height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, viewport_width,
        0, viewport_height,
        -1, 1);

We want to display the image relative to the viewport offset, so
you got in fact two possible offsets: One for the viewport, and
one for the image displayed within the viewport.

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(image_offset_x, image_offset_y, 0);

Now we get to the trickiest part: OpenGL defines, that texture
coordinates address by implying, that the whole texture is fit
within the range [0, 1]^2, with the _borders_ being at
exactly{0, 1}^2. So using texture coordinates of {0, 1} will
give you _not_ pixel perfect alignment, but a slightly offset,
hitting the border. That OpenGL uses texture coordinates this
way is due to the possibility to supply extra borders to a
texture.

So to hit exactly a texel, we must apply some linear distortion
to the texture coordinates.

The following function will return the texture coordinate for a
certain pixel in one dimension, given the parameters of the
texture, assuming that there is _no_ border defined:

GLfloat TexCoordByTexel(GLuint texture_dim, GLuint texel_pos)
{
        return 0.5/texture_dim + texel_pos /
                ( (texture_dim-1) + 1./(texture_dim-1) );
}

Now let's draw the image. And be aware, that we start counting at
0, so if the images is image_width wide, the rightmost
pixel/texel will be at image_width-1 !

glBegin(GL_QUADS);
glTexCoord2f(   TexCoordByTexel(texture_width, 0),
                TexCoordByTexel(texture_height, 0) );
glVertex2f(0, 0);

glTexCoord2f(   TexCoordByTexel(texture_width, image_width-1),
                TexCoordByTexel(texture_height, 0) );
glVertex2f(image_width-1, 0);

glTexCoord2f(   TexCoordByTexel(texture_width, image_width-1),
                TexCoordByTexel(texture_height, image_height-1) );
glVertex2f(image_width-1, image_height-1);

glTexCoord2f(   TexCoordByTexel(texture_width, 0),
                TexCoordByTexel(texture_height, image_height-1) );
glVertex2f(0, image_height-1);
glEnd();

That's it. *phew* :-)

I know it looks a bit confusing if you look at it for the first
time, but it get's quite easy one you've got the hang of it.

Instead of using that function TexCoodByTexel you could also have
manipulated the GL_TEXTURE matrix,

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef( 0.5/texture_width, 0.5/texture_height );
glScalef( 1./((texture_width-1) + 1./(texture_width-1)),
         1./((texture_height-1) + 1./(texture_height-1)),
        1 );
// Hope that's correct, wrote this ex tempora...

and simply used

glTexCoord2f(0,0);
glTexCoord2f(image_width-1,0);
glTexCoord2f(image_width-1,image_height-1);
glTexCoord2f(0,image_height-1);

However you should use vertex arrays for all this anyway, so
there's no real performance gain, if using the later method,
which is Copy'n'Paste error prone (someone might just copy the
function calls to draw the image, but not the texture matrix
setup).

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: hexarith@jabber.org, ICQ: 134682867

0
Reply Wolfgang 5/2/2008 9:44:52 AM

On May 1, 10:05 pm, Judie <judie.m.stan...@gmail.com> wrote:
>
> I can't do that because that would affect the size of the rendered
> objects as they are projected to the screen which would add a whole
> nother layer of difficulty which at some point we will conquer, just
> not initially.

a) No it wouldn't one pixel is still "one" in that viewport.

b) You can reset the viewport back to normal at any time
- eg. right after the glDrawPixels().

Ok, another trick to get around the clipping....use glBitmap
to adjust the rasterpos (see "notes" in the page for glBitmap).

glRasterPos2i(0,0);       // Cannot be clipped
glBitmap(0,0,0,0,x,y,0); // Set raster position to (x,y)
glDrawPixels();

--
<\___/>
/ O O \
\_____/  FTB.     Remove my socks for email address.
0
Reply fungus 5/2/2008 11:35:27 AM

On May 2, 1:21 am, Andy V <nob...@nowhere.net> wrote:
>
> However, the texture image is probably a better plan.
>

In the long term, yes, but it's tricky to align the pixels
properly.

Textures also garantee best performance.


--
<\___/>
/ O O \
\_____/  FTB.     Remove my socks for email address.
0
Reply fungus 5/2/2008 11:37:37 AM

On May 2, 2:44=A0am, Wolfgang Draxinger <wdraxin...@darkstargames.de>
wrote:
> Judie wrote:
> > Well, I just looked up glTexSubImage2D and it sounds perfect!
> > Now can you provide your example so I can get perfect texture
> > coordinate i.e. pixel mapping?
>
> > Lets say my quad is 640 x 480 and the texture is 640 x 480 but
> > I make it 1024 x 512 initially.
>
> > After processing the image may be 630 x 470 and require an
> > offset of 10 pixels in the x and y directions. (so if it were
> > glDrawPixels I would set the glRasterPos2i(10, 10);
>
> > In this case I give my quad (drawn as 2D in ortho) the same
> > coordinates, (0,0), (630, 0), (630, 470), (0,470). But now
> > figuring out the texture coordinates is trixy.
>
> > minXTexCoord =3D 0.0;
> > minYTexCoord =3D 0.0;
> > maxXTexCoord =3D 630.0/1024.0;
> > maxYTexCoord =3D 470.0/512.0;
>
> > Is this correct?
>
> Almost. You placed a 640x480 image within a 1024x512 texture. In
> the most simple case just in the left lower corner, so you have
> some 384 pixel margin at the right and a 32 pixel margin to the
> top.
>
> GLint image_width =3D 640;
> GLint image_height =3D 480;
> GLint texture_width =3D 1024;
> GLint texture_height =3D 512;
>
> GLint margin_left =3D 0;
> GLint margin_bottom =3D 0;
> GLint margin_right =3D texture_width - image_width;
> GLint margin_top =3D texture_height - image_height;
>
> Now you want to place the image using pixel coordinates within
> the viewport, so it makes sense to map the modelview XY plane to
> the viewport plane _and_ let modelview units be pixels.
>
> glViewport(viewport_offset_x,
> =A0 =A0 =A0 =A0 viewport_offset_y,
> =A0 =A0 =A0 =A0 viewport_width,
> =A0 =A0 =A0 =A0 viewport_height);
> glScissor(viewport_offset_x,
> =A0 =A0 =A0 =A0 viewport_offset_y,
> =A0 =A0 =A0 =A0 viewport_width,
> =A0 =A0 =A0 =A0 viewport_height);
> glMatrixMode(GL_PROJECTION);
> glLoadIdentity();
> glOrtho(0, viewport_width,
> =A0 =A0 =A0 =A0 0, viewport_height,
> =A0 =A0 =A0 =A0 -1, 1);
>
> We want to display the image relative to the viewport offset, so
> you got in fact two possible offsets: One for the viewport, and
> one for the image displayed within the viewport.
>
> glMatrixMode(GL_MODELVIEW);
> glLoadIdentity();
> glTranslatef(image_offset_x, image_offset_y, 0);
>
> Now we get to the trickiest part: OpenGL defines, that texture
> coordinates address by implying, that the whole texture is fit
> within the range [0, 1]^2, with the _borders_ being at
> exactly{0, 1}^2. So using texture coordinates of {0, 1} will
> give you _not_ pixel perfect alignment, but a slightly offset,
> hitting the border. That OpenGL uses texture coordinates this
> way is due to the possibility to supply extra borders to a
> texture.
>
> So to hit exactly a texel, we must apply some linear distortion
> to the texture coordinates.
>
> The following function will return the texture coordinate for a
> certain pixel in one dimension, given the parameters of the
> texture, assuming that there is _no_ border defined:
>
> GLfloat TexCoordByTexel(GLuint texture_dim, GLuint texel_pos)
> {
> =A0 =A0 =A0 =A0 return 0.5/texture_dim + texel_pos /
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ( (texture_dim-1) + 1./(texture_dim-1) );
>
> }
>
> Now let's draw the image. And be aware, that we start counting at
> 0, so if the images is image_width wide, the rightmost
> pixel/texel will be at image_width-1 !
>
> glBegin(GL_QUADS);
> glTexCoord2f( =A0 TexCoordByTexel(texture_width, 0),
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TexCoordByTexel(texture_height, 0) );
> glVertex2f(0, 0);
>
> glTexCoord2f( =A0 TexCoordByTexel(texture_width, image_width-1),
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TexCoordByTexel(texture_height, 0) );
> glVertex2f(image_width-1, 0);
>
> glTexCoord2f( =A0 TexCoordByTexel(texture_width, image_width-1),
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TexCoordByTexel(texture_height, image_heig=
ht-1) );
> glVertex2f(image_width-1, image_height-1);
>
> glTexCoord2f( =A0 TexCoordByTexel(texture_width, 0),
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TexCoordByTexel(texture_height, image_heig=
ht-1) );
> glVertex2f(0, image_height-1);
> glEnd();
>
> That's it. *phew* :-)
>
> I know it looks a bit confusing if you look at it for the first
> time, but it get's quite easy one you've got the hang of it.
>
> Instead of using that function TexCoodByTexel you could also have
> manipulated the GL_TEXTURE matrix,
>
> glMatrixMode(GL_TEXTURE);
> glLoadIdentity();
> glTranslatef( 0.5/texture_width, 0.5/texture_height );
> glScalef( 1./((texture_width-1) + 1./(texture_width-1)),
> =A0 =A0 =A0 =A0 =A01./((texture_height-1) + 1./(texture_height-1)),
> =A0 =A0 =A0 =A0 1 );
> // Hope that's correct, wrote this ex tempora...
>
> and simply used
>
> glTexCoord2f(0,0);
> glTexCoord2f(image_width-1,0);
> glTexCoord2f(image_width-1,image_height-1);
> glTexCoord2f(0,image_height-1);
>
> However you should use vertex arrays for all this anyway, so
> there's no real performance gain, if using the later method,
> which is Copy'n'Paste error prone (someone might just copy the
> function calls to draw the image, but not the texture matrix
> setup).
>
> Wolfgang Draxinger
> --
> E-Mail address works, Jabber: hexar...@jabber.org, ICQ: 134682867- Hide qu=
oted text -
>
> - Show quoted text -

Thanks Wolfgang, reading your code carefully and slowly, it does not
seem so difficult and I think I understand it all as you have provided
a nice explanation.

There should not be a problem to reset the glViewport to 640 x 480
before drawing the 3D objects afterwards right? Because we have set up
the perspective projection with that aspect ratio and everything must
match up precisely with the camera image.

I appreciate your experience and advice.

Thanks,

Judie
0
Reply Judie 5/2/2008 2:16:41 PM

On May 2, 4:35=A0am, fungus <openglMYSO...@artlum.com> wrote:
> On May 1, 10:05 pm, Judie <judie.m.stan...@gmail.com> wrote:
>
>
>
> > I can't do that because that would affect the size of the rendered
> > objects as they are projected to the screen which would add a whole
> > nother layer of difficulty which at some point we will conquer, just
> > not initially.
>
> a) No it wouldn't one pixel is still "one" in that viewport.
>
> b) You can reset the viewport back to normal at any time
> - eg. right after the glDrawPixels().
>
> Ok, another trick to get around the clipping....use glBitmap
> to adjust the rasterpos (see "notes" in the page for glBitmap).
>
> glRasterPos2i(0,0); =A0 =A0 =A0 // Cannot be clipped
> glBitmap(0,0,0,0,x,y,0); // Set raster position to (x,y)
> glDrawPixels();
>

Oh b just answered a question I asked of Wolfgang. So it is OK to set
glViewport with negative minX, minY pos? I did not realize that was
allowed and never thought to try. Good.

In the glBitmap example, the x and y values can be negative and that
would move the position to the left and down?

Thanks,
Judie
0
Reply Judie 5/2/2008 2:27:30 PM

On May 2, 4:37=A0am, fungus <openglMYSO...@artlum.com> wrote:
> On May 2, 1:21 am, Andy V <nob...@nowhere.net> wrote:
>
>
>
> > However, the texture image is probably a better plan.
>
> In the long term, yes, but it's tricky to align the pixels
> properly.
>
> Textures also garantee best performance.
>
> --
> <\___/>
> / O O \
> \_____/ =A0FTB. =A0 =A0 Remove my socks for email address.

Well, as you probably guessed, speed is important. It is interesting
that there are so many ways to do the this!

Judie
0
Reply Judie 5/2/2008 2:28:41 PM

Judie wrote:

> There should not be a problem to reset the glViewport to 640 x
> 480 before drawing the 3D objects afterwards right? Because we
> have set up the perspective projection with that aspect ratio
> and everything must match up precisely with the camera image.

The viewport is just a state and the very last step in the
coordinate transformation chain. You can change any way you like
and combine rendering with several viewports into a single
image. Actually it's the commonly used technique to render HUDs
and stuff like that. Or have a look at Blender: Every UI element
defines it's own viewport for rendering, so in a single
rendering of the Blender UI you got ~100 different viewports
used.

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: hexarith@jabber.org, ICQ: 134682867

0
Reply Wolfgang 5/2/2008 2:49:46 PM

On May 2, 4:27 pm, Judie <judie.m.stan...@gmail.com> wrote:
>
> In the glBitmap example, the x and y values can be negative and that
> would move the position to the left and down?
>

Yes.

-
<\___/>
/ O O \
\_____/  FTB.     Remove my socks for email address.
0
Reply fungus 5/2/2008 4:47:52 PM

On May 2, 4:28 pm, Judie <judie.m.stan...@gmail.com> wrote:
>
> Well, as you probably guessed, speed is important.

For some strange reason it always is...


--
<\___/>
/ O O \
\_____/  FTB.     Remove my socks for email address.
0
Reply fungus 5/2/2008 4:49:55 PM

21 Replies
288 Views

(page loaded in 0.201 seconds)

Similiar Articles:
















7/27/2012 6:29:48 AM


Reply: