mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-30 18:29:04 +08:00
Add a texture coordinates examples for Y flipping
parent
8eab8863ed
commit
45a32c7331
@ -883,7 +883,14 @@ See e.g. http://wiki.polycount.com/wiki/Texture_Coordinates
|
||||
|
||||
For the purpose of this section we use "Texture Coordinates" and "UV Coordinates" interchangeably.
|
||||
|
||||
The `ImGui::Image()` and `ImDrawList::AddImage()` functions allow you to pass "UV coordinates" corresponding to the upper-left and bottom-right portion of the texture you want to display. Using the default values, respectively `(0.0f, 0.0f)` and `(1.0f, 1.0f)` for those coordinates allow you to display the entire underlying texture. UV coordinates are traditionally normalized coordinates, meaning that for each axis, instead of counting a number of texels, we address a location in the texture using a number from 0.0f to 1.0f. So (0.0f, 0.0f) is generally addressing the upper-left section of the texture and (1.0f, 1.0f) is addressing the lower-right corner of the texture.
|
||||
The `ImGui::Image()` and `ImDrawList::AddImage()` functions allow you to pass "UV coordinates" corresponding to the upper-left and bottom-right portion of the texture you want to display. Using the default values, respectively `(0.0f, 0.0f)` and `(1.0f, 1.0f)` for those coordinates allow you to display the entire underlying texture. UV coordinates are traditionally normalized coordinates, meaning that for each axis, instead of counting a number of texels, we address a location in the texture using a number from 0.0f to 1.0f. So (0.0f, 0.0f) is generally addressing the upper-left section of the texture and (1.0f, 1.0f) is addressing the lower-right corner of the texture. Some graphics systems may use coordinates that are inverted on the Y axis.
|
||||
|
||||
```cpp
|
||||
ImGui::Image((void*)my_texture, ImVec2(256, 256), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f)); // Default coordinates
|
||||
ImGui::Text("Flip Y coordinates:");
|
||||
ImGui::Image((void*)my_texture, ImVec2(256, 256), ImVec2(0.0f, 1.0f), ImVec2(1.0f, 0.0f)); // Flip Y coordinates
|
||||
```
|
||||
![image](https://github.com/ocornut/imgui/assets/8225057/532ed112-f4ed-459b-9308-a2d30f43d03c)
|
||||
|
||||
If you want to display part of a texture, say display a 100x200 rectangle stored from pixel (10,10) to pixel (110,210) out of a 256x256 texture, you will need to calculate the normalized coordinates of those pixels:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user