Leon Moctezuma schrieb:
> Well I think you already know what I did
> this week. I just will add, that today I
> was working on the upside down texture
> problem. I still have not solved it, but
> I isolated where the png problem comes from.
OpenGL uses a different coordinate system.
0,0 is in the lower left corner just as
in math. x extends to the left and y to the top.
See the texture mapping chapter of the red book
for more information. Try first with a simple example.
> When I added support for png I changed
> some small parts from the Image class,
> including, copyImgToTexImg() function,
> it works fine with jpg and png withou alpha
> values, I changed all the 3 numbers by
> color_channels variable (1,3,4), when I use alpha png
> files it produces a memory corruption, and it
> seems that comes from the second
> memcpy() function, this probably means an overflow,
> but I'm not sure.
Yes, that code is a real hack since it does the address computation
by hand.
>
> I'm able to create simple spi-v panoramas mixing flat
> images and cube or spherical panoramas, the problem
> still be the upside down problem and that I'm not able
> to use tiled images... don't know if this is really necessary,
> in some point freepv must be fliping the images for the
> cube faces, since this are correctly textured,
> I created some pnm files and realized that the images
> are upside-up (opengl uses upside-down images), now
> if the cubes are textured correctly using this textures
> at some point the textures are fliped, I also checked
> my texture coordinates and I'm more than sure they
> are correct.
Hmm, I don't flip the images manually. I generate the right texture
coordinates to do so.
> glBegin(GL_QUADS);
> glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, - 4.0f);
> glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -4.0f);
> glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -4.0f);
> glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -4.0f);
> glEnd();
This assumes the textures are stored with the same convention as the OpenGL,
which they are not. try flipping y of the texture coordinates:
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, -1.0f, - 4.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -4.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, -4.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, -4.0f);
glEnd();
> I rewrote the writePPM fuction that pablo added
> to make some debuggin, now the function is
> able to create pnm files from images with alpha channels,
> anyway I just did this to try to find what's going on.
>
> I will add in the report the code where I'm having
> the problem... since I have already explained
> a lot in this mail and I think there is no reason for sending
> two mail about the same topic...
>
> void FPV::copyImgToTexImg(Image * dest, Image * src, Point2D
> destPos, Point2D srcPos, Size2D srcSize, bool pad)
> {
> if (srcSize.w == -1) srcSize = src->size() - Size2D(srcPos.x,
> srcPos.y);
>
> if (srcSize.w + srcPos.x > src->size().w) {
> srcSize.w = src->size().w - srcPos.x;
> }
> if (srcSize.h + srcPos.y > src->size().h) {
> srcSize.h = src->size().h - srcPos.y;
> }
>
> assert((srcPos.x + srcSize.w <= src->size().w) && (srcPos.x +
> srcSize.w <= src->size().w));
> assert((destPos.x+srcSize.w <= dest->size().w) &&
> (destPos.y+srcSize.h <= dest->size().h));
>
> int color_channels = src->getColorChannels();
> // pad if requested.
> bool padX = (destPos.x+srcSize.w != dest->size().w) && pad;
> bool padY = (destPos.y+srcSize.h != dest->size().h) && pad;
>
> int srcStride = src->getRowStride();
> int destStride = dest->getRowStride();
does getRowStride() return the right values for 4 channel images?
> //int pixelStride = 3;
> // copy image
> unsigned char * destPtr = dest->getData() + color_channels*
> destPos.x + destStride*destPos.y;
> unsigned char * srcPtr = src->getData() +
> color_channels*srcPos.x + srcStride*srcPos.y;
>
> if (padX) {
> for (int y=srcSize.h; y; y--)
> {
> // pad texture
> memcpy(destPtr, srcPtr, srcSize.w*color_channels);
> unsigned char *srcPtrt = srcPtr +
> color_channels*(srcSize.w-1);
> unsigned char *destPtrt = destPtr +
> srcSize.w*color_channels ;
> for (int x=destPos.x + srcSize.w ; x < dest->size().w;
> x++) {
> for(int j=0; j<color_channels; j++)
> *destPtrt++ = *(srcPtrt+j);
> }
> srcPtr += srcStride;
> destPtr += destStride;
> }
> } else {
> for (int y=srcSize.h; y; y--)
> {
> memcpy(destPtr, srcPtr, srcSize.w*color_channels);
> //MEMORY CORRUPTION
> destPtr += destStride;
> srcPtr += srcStride;
> }
> }
> srcPtr -= srcStride;
> if (padY) {
> for (int y=(destPos.y + srcSize.h); y < dest->size().h ; y++)
> {
> memcpy(destPtr, srcPtr, srcSize.w*color_channels);
> unsigned char *srcPtrt = srcPtr +
> color_channels*(srcSize.w-1);
> unsigned char *destPtrt = destPtr +
> srcSize.w*color_channels;
> for (int x=destPos.x + srcSize.w ; x < dest->size().w;
> x++) {
> for(int j=0; j<color_channels; j++)
> *destPtrt++ = *(srcPtrt+j);
> }
> destPtr += destStride;
> }
> }
> }
>
ciao
Pablo
|