summaryrefslogtreecommitdiff
path: root/common/project.cpp
diff options
context:
space:
mode:
authorleo2000-09-13 14:00:50 +0000
committerleo2000-09-13 14:00:50 +0000
commit8da07672a44fc652baa72e9e4bf04f8f83f59825 (patch)
treeaae67fc8346bb4c9a2c00b391d59d1bc4fd5f78a /common/project.cpp
parent6535700af4f6e95a3812c7896b4ebc0be7281e46 (diff)
Fixed bug that caused image files to be saved upside down.
git-svn-id: http://svn.leocad.org/trunk@114 c7d43263-9d01-0410-8a33-9dba5d9f93d6
Diffstat (limited to 'common/project.cpp')
-rw-r--r--common/project.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/common/project.cpp b/common/project.cpp
index 92a855f..121b0b9 100644
--- a/common/project.cpp
+++ b/common/project.cpp
@@ -2838,7 +2838,8 @@ void Project::CreateImages(LC_IMAGE** images, int width, int height, unsigned sh
{
int oldx, oldy;
unsigned short oldtime;
- void* render = Sys_StartMemoryRender(width, height);
+ void* render = Sys_StartMemoryRender (width, height);
+ unsigned char* buf = (unsigned char*)malloc (width*height*3);
oldtime = m_bAnimation ? m_nCurFrame : m_nCurStep;
oldx = m_nViewX;
oldy = m_nViewY;
@@ -2878,8 +2879,12 @@ void Project::CreateImages(LC_IMAGE** images, int width, int height, unsigned sh
image->width = width;
image->height = height;
image->bits = (unsigned char*)image + sizeof(LC_IMAGE);
+
glPixelStorei (GL_PACK_ALIGNMENT, 1);
- glReadPixels (0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,image->bits);
+ glReadPixels (0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buf);
+
+ for (int row = 0; row < height; row++)
+ memcpy ((unsigned char*)image->bits + (row*width), buf + ((height-row-1)*width), width);
images[i-from] = image;
}
@@ -2891,6 +2896,7 @@ void Project::CreateImages(LC_IMAGE** images, int width, int height, unsigned sh
else
m_nCurStep = (unsigned char)oldtime;
CalculateStep();
+ free (buf);
Sys_FinishMemoryRender (render);
}
@@ -3412,6 +3418,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
{
int cx = 120, cy = 100;
void* render = Sys_StartMemoryRender (cx, cy);
+ unsigned char* buf = (unsigned char*)malloc (cx*cy*3);
float aspect = (float)cx/(float)cy;
glViewport(0, 0, cx, cy);
@@ -3465,13 +3472,17 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
image->height = cy;
image->bits = (unsigned char*)image + sizeof(LC_IMAGE);
glPixelStorei (GL_PACK_ALIGNMENT, 1);
- glReadPixels (0,0,cx,cy,GL_RGB,GL_UNSIGNED_BYTE,image->bits);
+ glReadPixels (0, 0, cx, cy, GL_RGB,GL_UNSIGNED_BYTE, buf);
+
+ for (int row = 0; row < cy; row++)
+ memcpy ((unsigned char*)image->bits + (row*cx), buf + ((cy-row-1)*cx), cx);
sprintf(fn, "%s%s%s", opts.path, pInfo->m_strName, ext);
SaveImage(fn, image, &opts.imdlg.imopts);
free(image);
}
Sys_FinishMemoryRender (render);
+ free (buf);
}
}
} break;