Nuklear icon indicating copy to clipboard operation
Nuklear copied to clipboard

OpenGL - Upside down textures using nk_button_image

Open jorgefz opened this issue 2 years ago • 1 comments

Hello everyone,

I have a small issue regarding textures rendering upside down using nk_button_image.

I am building a small game engine in C which makes use of GLFW. I'm using stb_image to load textures, which I then flip vertically using stbi_set_flip_vertically_on_load(1). This, however, causes nk_button_image to render its textures upside down (whereas the textures I render myself are upright). However, if I change the above setting to stbi_set_flip_vertically_on_load(0), button images render upright, but nothing else on my engine does.

This leads me to believe the GLFW backend Nuklear uses flips images automatically. I have tried modifying the internal shader and orhtographic matrix Nuklear uses to no avail (results in invisible widgets).

Is there an straightforward way of flipping the images on Nuklear without changing the way my engine handles textures?

Thank you in advance!

jorgefz avatar Aug 16 '22 15:08 jorgefz

Use a custom shader for nuklear and just flip the uv.

v_texcoord = vec2(a_texcoord.s, 1.0 - a_texcoord.t);

But if you have to flip images by default you probably are building your vertex buffer incorrectly and the texcoord x and y are swapped.

revolucas avatar Jan 31 '23 04:01 revolucas