mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-14 19:04:44 +00:00
Drawing an image or even better an opengl view in IMGUI window #497
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#497
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi,

I am facing the following issue. I use ImGui::Image to draw in a window a bitmap (sprite) that i can scale and rotate in my home game editor.
My problem is that i can not rotate the Image in the preview window or I am not sure how i can do it so the preview window reflects the actual bitmap I am modifying. The reason i need this is cause when u manipulate properties of the bitmap used for drawing the bitmap is not displayed somewhere so for the user to see in real time the changes.
Regards
Rotate the 4 corner points, then call draw_list->PrimQuadUV() or add the triangles/indices yourself.
Are you doing something involving Wonder Boy?
:) the truth is I want to make my own version of Wonder Boy. I start building simple opengl engine to handle 2D and i ended up building a 2D Game Builder tool (https://youtu.be/3aSHfHRLrpQ). Hopefully it will allow me once i finish to make my own version of Wonder Boy (fast-paced but with RPG elements like Wonder Boy in Monster Land). I am just using graphics from internet.. for the moment to test my 2D Game Builder. Amazing work you doing with ImGui by the way!
Not sure i understood how to rotate the 4 corner points.
I do something like below to display the graphics:
Instead of calling ImGui::Image() get the draw list and do something like
To render an arbitrary quad. Use whatever math you would use (e.g. 2x2 rotation matrix) to rotate the 4 corners a,b,c,d.
I love Monster Land, I have purchased the arcade board a while ago. I am now working on Wonder Boy related project as well :)
:) Just checked your project on https://forums.tigsource.com/index.php?topic=50899
Very interesting :) :) :) I also completed home project Arcade Machine (with real Arcade Monitor) so i can play Wonder Boy games (and much more) the way i used to play them when i was little on CRT monitor with perfect frame rate and super smooth scrolling. Thanks for the help.
Closing this for now.
Hope to be announcing our game more formally soon :)
Good Luck! :) i will have an eye for it :) I am very big fun of old arcade remakes
@ocornut will your project be hosted here on github?
It is already but it is a commercial endeavour and won't be open-sourced or at least not right away. I hope to release some tools screenshot or code pertinent to ImGui.
Hi, just discovered the library and am loving it. I ran into the same issue as nikmes, and ended up writing my own little helper, but it'd be great if there was an Image function that allowed all four uv co-ordinates. (And then used PrimQuadUV)
Cheers!
Hello and welcome!
Out of curiosity, did you get stuck figuring out what approach to use? Using ImDrawList is pretty common if you start doing visual stuff.
Using 4 uv coordinates is fairly rare (rarer than needing 4 positions instead of 2). We could in theory add a helper variant of ImGui::Image() that took an angle and scale, maybe a rotation center.
However I imagine it would be rather awkward in term of layout (in term of using the axis-aligned bounding box from the rotated image as the aabb used for layout), you'd practically want to set the cursor position before and maybe after calling ImGui::Image().
I would suggest instead:
Do you think it would improve the situation?
Sent from my fax machine
I love the first suggestion! I'm going to dive into the drawlists now. I don't know why I needed all four, graphics isn't really my forte(audio is...), I just found it easy for me to say here are the four points in clockwise order! Tnx again for a great library. EDIT - Just remembered, I did end up using a drawlist..(which I lifted for the most part from the default Image) Here is my hacky approach.
Jaydee2190: The above performs rotation of the image? Is just drawing the image without rotation correct? To be honest i didn't manage yet to draw using drawList and rotate the image.
ocornut: I like the idea of helper. Just we pass rotation (angles or degrees) and the scale factor and then image is just drawn in window scaled and rotated :)
Hi nikmes, yes it maps rotated(just does the texture mapping). So you pass in your u,v co-ordiantes
0,1(uv_b) 1,1(uv_c)
0,0(uv_a) 1,0(uv_d)
And it'll draw thew starting with b(so if you use a texturepacker like me that rotates 90 degree's CW, this rotates it back)
I have had luck(different problem) with adding a UserCallback before adding the image and in that apply a matrix, then after the image reseting the matrix(another userCallback with a flag in UseCallbackData as to whether to set or reset). Probably better ways of doing it, but that worked for me!
Note that when you start using callbacks and you are breaking the draw-call merging mechanism of ImGui. Each callback will lead to creating a new draw call.
nikmes, I'll post some helper code later, really you only have to apply a 2d rotation matrix to each of the four points.
If this is confusing ignore the UV coordinates and draw lines between those 4 points for testing (and remember you can add imgui widget to easily test your code in an interactive manner)