Nick
Nick

Reputation: 21

SDL2 - Draw from bottom left

SDL2 uses a (0,0) top-left configuration with a positive y axis pointing down. How can I change this for y pointing up from the bottom left? Note that the area covered by the input co-ordinates may or may not be the same as the screen area.

Usually I would just change the projection matrix to what I need but I don't seem to have access to this through the SDL API?

Upvotes: 2

Views: 1016

Answers (1)

user2742371
user2742371

Reputation:

How about a function which converts it for you?

float convertPointY(float y) {
     return -y + WINDOW_HEIGHT;
}

And if the window changes size thus not having a constant height:

float convertPointY(float y) {
     int width = 0, height = 0;
     SDL_GetWindowSize(window, &width, &height);

     return -y + height;
}

Upvotes: 1

Related Questions