It looks like the orientation here is correct. In OpenGL, screen coordinates (0, 0) are in the lower-left corner.
But texture coordinates point down in the positive direction.
#include "Leadwerks.h"
namespace lwe = Leadwerks;
int main(int argc, const char* argv[])
{
auto displays = lwe::GetDisplays();
auto window = lwe::CreateWindow("gl_FragCoord", 0, 0, 720, 720, displays[0], lwe::WINDOW_DEFAULT);
auto framebuffer = lwe::CreateFramebuffer(window);
auto world = lwe::CreateWorld();
auto light = lwe::CreateDirectionalLight(world);
auto cone_0 = lwe::CreateCone(world, 0.5f, 1.f, 64);
auto cube_f = lwe::CreateBox(world);
cube_f->SetScale(100.f, 1.f, 100.f);
cube_f->SetPosition(0.f, -3.001f, 0.f);
cone_0->SetPosition(0.0f, +1.f, +2.f);
light->SetRotation(60, 0, 0);
light->SetColor(0.5f);
world->SetAmbientLight(0.1f, 0.1f, 0.1f);
auto camera_0 = lwe::CreateCamera(world);
auto camera_1 = lwe::CreateCamera(world);
auto camera_0_texture_0 = lwe::CreateTexture(lwe::TEXTURE_2D, 720, 720);
auto camera_0_texbuff = lwe::CreateTextureBuffer(720, 720, 1, true);
camera_0_texbuff->SetColorAttachment(camera_0_texture_0, 0);
camera_0->SetRenderTarget(camera_0_texbuff);
camera_0->SetOrder(0);
/*
camera_1->SetLighting(false);
camera_1->SetRenderLayers(0);
camera_1->SetOrder(1);
auto camera_1_effect = lwe::LoadPostEffect("Effects/BaseColor.fx");
auto camera_1_effect_id = camera_1->AddPostEffect(camera_1_effect);
camera_1->EnablePostEffect(camera_1_effect_id);
camera_1->SetUniform(camera_1_effect_id, "ColorBuffer", camera_0_texture_0);
*/
auto texturebuff_rt = lwe::CreateTextureBuffer(2, 2, 1, false);
auto framebuffer_rt = nullptr;
auto box = CreateBox(world);
box->SetPosition(0, 0, 3);
auto mtl = lwe::CreateMaterial();
mtl->SetTexture(camera_0_texture_0);
// Uncomment to verify the box UV mapping is correct:
//mtl->SetTexture(lwe::LoadTexture("https://leadwerksstorage.s3.us-east-2.amazonaws.com/monthly_2026_02/test.png.d230cd11a6904ef36c91256aa96b243d.png"));
box->SetMaterial(mtl);
// Let's make sure the position V axis points down on the texcoords
for (int v = 0; v < box->lods[0]->meshes[0]->CountVertices(); ++v)
{
auto pos = box->lods[0]->meshes[0]->vertices[v].position;
auto tc = box->lods[0]->meshes[0]->vertices[v].texcoords.xy();
tc.y = 1.0f - (pos.y + 0.5f);
box->lods[0]->meshes[0]->SetVertexTexCoords(v, tc);
}
while (window->Closed() == false &&
window->KeyDown(lwe::KEY_ESCAPE) == false)
{
#if 1
if (window->KeyHit(lwe::KEY_D1))
{ // Output to framebuffer from camera_1 (post effect Shaders/BaseColor.fx)
//camera_0->SetRenderTarget(camera_0_texbuff);
//camera_1->SetRenderTarget(framebuffer_rt);
}
if (window->KeyHit(lwe::KEY_D2))
{ // Output to framebuffer from camera_0 (post effect is ignored)
//camera_0->SetRenderTarget(framebuffer_rt);
//camera_1->SetRenderTarget(texturebuff_rt);
}
#endif
box->Turn(0, 1, 0);
world->Update();
world->Render(framebuffer);
}
return 0;
}
You can see here that render-to-texture has the correct orientation. THere's a line you can uncomment to load a different texture to verify the UV mapping of the box.