简体   繁体   English

镜像(翻转)使用SOIL_load_image加载的JPG图像

[英]Mirror (flop) a JPG image loaded using SOIL_load_image

I have successfully loaded a .jpg image using the library libsoil-dev as found for Debian using the command 我已经使用库libsoil-dev成功加载了.jpg图像,如使用以下命令为Debian找到的那样:

    uchar* img = SOIL_load_image(pfname_texture.c_str(),
      &img_width, &img_height, NULL, 0);

The latter two parameters are int* channels and int force_channels whatever that may mean in detail, but they seem to touch stuff like the alpha channel. 后两个参数分别是int *通道int force_channels,无论可能有什么含义,但它们似乎与alpha通道类似。

Using said command I know width and height of the image in pixels. 使用上述命令,我知道图像的宽度和高度(以像素为单位)。

Now I want to flop it horizontally (meaning the left and right edges switch sides). 现在,我想水平翻转它(意思是左右边缘切换两侧)。 This would be easy if I knew the size of uchar* img . 如果我知道uchar * img的大小,这将很容易。 However, as things stand I do not, because I cannot be sure how many uchars make up one pixel. 但是,按照目前的情况,我不知道,因为我不能确定一个像素中有多少个uchar Plus I do not know how the pixels are ordered in memory (linewise, columnwise, from top to bottom or vice versa, you name it). 另外,我不知道像素在内存中的排序方式(按行,列,从上到下或从上到下,反之亦然)。 Any ideas? 有任何想法吗?

Have you try mapping your texture out differently, for example: 您是否尝试过以其他方式映射纹理,例如:

glBegin(GL_QUADS);
glTexCoord2f(1, 1); glVertex3f(0, 798, 0); // 0, 1
glTexCoord2f(1, 0); glVertex3f(0, 0, 0); // 0, 0
glTexCoord2f(0, 0); glVertex3f(1280, 0, 0); // 1, 0
glTexCoord2f(0, 1); glVertex3f(1280, 798, 0); // 1, 1
glEnd();

here I switched the x coordinate in glTexCoord2f (first argument) with it's opposite, so glTexCoord2f(1, 1) would become glTexCoord2f(0, 1). 在这里,我在相反的glTexCoord2f(第一个参数)中切换了x坐标,因此glTexCoord2f(1,1)将变成glTexCoord2f(0,1)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM