Closed titos-carrasco closed 2 years ago
Some test and NO need to change nothinge else (only mirror the background)
I am not sure to understand, is the problem that the background image has the red and blue channels inverted?
It seems that indeed, that line should use GL_RGBA
instead of GL_BGRA
according to QGLWidget's convertToGLFormat documentation.
It seems that I introduced a change in that commit and somewhat forgot about the texture being loaded from file. Probably the easiest is to fix the data on load after the call to convertToGLFormat
, otherwise it is an API breakage of Enki and I'm sure it will break downstream users.
Current background image - blue: 0,0,1 - cyan: 0,1,1
With "QGLWidget::convertToGLFormat()" when preparing groundTexture and robot over "cyan", gound sensors (World::getGroundColor) shows inverted values for channels
Without "QGLWidget::convertToGLFormat()" when preparing groundTexture (just mirroring the image) and robot over cyan, gound sensors (World::getGroundColor) shows correct values
In this last case no need to change fromARGB or GL_BGRA ¿why?
As its documentation says, QGLWidget::convertToGLFormat()
converts to GL_RGBA but the viewer, and the robot's sensors, expect the equivalent of GL_BGRA. So the hack I propose is to still call convertToGLFormat()
, to have a known but wrong order, than pass through the array to invert R and B.
Many images in QImage are stored using a 32-bit ARGB format (QImage::Format_ARGB32
- 0xAARRGGBB). In little endian means BRGA****
This is why in Viewer.cpp (line 873 - initializeGL ) "groundTexture" is read as GL_UNSIGNED_BYTE GL_BGRA in glTexImage2D() - because read byte 0 first, then byte 1 and so on
In PhysicalEngine.cpp (line 783) getGroundColor() reads ground texture data as uint32_t and this is why returns "Color::fromARGB" (QImage::Format_ARGB32
format)
So, no needs to change anything just:
Saludos
Just don't use convertToGLFormat()
in:
Saludos
The reason there is the call to convertToGLFormat
in the first place is that the loaded image can have any format, so we need to convert to the one we will use. Maybe another conversation is bether indeed, as long as we have guarantees on not having any padding between lines.
In that case, and considering that the GL format used in convertToGLFormat
is GL_RGBA:
glTexImage2D
must be GL_RGBA (to display the background image in the right way)getGroundColor
,must returns Color::fromABGR
Saludos
I do not want to change the format of the ground data stored within Enki itself, as this would break the API and the projects using Enki. So we should convert to the current expected format on load, with 32 bpp hopefully there should be no padding, so calling QImage::convertToFormat
with QImage::Format_ARGB32
instead of using convertToGLFormat
should work.
Fixed by bb486bf.
Works fine :-)
I'm testing enki viewer using the enkiplayground app and the image below (Equinoxe Infinity Album - Jean Michel Jarre) as background
But the image does not shows properly
The next patch (Playground.cpp) fix the problem
You can use jpg, gif, svg, etc image formats (RGB - needs the qt image format filters) - a 200cm x 200cm and 18dpi image works fine with low memory consumption
BUT:
Saludos