RenderTexture2d renders upside down

edited October 2016 in raylib: textures
Hi Ray! I am getting a bit of unexpected behavior with RenderTexture2D. The texture seems to be rendering rotated 180 degrees along X axis. Am I misunderstanding how to use it or is there perhaps a small bug? I looked through the examples but did not find any that use this struct. Here is the small program I wrote to test this:


#include "raylib.h"

int screen_width = 800;
int screen_height = 600;

void main(){
InitWindow(screen_width, screen_height, "RenderTexture2D test");

RenderTexture2D rt2d = LoadRenderTexture(400, 300);
while (!WindowShouldClose()){
BeginDrawing();
ClearBackground(RAYWHITE);

BeginTextureMode(rt2d);
DrawText("'ullo, mate!", 50, 50, 50, ORANGE);
EndTextureMode();
DrawTexture(rt2d.texture, 200, 150, LIGHTGRAY);
EndDrawing();
}
UnloadRenderTexture(rt2d);

CloseWindow();
}


Thanks as always for your help!

Comments

  • Hi wly_cdgr!

    Actually, that's the usual behaviour, RenderTexture2D is drawn upside-down... I really looked for a way to get the texture rendered ok but I couldn't find one (yeah, I know, it sounds really weird that an API like OpenGL doesn't provide an easy mechanism for that simple flip...).

    The easiest solution is just drawing the texture y-flipped; to make it easy I adapted DrawTextureRec(), you can check the example shaders_postprocessing.c (https://github.com/raysan5/raylib/blob/master/examples/shaders_postprocessing.c).

    Maybe I should add a DrawRenderTexture() function...
  • edited October 2016
    Got it, thanks!

    A DrawRenderTexture() function would make a lot of sense from where I'm standing cos it would complete the symmetrical set of LoadTexture & LoadRenderTexture, etc

    What an odd small-but-obvious thing for a huge project like OpenGL to not handle!
  • I didn't add a DrawRenderTexture() because it would also require another bunch of functions like DrawRenderTextureEx(), DrawRenderTextureRec(), DrawRenderTexturePro()... Additionally, that's not technically correct because a RenderTexture2D internally consist of multiple textures (color texture, depth texture), so I decided to keep it simple and let the user draw the desired texture...

    About texture flipped, by default OpenGL understand coordinates (0,0) at bottom-left corner, using top-left corner is not standard... but raylib is configured this way because, well, is the most common configuration for videogames and art programs...

    OpenGL mechanism to deal with it is as simple as drawing the quad containing the texture flipped (what we actually do) but in raylib, due to the fact it is a quite low-level library, it's not possible to do that automatically (other high-level libraries just do that automatically).
  • I see! Thanks for the explanations!
Sign In or Register to comment.